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).
- 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
NIC with MAC 00:10:5a:3e:c5:6a should correspond to
NIC withMAC 00:02:b3:b8:66:d6 should correspond to
- 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.
- Use the following syntax in the .rules files to hard code the ordering:
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:
- Save the file and restart. Then type
ifconfig -ato check that it has worked