Renaming a Linux NIC interface

You may be wondering why this is even a topic of discussion. Well, certain Linux distros such as CentOS come with the main interface as eth0. For me, it’s not as big of a deal. The concern comes in when I am developing baselines and distributing them back into the community. The more I can do to ensure that things look the same across the distros, the better. In order to rename the interface, one can do the below.

1. Open a terminal and ensure you are Root.

2. Get the MAC and current listing of the interface. Be sure to make note of the MAC for a future step.

[root@localhost ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:da:a2:e7  txqueuelen 1000  (Ethernet)
        RX packets 2474  bytes 156828 (153.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        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 0  (Local Loopback)
        RX packets 898  bytes 78092 (76.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 898  bytes 78092 (76.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

3. Open/create the file we will use to edit the interface.

[root@localhost ~]# vi /etc/udev/rules.d/70-persistent-net.rules

4. Once the file is open, copy and paste the below (if its not already there). Put the MAC address of your system where it says “ATTR{address}==”. Input whatever you want the interface to be labeled as where it says “NAME=”.

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:00:00:00:00:00", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

5. Save and close the file.

6. Next disable the predictable naming rule. In order to do that, edit the /etc/default/grub file and add “net.ifnames=0″ to GRUB_CMDLINE_LINUX variable. You can do that by copying the below text which already has it in there.

[root@localhost ~]# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="vconsole.keymap=us crashkernel=auto  vconsole.font=latarcyrheb-sun16 net.ifnames=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

7. Save and close the file.

8. Next, run the below command to regenerate the GRUB configuration file with updated kernel parameters.

[root@localhost ~]# sudo grub2-mkconfig -o /boot/grub2/grub.cfg

9. Reboot the system.

10. Log back in and check that its change.

11. Verify settings after reboot.

[root@localhost ~]# ifconfig

12. Done!