Paul Kiddie

Renaming and reordering of network interfaces in linux using udev

October 04, 2009

As part of a network testbed I’m working on I need to manage network interfaces and dedicate a network interface to a Linux container. Now depending on the network hardware, the ordering of the eth devices does not necessarily correspond to the ordering on the PCI bus but instead seems to correspond to the order of detection. This seems to be OK for homogeneous environments such as a PC stacked full with ethernet cards from the same manufacturer but not so good where the PC has network adapters from different manufacturers, so the top NIC may correspond to eth0, the next one down to to eth2, the next to eth1 and so on…

I wanted a way of ensuring that the eth naming scheme corresponds to the ordering of network interfaces, running top to bottom in the case. To do this, you can use udev in the following way (thanks to http://www.debianhelp.co.uk/udev.htm for the tip).

  1. Record the MAC address of each adapter and the specific ordering you require. Lets assume the following:

    NIC with MAC 00:60:08:7b:b3:a4 should correspond to eth0 NIC with MAC 00:10:5a:3e:c5:6a should correspond to eth1 NIC withMAC 00:02:b3:b8:66:d6 should correspond to eth2

  2. Create a new ‘rules’ file in the /etc/udev/rules.d directory, calling it something like 010_netinterface.rules. These rules are executed on start up of udev.

  3. Use the following syntax in the .rules files to hard code the ordering:

    KERNEL=="eth*",SYSFS{address}=="_mac_id_here_",NAME="_name_here_"

    Where mac_id_here corresponds to the MAC address and name_here corresponds to the eth device. You can also use this to rename any particular network interface but bear in mind that some applications may assume standard ethX for network interfaces.

    In our example, the .rules file becomes:

    KERNEL=="eth*",SYSFS{address}=="00:60:08:7b:b3:a4",NAME="eth0" KERNEL=="eth*",SYSFS{address}=="00:10:5a:3e:c5:6a",NAME="eth1" KERNEL=="eth*",SYSFS{address}=="00:02:b3:b8:66:d6",NAME="eth2"

  4. Save the file and restart. Then type ifconfig -a to check that it has worked


👋 I'm Paul Kiddie, a software engineer working in London. I'm currently working as a Principal Engineer at trainline.