MFEL Misnamed IP Ports

Jan 2017
After installing CentOS on to a server (software or appliance) you may have some IP ports that are incorrectly named. I have only seen this in CentOS v7.x and it mostly happens on SW only or appliance installs where the wrong CentOS .img file has been used (if you put the G7 CentOS7 build on a G6 for example).
When you look at the IP ports, you expect to see the ports listed as eth0, eth1, eth2 etc. However, you may see the ports listed with names such as:
2: ens513f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
3: ens513f1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
4: ens513f2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
5: ens513f3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
6: enp4s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
7: enp4s0f3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
Sticking with these names is not an issue, but you won't likely remember then, and nor will customers, so ideally we need to change them, the process is quite simple, but you need to work out which port is which first.

Identify Ports

The simplest way to do this that I have used is to only connect a single interface on the server, and use the following to see what port is 'UP'
Lets assume I connect the first port from the left hand side (normally eth0)

ip link show |grep "state UP"
This will display the connected port because it will be in the UP state
6: enp4s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

So in the above example we can see that interface 0 (eth0) is the port identified as enp4s0f0.
Repeat this for all the interfaces until you have mapped each name to each physical interface.

Rename ifcfg-xxxxxx files

The configuration files need to match the interface names so that it is easy to identify which file belongs to which interface. Here is an example of the interface files before renaming (this server has 6 interfaces).
Navigate to /etc/sysconfig/network-scripts

-rw-r–r–. 1 root root 282 Jan 20 00:37 ifcfg-enp4s0f0

-rw-r–r–. 1 root root 281 Jan 20 00:37 ifcfg-enp4s0f3

-rw-r–r–. 1 root root 281 Jan 20 00:37 ifcfg-ens513f0

-rw-r–r–. 1 root root 281 Jan 20 00:37 ifcfg-ens513f1

-rw-r–r–. 1 root root 281 Jan 20 00:37 ifcfg-ens513f2

-rw-r–r–. 1 root root 281 Jan 20 00:37 ifcfg-ens513f3

-rw-r–r–. 1 root root 254 Sep 16 2015 ifcfg-lo

Once you have identified which file belongs to which interface, then you can rename the files using the mv command.

mv sourcefile destination file
mv ifcfg-enp4s0f0 ifcfg-eth0

Repeat this process until all of the files have been renamed. (leave the ifcfg-lo file)

Edit the ifcfg-xxxxx files

The files will now need to be edited, and a few changes made to each file. Open the file ifcfg-eth0

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp4s0f0
UUID=1c31d575-3a80-41c0-ad24-92be3d9b7b9e
DEVICE=enp4s0f0
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

Add or Edit the following lines:
DEVICE=eth0 This should be the actual interface name, you don't have to change the DEVICE name
HWADDR=00:1e:67:d8:a9:51 You can get the address from the ip a command.
ONBOOT=yes If this is no, change it to yes
Make these changes for all of the files.