Managing multiple NICs in Linux

When running a Linux kernel 2.6, it’s very difficult to tell network interfaces apart when they use the same driver or chipset. This can also be confusing even on systems with multiple network interfaces using different chipsets or drivers. Which one is eth0? Which one is eth1? What’s even worse is that it seems udev doesn’t always assign the same name to each network interface between reboots, so the same card sometimes is named eth0, and sometimes eth2, for example.

Fortunately, there is a way to tie each network interface card with a fixed network interface name by using udev rules.

My system has four network interfaces:

  • 2 Ethernet 3Com 3C905 10/100, using the 3c59x linux driver.
  • 1 Ethernet SMC 9452TX 10/100/1000, using the skge linux driver.
  • 1 Wireless 802.11g SMC 2835W V3, using ndiswrapper.

Let’s suppose udev has given the name eth2 to the SMC 9452TX. Now, let’s suppose we want to rename this network interface to eth0 or a more meaningful name like lan or e1000. We can write a udev rule to perform the renaming, thus making a persistent device-name association.

To write this rule, first we need to use some attribute which is unique to the device. For network devices, we can use the MAC address. Using udevinfo we can retrieve all attributes for the eth2 device:

# udevinfo -a -p /sys/class/net/eth2 looking at class device '/sys/class/net/eth2': KERNEL=="eth2" SUBSYSTEM=="net" SYSFS{addr_len}=="6" SYSFS{address}=="00:13:AA:AA:AA:AA" SYSFS{broadcast}=="ff:ff:ff:ff:ff:ff" SYSFS{carrier}=="1" SYSFS{features}=="0x1023" SYSFS{flags}=="0x1003" SYSFS{ifindex}=="4" SYSFS{iflink}=="4" SYSFS{mtu}=="1500" SYSFS{tx_queue_len}=="1000" SYSFS{type}=="1" SYSFS{weight}=="64"

SYSFS{address}=="00:13:AA:AA:AA:AA" is the udev attribute used to refer to this network interface MAC address, the SMC 9452TX that is being named eth2 by default. We can repeat this step to retrieve the attribute for every network interface for which we want to write a udev rule.

Once we’ve got all the attributes, we can place the udev rules in a file named code>/etc/udev/rules.d/99-user.rules:

KERNEL=="eth*", SYSFS{address}=="00:13:AA:AA:AA:AA", NAME="e1000" KERNEL=="eth*", SYSFS{address}=="00:04:BB:BB:BB:BB", NAME="e100" KERNEL=="eth*", SYSFS{address}=="00:04:CC:CC:CC:CC", NAME="e10"

Now, the easiest way of making these changes take effect is rebooting. Next time, udev will rename the network interfaces to e1000, e100 and e10 instead of eth0, eth1 or eth2. What’s more, now it’s easier to tell the interfaces apart from each one.

5 Responses to “Managing multiple NICs in Linux”

  1. Thank you very much for your clear and helpful instructions!

  2. Thanks a lot ! It is indeed really helpful.

  3. Excellent! I’ve been looking for this info for ages as my devices kept swapping on me. The one change I did have to make (I am using Ubuntu dapper) was to use 20-user_ifcfg.rules (instead of 99-user.rules) so that it runs prior to 25-iftab.rules

  4. it should be KERNEL==”eth*” not KERNEL=”eth*”, shouldn’t it? Otherwise worked great on my dapper machine wiht the change mentioned above by Angelo Berios

  5. You are completely right, John. I’ve fixed the typo. Thanks! :)

Leave a Reply