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 Overview
Section titled “NetworkManager Overview”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, orvirbr0. - 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.
Checking NetworkManager Service Status
Section titled “Checking NetworkManager Service Status”systemctl status NetworkManagerIf the service is not running, you can start it and enable it at boot:
sudo systemctl enable --now NetworkManagerManaging Networks with nmcli
Section titled “Managing Networks with nmcli”nmcli is the command-line tool for NetworkManager. It is fully featured and well-suited for scripting.
Viewing Network Devices
Section titled “Viewing Network Devices”nmcli device statusExample output:
DEVICE TYPE STATE CONNECTIONens33 ethernet connected ens33lo loopback unmanaged --Viewing All Connection Profiles
Section titled “Viewing All Connection Profiles”nmcli connection showView detailed information for a specific connection:
nmcli connection show ens33Viewing Current IP Information for a Device
Section titled “Viewing Current IP Information for a Device”nmcli device showView a specific device only:
nmcli device show ens33Configuring a Static IP Address
Section titled “Configuring a Static IP Address”Switching a network interface from DHCP to a static IP is one of the most common operations.
Setting a Static IPv4 Address
Section titled “Setting a Static IPv4 Address”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:
sudo nmcli connection up ens33Verifying the Configuration
Section titled “Verifying the Configuration”nmcli -p connection show ens33 | grep ipv4Configuring DHCP
Section titled “Configuring DHCP”To switch back from a static IP to DHCP:
sudo nmcli connection modify ens33 \ ipv4.method auto \ ipv4.addresses "" \ ipv4.gateway "" \ ipv4.dns ""sudo nmcli connection up ens33DNS Configuration
Section titled “DNS Configuration”Setting DNS Servers
Section titled “Setting DNS Servers”sudo nmcli connection modify ens33 ipv4.dns "223.5.5.5 119.29.29.29"Appending DNS Servers
Section titled “Appending DNS Servers”Use the + prefix to append to the existing DNS list instead of replacing it:
sudo nmcli connection modify ens33 +ipv4.dns "8.8.8.8"Setting DNS Search Domains
Section titled “Setting 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:
sudo nmcli connection modify ens33 ipv4.ignore-auto-dns yesConnection Profile Management
Section titled “Connection Profile Management”Creating a New Connection Profile
Section titled “Creating a New 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"Switching Connection Profiles
Section titled “Switching Connection Profiles”A single network interface can have multiple connection profiles that you can switch between as needed:
sudo nmcli connection up office-staticsudo nmcli connection up ens33Deleting a Connection Profile
Section titled “Deleting a Connection Profile”sudo nmcli connection delete office-staticConfiguration File Locations
Section titled “Configuration File Locations”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
ls /etc/NetworkManager/system-connections/ls /etc/sysconfig/network-scripts/ifcfg-*Graphical Configuration with nmtui
Section titled “Graphical Configuration with nmtui”nmtui provides a text-based interactive interface that is more user-friendly for those unfamiliar with nmcli commands.
sudo nmtuinmtui offers three options:
- Edit a connection — Edit an existing connection or create a new one
- Activate a connection — Activate or deactivate a connection
- Set system hostname — Set the hostname
Use arrow keys to navigate, Tab to switch between options, and Enter to confirm.
Entering Edit Mode Directly
Section titled “Entering Edit Mode Directly”sudo nmtui editEditing a Specific Connection Directly
Section titled “Editing a Specific Connection Directly”sudo nmtui edit ens33Quick Reference for Common Operations
Section titled “Quick Reference for Common Operations”Enabling/Disabling a Network Interface
Section titled “Enabling/Disabling a Network Interface”sudo nmcli device disconnect ens33sudo nmcli device connect ens33Viewing Available Wi-Fi Networks (for systems with wireless interfaces)
Section titled “Viewing Available Wi-Fi Networks (for systems with wireless interfaces)”nmcli device wifi listSetting the Hostname
Section titled “Setting the Hostname”sudo nmcli general hostname myserver.example.comViewing Overall NetworkManager Status
Section titled “Viewing Overall NetworkManager Status”nmcli general statusTroubleshooting Tips
Section titled “Troubleshooting Tips”If your network configuration is not taking effect, follow these steps to diagnose the issue:
sudo journalctl -u NetworkManager --no-pager -n 50nmcli connection show ens33 | grep -E "ipv4\.(method|addresses|gateway|dns)"ip addr show ens33