• Renaming and reordering of network interfaces in linux using udev

    by  • October 4, 2009 • linux, networking, Uncategorized • 3 Comments

    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

    About

    .NET developer at thetrainline.com, previously web developer at MRM Meteorite. Awarded a PhD in misbehaviour detection in wireless ad-hoc networks.A keen C# ASP.net developer bridging the gap with APIs and JavaScript frameworks, one web app at a time.

    http://www.paulkiddie.com

    3 Responses to Renaming and reordering of network interfaces in linux using udev

    1. Pingback: Renaming and reordering of network interfaces in linux using udev

    2. Pingback: Paul Kiddie’s Blog : Force udev to reassign ethX identifiers in Ubuntu 8.04

    3. Pingback: Reordering linux eth numbers « windowsmasher

    Leave a Reply

    Your email address will not be published. Required fields are marked *