Fixing Ubuntu's ethN device names when you swap hardware

September 27, 2007

If you swap an Ubuntu 6.06 system disk between hardware units (even nominally identical hardware units, like from one Dell 2950 to another PE2950), the system will come up scrambled Ethernet devices and you won't be on the network. (As we found out the hard way today.)

This happens because the only way Ethernet devices get consistent numbers on Ubuntu machines is because Ubuntu remembers the mapping between hardware ethernet addresses and the ethN name that they should get. When you transplant hardware, the hardware addresses change, nothing matches up any more, and your Ethernet NICs get random names.

(This also means that eth0 in kernel messages is usually not the device that ifconfig eth0 is talking about.)

/etc/iftab has the ethN ↔ hardware ethernet address mapping; unknown hardware addresses will be given ethN names that are not in use in here. /etc/network/interfaces tells you what ethN names you are using for what actual network connections.

Because Ubuntu seems to more or less randomly renumbers ethN devices on each reboot, you can't just remove /etc/iftab, fix your interfaces file to use the 'natural' names, and be done. Instead you have to reconstruct it with the right MAC addresses for any interfaces you care about. Steps to do this:

  • look at /etc/network/interfaces to find out what ethN names you care about.

  • find out what current ethN names are connected to the network:
    cd /sys/class/net
    for i in eth*; do ifconfig $i up; done
    dmesg | tail -10

    Now look for devices that have reported that their link is up. If you are lucky, the machine only has one network connection and you are done.

    If the machine has multiple network connections you will need to use various means (eg, unplugging and replugging network cables and watching kernel messages) to figure out which ethN name is which connection.

  • look up the MAC of each interface you care about with ifconfig ethN, and edit /etc/iftab to update the MAC for the 'correct' name for that interface. Delete every other ethN name in iftab, just so they don't confuse anyone.

Once you have updated everything you care about, reboot.

Optionally and possibly later, add name/MAC mappings for everything to iftab, so that if you add another network connection in the future it's sure to have a stable name. If you do this you will want to map out what each physical port's Ethernet address is, so that you can assign the names in a consistent and logical way and do things like make sure that a card with two NICs gets two consecutive ethN names.

For bonus charm iftab is apparently being deprecated in favour of another way of doing this, so the next Ubuntu LTS release will probably require an entirely different way of fixing this.

(Of course, Ubuntu does not supply a convenient program to (re)build an iftab for you.)

Sidebar: on the random renumbering issue

If a kernel device driver is responsible for more than one Ethernet device, it always reports them in a consistent internal order. If you have no iftab file, Ubuntu will probably only reorder blocks of ethN devices served by different drivers. Eg, if you have four Intel NICs and two Broadcom NICs, the internal order in the Intel NICs and the Broadcom NICs is probably always going to be consistent, and the first Intel NIC will be either eth0 (Intel driver loaded first) or eth2 (Broadcom driver loaded first). However, which driver is loaded first seems to be more or less random.

If Ubuntu does have an iftab file it will rename the kernel's initial ethN names to not use any ethN name claimed by iftab, and I believe the order it does this renaming is really random and can completely shuffle ethN names, so that if iftab claims eth0 through eth3, you could have eth4 being the third Intel NIC, eth5 being the first Broadcom NIC, and so on.

Written on 27 September 2007.
« Thinking about why Apache waits for CGIs to close standard output
Phase objects: simple decent error reporting for Python programs »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Sep 27 15:20:07 2007
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.