Are you trying to manage Networking with NetworkManager in RHEL?
This guide is for you.
In RHEL and CentOS 8 the networking service is managed by the NetworkManager daemon and it is used to dynamically configure and control network devices and keep connections up and active when they are available.
NetworkManager comes with numerous benefits such as support for easy network setup and management using both command-line interface and graphical user interface tools, provides an API through D-Bus which allows for querying and controlling network configuration, support for configuration flexibility and much more.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform NetworkManager related queries.
In this context, we shall look into how to manage Networking with NetworkManager in RHEL/CentOS 8.
How to 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:
i. It supports the traditional ifcfg type configurations (eg. ifcfg-eth0, ifcfg-enp0s3).
ii. It does not provide Network scripts by default and they are deprecated.
iii. A minimal installation provides a new version of the ifup and ifdown scripts that call NetworkManager via the nmcli tool.
iv. To run the ifup and ifdown scripts, NetworkManager must run.
1. 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/.
2. 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:
i. 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
ii. Start NetworkManager
To start NetworkManager we run:
# systemctl start NetworkManager
iii. Stop NetworkManager
In addition, to stop or deactivate the NetworkManager, run:
# systemctl stop NetworkManager
iv. 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
v. Reload NetworkManager
To reload the NetworkManager daemon's configuration without restarting the service, we run:
# systemctl reload NetworkManager
3. Using NetworkManager Tools and Working with ifcfg Files
The NetworkManager supports some tools for users to interact with it, which are:
i. nmcli – a command-line tool to configure networking.
ii. nmtui – a simple curses-based text user interface, to configure and manage network interface connections.
iii. 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
# nmcli device status
To view all active connections, run:
# nmcli connection show -a
4. 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:
Eventually, save the changes.
Then we reload all connection profiles or restart the NetworkManager for the changes to apply:
# nmcli connection reload
# systemctl restart NetworkManager
5. 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.
6. 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.