Fixed NIC names (eth\*) on RHEL and CentOS

Tristan Terpelle Summary: How to go back to the classic naming of eth devices on EL7

EL7 uses systemd magic to give network devices consistent and predictable names based on firmware, topology, and location information. But what if you just want the NICs in your VMware virtual machine to be named eth0, eth1, ... based on their MAC address?

In bug 1046302 it says to use a different naming scheme than "eth". The CentOS 7 FAQ (and articles by Red Hat as well) tell you to use the boot options net.ifnames=0 biosdevname=0 to get the old naming scheme back.

When I did this, udev was unable to rename my devices to what I wanted, because the target name already existed, as mentioned in the bug report:

Jun 24 10:26:52 example systemd-udevd[388]: error changing net interface name eth0 to eth1: File exists

The fix was simple: use the new system together with udev rules.

  1. add net.ifnames=1 biosdevname=1 to GRUB_CMDLINE_LINUX in /etc/default/grub
  2. rebuild the GRUB configuration with grub2-mkconfig -o /boot/grub2/grub.cfg
  3. create /etc/udev/rules.d/70-persistent-net.rules and add some lines like
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:11:22:33:44:55", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="22:33:44:55:66:77", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
  1. reboot

In your boot logs you will see:

Jun 24 11:40:57 example systemd-udevd[271]: renamed network interface eth0 to ens256
Jun 24 11:40:59 example systemd-udevd[580]: renamed network interface ens256 to eth1

This has only been tested with VMware virtual machines, I don't know (yet) how it works on bare metal machines.

Tagged , , , , , , ,