Interface Renaming Scripts

June 2018

For anyone that has used CentOS/Red Hat prior to version 7, or indeed other versions of Linux, the norm for network interface naming is to use eth0, eth1, eth2 etc.
CentOS 7 changed this naming convention, for two main reasons.

1. Security (knowing particular interface names is considered a security risk).
2. Deterministic Naming. While the interfaces names used have always been the same, the
mapping has been a bit hit and miss, and so on 10 identical servers, while the names are
the same, eth0 may not always be the same physical interface (like Windows it can move).

Here we are looking at a couple of scripts written by an engineer here at work (not by me). While these scripts can work very well, there are a couple of things to be aware off.
Firstly the two scripts, these are:

1. store_macaddr_mapping.sh - stores server MAC addresses for use by the rename_network_interfaces.sh script.
2. rename_network_interfaces.sh - renames the interfaces using the information generated
by store_macaddr_mapping.sh

store_macaddr_mapping.sh

The store_macaddr_mapping.sh is the trickier of the two scripts. I don't know what hardware this script was written for, but for me it has been a little troublesome. But it provides a good starting point for the renaming process.
Copy this file to the server that needs the interfaces renaming, then give the file execute rights.

chmod 777 store_macaddr_mapping.sh

Now execute the file using the following syntax:

./store_macaddr_mapping.sh network_mapping.csv

A file network_mapping.csv will have been created. you can view this file using:

cat network_mapping.csv

Here is an example of what I have:

enp4s0f0;00:1e:67:d1:24:0e
;00:1e:67:d1:24:0f
;00:1e:67:d1:24:10
;00:1e:67:d1:24:11
;00:1e:67:d8:b3:68
;00:1e:67:d8:b3:69

The file should contain the following:

interface;mac
interface;mac
interface;mac
interface;mac
etc.