×


Manage Networking with NetworkManager in RHEL CentOS 8

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

OR

# 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:
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


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.

[Need help with NetworkManager on CentOS?  We are here for you. ]


Conclusion

This article covers NetworkManager daemon for managing the networking service to dynamically configure and control network devices and keep connections up and active when they are available.
Netstat is a command line utility that can be used to list out all the network (socket) connections on a system.
It lists out all the tcp, udp socket connections and the unix socket connections.
To reboot Linux using the command line: To reboot the Linux system from a terminal session, sign in or “su”/”sudo” to the “root” account.
Then type “ sudo reboot ” to reboot the box. Wait for some time and the Linux server will reboot itself.

To troubleshoot network connectivity with Linux server:
i. Check your network configuration.
ii. Check the network configuration file.
iii. Check the servers DNS records.
iv. Test the connection both ways.
v. Find out where the connection fails.
vi. Firewall settings.
vii. Check Host status information.

To change the hostname in Linux Ubuntu:
i. Type the following command to edit /etc/hostname using nano or vi text editor: sudo nano /etc/hostname. Delete the old name and setup new name.
ii. Next Edit the /etc/hosts file: sudo nano /etc/hosts.
iii. Reboot the system to changes take effect: sudo reboot.

To reinstall #network service in #Linux (#Ubuntu / #Debian):
i. Use the following command to restart the server networking service. # sudo /etc/init.d/networking restart or
# sudo /etc/init.d/networking stop # sudo /etc/init.d/networking start else # sudo systemctl restart networking.
ii. Once this done, use the following command to check the server network status.