wiki:interface_renaming_scripts

This is an old revision of the document!


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.


There are two issues here:

  1. The interface names need to be eth0, eth1 etc.
  2. The MAC Addresses are in the incorrect order, and this will break the mapping.


Both of these are easy to fix. Firsly you can manually edit the file, so that the interface names are correct, but more importantly, you need to get the MAC address order correct.
Use ip link show to show interfaces and MACS

  ip link show
  
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  2: ens513f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
      link/ether 00:1e:67:d1:24:0e brd ff:ff:ff:ff:ff:ff
  3: ens513f1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
      link/ether 00:1e:67:d1:24:0f brd ff:ff:ff:ff:ff:ff
  4: ens513f2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
      link/ether 00:1e:67:d1:24:10 brd ff:ff:ff:ff:ff:ff
  5: ens513f3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
      link/ether 00:1e:67:d1:24:11 brd ff:ff:ff:ff:ff:ff
  6: enp4s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT qlen 1000
      link/ether 00:1e:67:d8:b3:68 brd ff:ff:ff:ff:ff:ff
  7: enp4s0f3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
      link/ether 00:1e:67:d8:b3:69 brd ff:ff:ff:ff:ff:ff


From here we can see which MAC is associated with which interface (so I know that enp4s0f0 is the first interface on my server) this allows me to build the following file:

  eth0;00:1e:67:d8:b3:68
  eth1;00:1e:67:d8:b3:69
  eth2;00:1e:67:d1:24:0e
  eth3;00:1e:67:d1:24:0f
  eth4;00:1e:67:d1:24:10
  eth5;00:1e:67:d1:24:11


So now the network_mapping.csv file is ready to use.


wiki/interface_renaming_scripts.1529402246.txt.gz · Last modified: 2023/03/09 22:35 (external edit)