Tuesday, 16 September 2014

NetworkManager on RHEL7

Objective: Introduction to NetworkManager using network tools on RHEL 7

Red Hat Enterprise Linux 7, the default networking service is provided by NetworkManager installed by default on RHEL, controls network and keeps up the network devices and their connections up and active.

users do not interact with NetworkManager system service directly, instead perform network configs using as below 

1. simple curses-based text user interface (TUI) for NetworkManager, nmtui
2. command line tool, nmcli, is provided to allow users and scripts to interact with NetworkManager
3. Graphical user interface tools are also available e.g control-center  provided by GNOME shell which incorporates a network settings tool.

Here, in this article I would discuss on using commnd line interface(nmcli) for controlling NetworkManager

In previous RHEL, default way to configure network was using network scripts(/etc/init.d/network) and any other installed script it calls. Although NetworkManager provides the default network service, it ensures that network scripts cooperate as well.

Red Hat Enterprise Linux 7, NetworkManager is started first, and /etc/init.d/network checks with NetworkManager to avoid tampering with NetworkManager's connections. NetworkManager is intended to be the primary application using sysconfig configuration files and /etc/init.d/network is intended to be secondary.


# systemctl status NetworkManager 
NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled)
   Active: active (running) since Tue 2014-09-16 07:05:22 IST; 45min ago
 Main PID: 648 (NetworkManager)
   CGroup: /system.slice/NetworkManager.service
           └─648 /usr/sbin/NetworkManager --no-daemon

Below are summarized nmcli commands as reference.

NetworkManager Commands Description
nmcli general status show the overall status of NetworkManager
nmcli connection show show all connections
nmcli connection show --active show only currently active connections
nmcli device status show devices recognized by NetworkManager
nmcli con up/down id <interface> start/stop interface
nmcli dev connect/disconnect iface <inetrface> start/stop interface
nmcli -p connection up <profile> ifname <interface> bring up the new connection
nmcli -p con show <profile> view detailed information about the newly configured connection


Configure manual IP address on the interface using nmcli 

Method 1 : 

 # ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:82:69:0b  txqueuelen 1000  (Ethernet)

# nmcli connection add con-name enp0s8 ifname enp0s8 type ethernet ip4 192.168.56.131/24 gw4 192.168.56.1
Connection 'enp0s8' (952e2bfa-1dcb-4612-9bb4-df347b5a8a50) successfully added.

# nmcli device show enp0s8
GENERAL.DEVICE:                         enp0s8
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:82:69:0B
GENERAL.MTU:                            1500
GENERAL.STATE:                          30 (disconnected)
GENERAL.CONNECTION:                     --
GENERAL.CON-PATH:                       --
WIRED-PROPERTIES.CARRIER:               on

# nmcli device connect enp0s8
Device 'enp0s8' successfully activated with '952e2bfa-1dcb-4612-9bb4-df347b5a8a50'.

# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.131  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fe82:690b  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:82:69:0b  txqueuelen 1000  (Ethernet)

Method 2 :

nmcli Interactive Connection Editor

# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::a00:27ff:fe82:690b  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:82:69:0b  txqueuelen 1000  (Ethernet)

# nmcli connection edit id enp0s8

===| nmcli interactive connection editor |===

Editing existing '802-3-ethernet' connection: 'enp0s8'

Type 'help' or '?' for available commands.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, ipv4, ipv6, dcb
nmcli> help
------------------------------------------------------------------------------
---[ Main menu ]---
goto     [<setting> | <prop>]        :: go to a setting or property
remove   <setting>[.<prop>] | <prop> :: remove setting or reset property value
set      [<setting>.<prop> <value>]  :: set property value
describe [<setting>.<prop>]          :: describe property
print    [all]                       :: print the connection
verify   [all]                       :: verify the connection
save     [persistent|temporary]      :: save the connection
activate [<ifname>] [/<ap>|<nsp>]    :: activate the connection
back                                 :: go one level up (back)
help/?   [<command>]                 :: print this help
nmcli    <conf-option> <value>       :: nmcli configuration
quit                                 :: exit nmcli
------------------------------------------------------------------------------
nmcli> 

nmcli> goto ipv4
You may edit the following properties: method, dns, dns-search, addresses, address-labels, routes, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-send-hostname, dhcp-hostname, never-default, may-fail
nmcli ipv4> print
['ipv4' setting values]
ipv4.method:                            auto
ipv4.dns:                               
ipv4.dns-search:                        
ipv4.addresses:                         

nmcli ipv4> set ipv4.addresses 192.168.56.131/24 192.168.56.1
Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes
nmcli ipv4> 

nmcli ipv4> print
['ipv4' setting values]
ipv4.method:                            manual
ipv4.dns:                               
ipv4.dns-search:                        
ipv4.addresses:                         { ip = 192.168.56.131/24, gw = 192.168.56.1 }

nmcli> save persistent
Connection 'enp0s8' (d0a11f5e-eb2b-4a7a-b225-71f8d07b5664) successfully updated.
nmcli> 
nmcli> activate enp0s8
Monitoring connection activation (press any key to continue)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
nmcli> 

[root@localhost ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.131  netmask 255.255.255.0  broadcast 192.168.56.255

Method 3 : 

Configure IP using ifcfg files


To configure an interface with static network settings using ifcfg files, for an interface with the name 
eth0, create a file with name ifcfg-eth0 in the /etc/sysconfig/network-scripts/ directory as 
follows:


DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.56.131
USERCTL=no
HWADDR=08:00:27:49:f1:68  <--- NOTE: Specify this as this may influence the device naming procedure.

How does the interface rename happens to be ?


A rule in /usr/lib/udev/rules.d/60-net.rules instructs the udev helper utility, /lib/udev/rename_device, to look into all /etc/sysconfig/network-scripts/ifcfg-suffix files. If it finds an ifcfg file with a HWADDR entry matching the MAC address of an interface it renames the interface to the name given in the ifcfg file by the DEVICE directive.

I, conclude hereby that the reader would have an understanding on how to configure and interact with NetworkManager.