Linux: Udev Multiple Interfaces Switching Names

Since udev 197, a predictable network interface names for hardware network interfaces have been implemented. Unfortunately, in huge amount of cases, this “improvement” results in network devices randomly switching names. This is how to deal with it…

You may have experienced that whatever eth0/eth1 to MAC assignment you provide in the /etc/udev/rules.d/ directory, nothing takes effect.


Assuming you have two network interface cards (NICs) and you know both of their MAC addresses. First, update the ruleset in /etc/udev/rules.d/80-net-name-slot.rules as follows:

ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
Originally, the file was named as:

ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules

This is because of:

:: Network device naming is now controlled by udev's net_setup_link
   builtin. Refer to the NETWORK LINK CONFIGURATION section of the
   udev manpage for a full description.
:: Renaming 80-net-name-slot.rules to 80-net-setup-link.rules in order
   to preserve existing network naming behavior.
«etc/udev/rules.d/80-net-name-slot.rules» -> «etc/udev/rules.d/80-net-setup-link.rules»

Now, assuming the first NIC is dedicated for WAN connectivity thus having its W:A:N:M:A:C MAC address, and the second NIC is dedicated for LAN connectivity thus having its L:A:N:M:A:C MAC address, it is necessary to update the /etc/udev/rules.d/70-persistent-net.rules file as follows:

echo -e "# cat /etc/udev/rules.d/70-persistent-net.rulesn
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="W:A:N:M:A:C", NAME="wan"n
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="L:A:N:M:A:C", NAME="lan""
> /etc/udev/rules.d/70-persistent-net.rules

This will make sure your device names will not switch next time you reboot your computer and they will be named as wan and lan.

Post-name-change Setup

Be careful, that it’s necessary to update the following as well!!!

1) The init scripts:

rm /etc/init.d/net.eth0
rm /etc/init.d/net.eth1
ln -s /etc/init.d/net.lo /etc/init.d/net.wan
ln -s /etc/init.d/net.lo /etc/init.d/net.lan

2) The NICs’ IP configuration (address, routing, DNS, NTP, …):

nano /etc/conf.d/net

and replace the eth0/1 statements with lan/wan.

3) Any iptables/ip6tables rules related to a specific interface needs to be modified as well. Check:

iptables -nvL | grep eth
ip6tables -nvL | grep eth

4) If there are any specific rules in /etc/sysctl.conf, these need to be corrected as well. Check:

cat /etc/sysctl.conf | grep eth

Hopefully, no more “surprises” like this one are about to come in the future.

This entry was posted in Linux, Server and tagged , , , , , . Bookmark the permalink.