Wednesday 8 February 2017

Red Hat Enterprise Linux 7 - Driving Network Manager via Command-Line

This is definitely a WIP, and results from my experiences with Red Hat Enterprise Linux 7.3, which does networking subtly differently to older versions of RHEL.

Having restored a VM from an OVA export ( using VMware Fusion on macOS ), I realised that I no longer had any network connectivity, even though the VM configuration hadn't changed.

I saw this from the VM console, whilst logged in as a root.

Firstly I checked the IP stack with ifconfig : -

ifconfig -a

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:38:a3:ca  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0  KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 340 (340.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 340 (340.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


So I've got an Ethernet interface - ens33 - which has no IP address.

Using Network Manager CLI, I checked the connection: -

nmcli connection

NAME         UUID                                  TYPE            DEVICE 
eno16777736  13756690-ac77-b776-4fc1-f5535cee6f16  802-3-ethernet  

which showed that the internal connection ( eno16777736 ) wasn't mapped to the ens33 interface.

This is easily resolved: -

nmcli connection modify eno16777736 connection.interface-name ens33

where I join the connection to the interface.

Now ifconfig shows a pukka IP address: -

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.153.130  netmask 255.255.255.0  broadcast 192.168.153.255
        inet6 fe80::20c:29ff:fefe:a16a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:fe:a1:6a  txqueuelen 1000  (Ethernet)
        RX packets 127  bytes 15722 (15.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 11401 (11.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 340 (340.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 340 (340.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


The actual IP configuration is, as before, handled via a script: -

/etc/sysconfig/network-scripts/ifcfg-eno16777736

TYPE="Ethernet"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="28ca0f72-3f90-41d1-a2f7-5ec6ea5fffbc"
DEVICE=ens33
ONBOOT="yes"
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes


which shows that the connection is using DHCP.

If I wanted to allocate a static IP address, I'd change the file as follows: -

TYPE="Ethernet"
BOOTPROTO="static"
IPADDR=192.168.153.133
NETMASK=255.255.255.0
GATEWAY=192.168.153.2

DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="28ca0f72-3f90-41d1-a2f7-5ec6ea5fffbc"
DEVICE=ens33
ONBOOT="yes"
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes


and restart the network service: -

service network restart

Restarting network (via systemctl):                        [  OK  ]

we now have this: -

ifconfig ens33

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.153.133  netmask 255.255.255.0  broadcast 192.168.153.255
        inet6 fe80::20c:29ff:fefe:a16a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:fe:a1:6a  txqueuelen 1000  (Ethernet)
        RX packets 961  bytes 88811 (86.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 539  bytes 75366 (73.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

So, to conclude, we have an interface - ens33 - and a Network Manager connection - eno16777736 - and NMCLI can show the join: -

nmcli connection

NAME         UUID                                  TYPE            DEVICE 
eno16777736  28ca0f72-3f90-41d1-a2f7-5ec6ea5fffbc  802-3-ethernet  ens33  

Thanks to this: -


and this: -


for inspiration.

For the record, at some point, I also had to do this: -

Map physical connection to interface

nmcli connection add type ethernet con-name ens33 ifname eth0

but I can't recall precisely how/why I got there, so we'll bank that for now :-)

No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...