知識庫

Configuring a static IP on Rocky or AlmaLinux 列印

  • rocky, almalinux, static-ip, networkmanager, networking
  • 0

Overview

Rocky Linux and AlmaLinux manage networking with NetworkManager, either through nmcli on the command line or by editing connection files. This article shows how to assign a static IP, gateway and DNS to a Pod while keeping a console session open as a safety net.

Before you begin

  • A Rocky or AlmaLinux Pod with sudo access.
  • The address, prefix length, gateway and DNS servers you plan to use. Public addressing must match the values in the ALYPOD Console.
  • Console access in case the change drops your connection.

Steps

  1. Identify the active connection and interface:

bash nmcli -t -f NAME,DEVICE connection show --active ip -brief addr

  1. Back up the current connection so you can restore it quickly:

bash sudo nmcli connection clone "System eth0" "System eth0 backup"

Replace the connection name with the one from step 1.

  1. Set the static address, gateway and DNS:

bash sudo nmcli connection modify "System eth0" \ ipv4.method manual \ ipv4.addresses 10.10.0.10/24 \ ipv4.gateway 10.10.0.1 \ ipv4.dns "1.1.1.1,8.8.8.8"

  1. Bring the connection up and verify:

bash sudo nmcli connection up "System eth0" ip -brief addr ip route ping -c 3 1.1.1.1

  1. Keep the connection from being reused, then confirm it is set to autoconnect:

bash sudo nmcli connection show "System eth0" | grep autoconnect

Editing files directly

Connections are stored as ifcfg-* files under /etc/sysconfig/network-scripts/. You can set BOOTPROTO=none, IPADDR, PREFIX, GATEWAY and DNS1 there and run sudo nmcli connection reload followed by sudo nmcli connection up "<name>".

Troubleshooting

  • Problem: Interface comes up without a default route. Solution: Re-check ipv4.gateway and confirm the gateway matches your subnet from the Console.
  • Problem: DNS stops working. Solution: Set ipv4.dns and, if needed, ipv4.ignore-auto-dns yes.
  • Problem: You lost SSH. Solution: Restore with sudo nmcli connection up "System eth0 backup" from the console.

Related articles

  • [Configuring a static IP on Ubuntu]
  • [Understanding the ALYPOD network and datacenters]

這篇文章有幫助嗎?

« 返回