Skip to content

NetworkManager Basics

NetworkManager is the default network management service on CentOS / AlmaLinux / Rocky Linux. It provides two convenient ways to configure and manage network connections: nmcli (command line) and nmtui (text-based user interface).

NetworkManager runs as a daemon responsible for automatically detecting, configuring, and switching network connections. It has two core concepts:

  • Device: A physical or virtual network interface, such as ens33, eth0, or virbr0.
  • Connection: A set of network configuration parameters bound to a device. A device can have multiple connection profiles, but only one can be active at a time.
Check if NetworkManager is running
systemctl status NetworkManager

If the service is not running, you can start it and enable it at boot:

Start and enable NetworkManager
sudo systemctl enable --now NetworkManager

nmcli is the command-line tool for NetworkManager. It is fully featured and well-suited for scripting.

List all network devices and their status
nmcli device status

Example output:

DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
lo loopback unmanaged --
List all connection profiles
nmcli connection show

View detailed information for a specific connection:

View the full configuration of the ens33 connection
nmcli connection show ens33

Viewing Current IP Information for a Device

Section titled “Viewing Current IP Information for a Device”
View IP addresses for all devices
nmcli device show

View a specific device only:

View detailed information for ens33
nmcli device show ens33

Switching a network interface from DHCP to a static IP is one of the most common operations.

Configure a static IP, gateway, and DNS for ens33
sudo nmcli connection modify ens33 \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8 8.8.4.4"

After making changes, you need to reactivate the connection for them to take effect:

Reactivate the connection to apply changes
sudo nmcli connection up ens33
Confirm the IP address is correctly configured
nmcli -p connection show ens33 | grep ipv4

To switch back from a static IP to DHCP:

Switch the connection to DHCP mode
sudo nmcli connection modify ens33 \
ipv4.method auto \
ipv4.addresses "" \
ipv4.gateway "" \
ipv4.dns ""
Reactivate the connection
sudo nmcli connection up ens33
Configure multiple DNS servers for a connection
sudo nmcli connection modify ens33 ipv4.dns "223.5.5.5 119.29.29.29"

Use the + prefix to append to the existing DNS list instead of replacing it:

Append a DNS server
sudo nmcli connection modify ens33 +ipv4.dns "8.8.8.8"
Configure DNS search domains
sudo nmcli connection modify ens33 ipv4.dns-search "example.com internal.local"

Preventing DHCP from Overwriting DNS Configuration

Section titled “Preventing DHCP from Overwriting DNS Configuration”

In DHCP mode, you may want to keep your manually specified DNS servers. You can set ignore-auto-dns:

Ignore DNS servers provided by DHCP
sudo nmcli connection modify ens33 ipv4.ignore-auto-dns yes
Create a new Ethernet connection profile
sudo nmcli connection add \
con-name "office-static" \
type ethernet \
ifname ens33 \
ipv4.method manual \
ipv4.addresses 10.0.0.50/24 \
ipv4.gateway 10.0.0.1 \
ipv4.dns "10.0.0.2"

A single network interface can have multiple connection profiles that you can switch between as needed:

Activate the office-static connection
sudo nmcli connection up office-static
Switch back to the original connection
sudo nmcli connection up ens33
Delete an unneeded connection profile
sudo nmcli connection delete office-static

NetworkManager stores connection profiles in the following directories by default:

  • EL 9 & EL 10 (AlmaLinux 9/10 / Rocky Linux 9/10): /etc/NetworkManager/system-connections/, in keyfile format (.nmconnection)
  • EL 8 and earlier: /etc/sysconfig/network-scripts/, in ifcfg format
View connection profiles on EL 9 / EL 10
ls /etc/NetworkManager/system-connections/
View connection profiles on EL 8
ls /etc/sysconfig/network-scripts/ifcfg-*

nmtui provides a text-based interactive interface that is more user-friendly for those unfamiliar with nmcli commands.

Launch the nmtui text interface
sudo nmtui

nmtui offers three options:

  1. Edit a connection — Edit an existing connection or create a new one
  2. Activate a connection — Activate or deactivate a connection
  3. Set system hostname — Set the hostname

Use arrow keys to navigate, Tab to switch between options, and Enter to confirm.

Open the connection editing interface directly
sudo nmtui edit
Edit the ens33 connection directly
sudo nmtui edit ens33
Temporarily disable a network interface
sudo nmcli device disconnect ens33
Re-enable a network interface
sudo nmcli device connect ens33

Viewing Available Wi-Fi Networks (for systems with wireless interfaces)

Section titled “Viewing Available Wi-Fi Networks (for systems with wireless interfaces)”
Scan and list available Wi-Fi networks
nmcli device wifi list
Set the hostname via nmcli
sudo nmcli general hostname myserver.example.com
View the overall network connectivity status
nmcli general status

If your network configuration is not taking effect, follow these steps to diagnose the issue:

View NetworkManager logs
sudo journalctl -u NetworkManager --no-pager -n 50
Check that the connection configuration loaded correctly
nmcli connection show ens33 | grep -E "ipv4\.(method|addresses|gateway|dns)"
Check the actual IP assigned to the device
ip addr show ens33