On RHEL, AlmaLinux, Rocky Linux, CentOS Stream and Fedora, network configuration is handled by NetworkManager, and the command-line tool is nmcli. (Ubuntu servers use netplan, and Debian typically uses ifupdown. See the links at the end.) Here’s how to inspect and change network settings with nmcli without locking yourself out.

Safety first: on a VPS, make network changes from the VNC console in your control panel, or schedule an automatic rollback, so a mistake doesn’t cut off SSH. See VPS VNC console and at command.

Look around

nmcli general status
nmcli device status            # interfaces and their state
nmcli connection show          # saved connection profiles
nmcli connection show "System eth0"     # all settings of one profile
ip addr; ip route              # what the kernel actually has

NetworkManager separates devices (physical/virtual interfaces like eth0) from connections (saved configuration profiles applied to a device). Profiles are stored in /etc/NetworkManager/system-connections/ (keyfile format on RHEL 9 and later).

Set a static IP

CON="System eth0"     # from nmcli connection show
sudo nmcli connection modify "$CON" \
  ipv4.method manual \
  ipv4.addresses 203.0.113.10/24 \
  ipv4.gateway 203.0.113.1 \
  ipv4.dns "1.1.1.1 9.9.9.9"
sudo nmcli connection up "$CON"

Use the exact values from your VPS client area. connection up applies the change immediately, so this is where a typo disconnects you.

Back to DHCP:

sudo nmcli connection modify "$CON" ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns ""
sudo nmcli connection up "$CON"

Add a second IP address

For multi-IP plans:

sudo nmcli connection modify "$CON" +ipv4.addresses 203.0.113.11/24
sudo nmcli connection up "$CON"
ip -4 addr show eth0

Remove it with -ipv4.addresses 203.0.113.11/24. See VPS IP addresses and multi-IP VPS.

DNS settings

sudo nmcli connection modify "$CON" ipv4.dns "1.1.1.1 9.9.9.9" ipv4.ignore-auto-dns yes
sudo nmcli connection up "$CON"
cat /etc/resolv.conf

ipv4.ignore-auto-dns yes stops DHCP from overriding your DNS servers. See change DNS server on Linux.

Hostname

sudo nmcli general hostname web1.example.com

See change the hostname.

Other useful tasks

sudo nmcli connection reload                  # re-read profile files after manual edits
sudo nmcli device reapply eth0                # apply profile changes to the device
nmcli -f GENERAL,IP4 device show eth0
sudo nmcli connection modify "$CON" connection.autoconnect yes

Bonding, VLANs and bridges can also be created with nmcli (nmcli connection add type bond …, type vlan, type bridge). See Linux network bonding.

nmtui: a text menu

Prefer menus? sudo nmtui gives a simple text interface to edit connections, set the hostname, and activate connections. It works well from the VNC console.

Troubleshooting

Problem Check
Changes don’t apply Did you run nmcli connection up? Is the right profile active on the device?
Two profiles fight for one device nmcli connection show shows duplicates. Delete the unused one
DNS keeps reverting Set ipv4.ignore-auto-dns yes
Interface “unmanaged” It’s configured elsewhere (for example ifcfg or cloud-init rules)
Lost connectivity VNC console: nmcli connection up with corrected settings, or revert to DHCP

Logs: journalctl -u NetworkManager.

Quick reference

Task Command
Devices / connections nmcli device status / nmcli connection show
Static IP nmcli con mod X ipv4.method manual ipv4.addresses …
Apply nmcli con up X
Extra IP nmcli con mod X +ipv4.addresses …
DNS ipv4.dns "…" ipv4.ignore-auto-dns yes
Text UI nmtui

Related: static IP with netplan (Ubuntu) and ifupdown on Debian.

  • Linux
  • Networking
  • AlmaLinux