How to be sure network interfaces have always the same names

root's picture

You are here because sometimes you find the network interfaces renamed after any tiny modification (like kernel upgrade for example). Well, fortunately there are ways to prevent this by binding the mac address to specific names. There are several ways to achieve this. Read on.

Rename Network Interface using udev.

Write to the following file (create it if it doesn't exist) as below:

root@pluto:~# cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="05:02:17:12:34:56", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="05:02:17:78:90:12", KERNEL=="eth*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="05:02:17:34:56:78", KERNEL=="eth*", NAME="eth2"

Rename Network interfaces with nameif.

In Debian this comes with net-tools package. The problem here is you cannot rename devices with names already in use so you will have to remove the existing network devices first or rename them totally different (check for want_ prefix on the example below).

1. Create/update /etc/mactab:

root@pluto:~# cat /etc/mactab 
want_eth0 18:24:37:0c:e7:f8
want_eth1 18:24:37:12:bw:9c
want_leetinterface 18:24:37:85:2e:c7
want_iscsi 18:24:37:11:6f:bd

2. Create/update /etc/network/if-pre-up.d/nameif and make it executable (with chmod +x):

root@pluto:~# cat /etc/network/if-pre-up.d/nameif

This network rule above tries to set want_ethX as written previously in /etc/mactab but if you want, you can put the lines from /etc/mactab directly in /etc/network/if-pre-up.d/nameif.

In both examples above, do not forget to check your interfaces and restart networking to reflect the modifications.

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself!
Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.