In Ubuntu, ensure that the same NIC gets assigned the same interface each time it comes up

9,260

Solution 1

Ubuntu uses udev for hardware detection. Everytime a new NIC is found, udev generates a rule for it so it will use the same physical interface eth0, eth1, ...

If you do not change your hardware, you do not have to care about the interface names, they will stay the same. Should you replace a NIC, it will get the next free interface, eg. eth2. To re-assign eth0 to the new NIC you will have to edit /etc/udev/rules.d/70-persistent-net.rules and delete the old MAC and change eth2 to eth0.

For more information on udev and networking see here.

Solution 2

I think you want to look at mapping in /etc/network/interfaces.

Stanzas beginning with the word "mapping" are used to determine how a logical interface name is chosen for a physical interface that is to be brought up.

There's an example interfaces file here. Scroll down and there's:

mapping eth0 eth1
script /path/to/get-mac-address.sh
map 11:22:33:44:55:66 lan
map AA:BB:CC:DD:EE:FF internet

Share:
9,260

Related videos on Youtube

Lorin Hochstein
Author by

Lorin Hochstein

Updated on September 17, 2022

Comments

  • Lorin Hochstein
    Lorin Hochstein almost 2 years

    I'm running an Ubuntu 9.10 server that has multiple NICs in it. I'd like to make sure that each time the kernel boots up, the NIC with MAC address 01:23:45:67:89:ab gets assigned to eth0 and the one with MAC address ba:98:76:54:32:10 gets assigned to eth1.

    On Fedora, I was able to do this by specifying the MAC address in /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0
    HWADDR=01:23:45:67:89:ab
    # the rest of the configuration goes here
    

    (and similarly for ifcfg-eth1).

    Is there something equivalent syntax in /etc/network/interfaces for doing this on Ubuntu?