Centos – How to set ethernet devices to specific hardware on Centos 7

centoscentos7linux-networking

I have a Centos 7 system where I've disabled the new network naming system and reverted to the old system (eth0, eth1, etc.). I've done this because I'm using this in an RDO Openstack setup, and this needs the same ethernet device names on a few different hosts. Some of these hosts are virts under kvm and use the eth naming system.

Since doing this, every few reboots, my ethernet devices get flipped around.

On a healthy boot, I see

[ 11.172339] tg3 0000:03:00.0 eth0: Tigon3 [partno(BCM95723) rev 5784100] (PCI Express) MAC address 68:b5:99:72:d8:02
[ 11.269599] e1000e 0000:02:00.0 eth1: (PCI Express:2.5GT/s:Width x1) 68:05:ca:04:90:16

On a 'bad boot', those will be flipped around and the e1000e will be eth0 with the tg3 being eth1.

I've done the following so far:

  • Added "net.ifnames=0 biosdevname=0" to the GRUB_CMDLINE_LINUX line in /etc/default/grub
  • grub2-mkconfig -o /boot/grub2/grub.cfg
  • created /etc/udev/rules.d/70-persistent-net.rules

After running the grub2-mkconfig, I see the following in /boot/grub2/grub.cfg (which implies my change above is taking effect)

linux16 /boot/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=eabee081-85f8-4f33-b72a-fbbdc575e010 ro vconsole.keymap=uk crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb net.ifnames=0 biosdevname=0 quiet

The contents of 70-persistent-net.rules are as follows:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="68:B5:99:72:D8:02", ATTR{type}=="1", KERNEL=="eth", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="68:05:CA:04:90:16", ATTR{type}=="1", KERNEL=="eth", NAME="eth1"

I've also tried changing the letters in the MAC addresses in this file to lowercase to match the output of dmesg. This makes no difference.

I have NetworkManager disabled and I have the HWADDR entry in /etc/sysconfig/network-scripts/ifcfg-eth*.

Under ubuntu and earlier versions of Centos, the above works fine and reliably.

None of this is leading to predictable devices on this box with Centos 7 though.

Any advice on how to pin these devices to the eth names would be much appreciated!

Best Answer

I investigated further and found more details.
The reason for this unfavorable behaviour were race conditions between the kernel and the udev software (the developers stated in a bug report).
So the developers of udev have decided to remove the reliable naming of NICs as ethX and force a less predictable naming instead.
They removed the code which allowed the admin to use a reliable order of the ethX interfaces and also added code which refuses to use any ethX name which has already been used by the kernel as the inernal NIC name.

So it seems you cannot receive reliable ordering if you want to use the names eth0, eth1 and the like anymore.
Some suggest to use names like netX instead.
It may also work if you set up ethX with X greater than the real number of interface.


I was the original poster who thought he had found the solution, when in fact it was just a temporary one. After a few test boots I found the ethernet devices to be named randomly and not the way I defined in 60-net.rules.

I had posted the original answer anonymously and then decided to sign up to be able to participate more. So I am sorry. The answer posted below DOES NOT actually solve the problem originally answered. It does so for a few boots, but it does not work reliable.


I have had success with the Minimal-CD of CentOS 7 and the following strategy:

I did a lot of things which didn't help, so I had to change a few of them back.

I reinstalled biosdevname (had it removed).

I edited /etc/default/grub and added biosdevname=0 AND ifnames=0 to the CMDLINE.

I remade the grub config with: grub2-mkconfig -o /boot/grub2/grub.cfg

Also I imported the following two files from an CentOS 6.5 installation:

/lib/udev/rules.d/75-persistent-net-generator.rules

/lib/udev/write_net_rules

(but these may not have had any effect at all)

Then I created a file called 60-net.rules in /etc/udev/rules.d/ with one line for each NIC I have:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="aa:bb:cc:dd:ee:ff", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth1"

(Of course the MAC ADDRESS 'aa:bb:...' has to be the correct one).

After that I booted and it worked.

Related Topic