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.


10 thoughts on “Managing multiple NICs in Linux

  1. 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

  2. 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

  3. 3 years later…
    I was configuring this, but it turns out that ubuntu-server 8.10 already has a 70-persistent-net.rules (generated by 75-persistent-net-generator.rules)
    I was hoping to use eth_green, eth_red, etc. for the different sub-nets connected to my firewall, but this is no longer nececery if ubuntu already keeps the names persistent.

  4. Pingback: links for 2009-11-02 « Donghai Ma

  5. IE is still the least-compatible, buggiest browser. By using it, you are driving up the cost of development on the web. Web-site developers must put in extra code to work around IE’s flaws so that you can use their site. Do a quick web search for “IE Hacks” to get a sense of the scope of the problem. Luckily there are many people willing the share their experience in these workarounds, but it is still frustrating and slow to track down bug when IE misbehaves.

  6. I’ve read over numerous of your current entries and I was wondering if you were interesting in swapping webpage links? I am constantly seeking to swap links with personal blogs on similar content! I look forward to hearing back from you quickly.

  7. whoah this blog is magnificent i really like reading your posts. Keep up the great work! You already know, lots of persons are hunting round for this info, you could help them greatly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s