Saturday, 12 September 2020

Managing the network with Network manager in Redhat Enterprise Linux 7

With the introduction of RHEL7 there is a new profile based network management. Like many other Daemons Network Manager in RHEL 7 is also a Daemon, it monitors and manages the network settings. Network manager can be managed using nmcli and other graphical tools.  In Red Hat Enterprise Linux 7 please note this is the default networking service and is provided by Network Manager,  basically this service is a dynamic network service control and there is a configuration daemon to keep network devices and connections up and active when they are available. An interesting thing to note is that the traditional ifcfg type configuration files are still supported which i will cover in this post.

The main advantage of this utility is that managing the networking is way much easier: Network Manager ensures that network connectivity works. When it detects that there is no network configuration in a system but there are network devices, Network  Manager creates temporary connections to provide connectivity.

These tools will automatically update /etc/sysconfig/network-scripts  in the back-end. So as we are aware commands and graphical tools are updating the network configuration files, human errors are eliminated. 

Lets see how Network Manager works : 

# First i will start my current network interface, The ifup command basically brings the network interface up, allowing it to transmit and receive data. Technically ifup command is used to configure network interfaces based on interface definitions in the file /etc/network/interfaces.

[root@node2 Desktop]# cd /etc/sysconfig/network-scripts/

[root@node2 network-scripts]# ifup ifcfg-eno16777736 

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/0)

# Lets get into network manager now, Current devices

[root@node2 ~]# nmcli con show

NAME         UUID                                  TYPE            DEVICE

eno16777736  bcc252b1-98d3-4fb6-a005-2caad8422622  802-3-ethernet  eno16777736

# Now lets make a new connection named as "RHEL_NEW" which will automatically connect as an Ethernet connection eth0 device using DHCP.

[root@node2 ~]# nmcli con add  con-name "RHEL_NEW" type ethernet ifname eth0

Connection 'RHEL_NEW' (5f87ee25-7007-4a35-b343-8e1351443f54) successfully added.

# Lets confirm it 

[root@node2 ~]# nmcli con show

NAME         UUID                                  TYPE            DEVICE

RHEL_NEW     5f87ee25-7007-4a35-b343-8e1351443f54  802-3-ethernet  --

eno16777736  bcc252b1-98d3-4fb6-a005-2caad8422622  802-3-ethernet  eno16777736

# Lets configure the static IP for the new connection, you need to specify the IP address and gateway.

[root@node2 network-scripts]# nmcli con add  con-name "RHEL_NEW"  ifname eth0 autoconnect no type ethernet ip4 gw4

Connection 'RHEL_NEW' (61a29c5f-72fd-4b4c-b850-1f139dd8d03b) successfully added.

# So when we try to bring up the interface we face this issue, lets troubleshoot it

[root@node2 network-scripts]#  nmcli connection up RHEL_NEW

Error: no device found for connection 'RHEL_NEW'.

[root@node2 network-scripts]#  systemctl -l status network.service

network.service - LSB: Bring up/down networking

   Loaded: loaded (/etc/rc.d/init.d/network)

   Active: failed (Result: exit-code) since Sat 2020-09-12 13:16:53 IST; 1min 0s ago

  Process: 3240 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)

  Process: 4047 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 network[4047]: RTNETLINK answers: File exists

Sep 12 13:16:53 systemd[1]: network.service: control process exited, code=exited status=1

Sep 12 13:16:53 systemd[1]: Failed to start LSB: Bring up/down networking.

Sep 12 13:16:53 systemd[1]: Unit network.service entered failed state.

Not to forget i am in directory /etc/sysconfig/network-scripts

[root@node2 network-scripts]# pwd


Making sure hardware address was put in the network interface was up post that

[root@node2 network-scripts]# cat ifcfg-RHEL_NEW




















[root@node2 network-scripts]#  nmcli connection up RHEL_NEW

Connection successfully activated 

# As mentioned earlier in this post this works with ifdown and ifup as well

[root@node2 network-scripts]# ifdown ifcfg-RHEL_NEW

[root@node2 network-scripts]# ifup ifcfg-RHEL_NEW

NetworkManager is installed by default on Red Hat Enterprise Linux. If it is not, enter as root:

~]# yum install NetworkManager

To check whether NetworkManager is running:

~]$ systemctl status NetworkManager

NetworkManager.service - Network Manager

   Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled)

   Active: active (running) since Fri, 11 Sep 2020 11:30:04 +0100; 1 days ago

Note that the systemctl status command displays Active: inactive (dead) when NetworkManager is not running.

To start NetworkManager:

~]# systemctl start NetworkManager

To enable NetworkManager automatically at boot time:

~]# systemctl enable NetworkManager

nmcli is the one way of working with networking manager, while you can still use nmtui, nm-connection-editor, control-center, network connection icon.

Lets understand about these options : 

nmcli : A command-line tool which enables users and scripts to interact with NetworkManager. Note that nmcli can be used on systems without a GUI such as servers to control all aspects of NetworkManager. It has the same functionality as GUI tools.

nmtui : A simple curses-based text user interface (TUI) for NetworkManager

nm-connection-editor : A graphical user interface tool for certain tasks not yet handled by the control-center utility such as configuring bonds and teaming connections. You can add, remove, and modify network connections stored by NetworkManager. To start it, enter nm-connection-editor in a terminal.

control-center : A graphical user interface tool provided by the GNOME Shell, available for desktop users. It incorporates a Network settings tool. To start it, press the Super key to enter the Activities Overview, type Network and then press Enter. The Network settings tool appears.

network connection icon : A graphical user interface tool provided by the GNOME Shell representing network connection states as reported by NetworkManager. The icon has multiple states that serve as visual indicators for the type of connection you are currently using.