Manage Networking with NetworkManager in RHEL/CentOS 8

Wondering how to manage Networking with NetworkManager in RHEL? We can help you.

In RHEL and CentOS 8, the NetworkManager daemon manages the networking service to dynamically configure and control network devices and keep connections up and active when they are available.

As part of our Server Management Services, we assist our customers with several NetworkManager queries.

Today, let us see how to manage Networking with NetworkManager in RHEL/CentOS 8

 

Manage Networking with NetworkManager in RHEL

NetworkManager supports easy network setup and management using both command-line interface and graphical user interface tools.

In addition, it provides an API through D-Bus to query and control network configuration, support for configuration flexibility, and much more.

Besides, NetworkManager also supports the use of custom scripts to start or stop other services based on the connection status.

Few important points about networking in RHEL/CentOS 8:

  • It supports the traditional ifcfg type configurations (eg. ifcfg-eth0, ifcfg-enp0s3).
  • It does not provide Network scripts by default and they are deprecated.
  • A minimal installation provides a new version of the ifup and ifdown scripts that call NetworkManager via the nmcli tool.
  • To run the ifup and ifdown scripts, NetworkManager must run.

 

Step1 – Install NetworkManager on RHEL/CentOS 8

If it does not come pre-installed, we can install it with the DNF package manager.

# dnf install NetworkManager

We can find the configuration file at /etc/NetworkManager/NetworkManager.conf and additional configuration files can be found in /etc/NetworkManager/.

 

Step2 – Manage NetworkManager Using Systemctl on RHEL/CentOS 8

In RHEL/CentOS 8 that has the systemd, services are managed using the systemctl tool.

The following are few useful systemctl commands:

  • Check the status of NetworkManager

We can use these commands to check if NetworkManager is active, enabled, and print runtime status information of the NetworkManager.

# systemctl is-active NetworkManager
# systemctl is-enabled NetworkManager
# systemctl status NetworkManager
  • Start NetworkManager

To start NetworkManager we run:

# systemctl start NetworkManager
  • Stop NetworkManager

In addition, to stop or deactivate the NetworkManager, run:

# systemctl stop NetworkManager
  • Restart NetworkManager

If we make changes to interface configurations files or NetworkManager daemon’s configuration, we can restart to apply the changes.

# systemctl restart NetworkManager
  • Reload NetworkManager

To reload the NetworkManager daemon’s configuration without restarting the service, we run:

# systemctl reload NetworkManager

 

Step3 – Using NetworkManager Tools and Working with ifcfg Files

The NetworkManager supports some tools for users to interact with it, which are:

  • nmcli – a command-line tool to configure networking.
  • nmtui – a simple curses-based text user interface, to configure and manage network interface connections.
  • Other tools include the nm-connection-editor, control-center, and network connection icon.

To list the devices detected by NetworkManager, we run the nmcli command:

# nmcli device
OR
# nmcli device status

To view all active connections, run:

# nmcli connection show -a

 

Step4 – Set Static IP Address on RHEL/CentOS 8

Network interface-specific configuration files are at /etc/sysconfig/network-scripts/ directory. We can edit them, for example, to set a static IP address for RHEL/CentOS 8 server.

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

Here is a sample configuration to set a static IP address.

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=e81c46b7-441a-4a63-b695-75d8fe633511
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.0.55
PREFIX=24
GATEWAY=192.168.0.1
DNS1=8.8.8.8
PEERDNS=no

Eventually, save the changes. Then we reload all connection profiles or restart the NetworkManager for the changes to apply.

# nmcli connection reload
OR
# systemctl restart NetworkManager

 

Step5 – Start or Stop Network Services/Scripts Based on Network Connectivity

On the basis of network connectivity, NetworkManager allows users to execute services (such as NFS, SMB, etc.) or simple scripts.

For example, if we want to automatically mount a remote directory locally with sshfs, mount SMB shares, or mount NFS shares after switching between networks, we want such network services to execute not until NetworkManager is up and running.

This feature is provided by the NetworkManager-dispatcher service. Once the service is running, we can add our scripts to the /etc/NetworkManager/dispatcher.d directory.

All scripts must be executable and writable, and owned by root, for example:

# chown root:root /etc/NetworkManager/dispatcher.d/10-nfs-mount.sh
# chmod 755 /etc/NetworkManager/dispatcher.d/10-nfs-mount.sh

The dispatcher scripts will execute in alphabetical order at connection time and in reverse alphabetical order at disconnect times.

 

Step6 – Using Legacy Network Scripts

Network scripts are deprecated in RHEL/CentOS 8 and do not come by default. However, to use it, we have to install the network-scripts package.

# yum install network-scripts

Once installed, this package provides a new version of the ifup and ifdown scripts which call NetworkManager via the nmcli tool.

[Need help with the tools? We are here for you]

 

Conclusion

In short, the NetworkManager daemon manages the networking service to dynamically configure and control network devices and keep connections up and active when they are available.