Linux

Use NMCLI To Manage Networking In RockyLinux 9 & AlmaLinux 9

In the latest versions of RHEL-based Operating Systems, you no longer manage the network using NetworkManager ifcfg files. Previously in RockyLinux 8 and AlmaLinux 8, you would add ifcfg files to configure adapters and also to configure persistent static routes. In RockyLinux 9 and AlmaLinux 9, the recommended way to manage the network is to use the command line tool NMCLI embedded in Linux. However, it is still possible to use ifcfg files although not recommended. NetworkManager now prioritises key files. When you create or manage connection profiles. These profiles will be given priority over the ifcfg files. As most NVMe VPS Servers are provisioned automatically, it’s strongly advised to use NMCLI to manage your server’s network.

NMCLI Basics

These Linux NMCLI commands show you the current network status and how to add net connection profiles.

NMCLI CommandDescription
nmcli con showList all connections on the server.
nmcli con show PublicList the current settings for the connection Public
nmcli dev statusShow the status of NetworkManager and connections.
nmcli con add con-name Public ..Add a new connection named Public.
nmcli con mod name ..Modify the connection name.
nmcli con reloadTell NetworkManager to reload the configuration files.
nmcli con up PublicActivate a connection named Public
nmcli dev dis devDeactivate and disconnect the current connection on the network interface dev
nmcli con del nameDelete the connection name and its configuration file

Example – NMCLI Show Adapters and Status

nmcli dev status

In this example, we can see that our RockyLinux 9 VPS has two connections named eth0 and eth1. Both of these connections are up.

DEVICE  TYPE      STATE                   CONNECTION
eth0    ethernet  connected               System eth0
eth1    ethernet  connected               System eth1
lo      loopback  connected (externally)  lo

Example – Show NMCLI connection details

nmcli con show

In this example, we can see the two connections. Notice how nmcli assigned a UUID to the connections.

Configure Static Routes Using MNCLI

Previously to configure a static route in CentOS 7, RockyLinux 8 and AlmaLinux 8 you would add a route-eth0 file to the /etc/sysconfig/network-scripts file. You can still do this, just as you can still add ifcfg-eth files to configure networking. However, as mentioned above if you do this these connections will have a lower priority than connections configured using nmcli. Therefore, to configure a static route on RockyLinux 9 and AlmaLinux 9 use nmcli.

Configure Static Route for 10.210.250.5

In this example, we want to route all traffic for the 10.210.250.5 IP address via the gateway 10.210.250.5.

nmcli connection modify eth1 +ipv4.routes "10.210.250.0/24 10.210.250.1"

But remember, you can still configure a static route in RockyLinux 9 or AlmaLinux 9 the old way by creating a route-eth1 file.

nano /etc/sysconfig/network-scripts/route-eth1
# Configure static route for 10.210.250.0/24 private network

10.210.250.0/24 dev eth1
default via 10.210.250.1 dev eth1

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button