Bits and bytes

Changing device names of NIC adapters

Ubuntu Server (and others)

If you play a lot with servers or networked PCs with multiple NICs and change and switch network cards often, you sooner or later end up with two computers having network cards named in a different order by the operating system (eg. the NIC in the first slot is eth0 on one computer while being eth1 on the other). But usually you want to have all computers in a group configured the same way, thus avoiding confusion which cable (and subnet) goes to which adapter.

To make things right is quite simple. Let’s say we want the adapter eth0 become eth1 and vice versa. We go to /etc/udev/rules.d and search for the proper network rule file:

tomo@tomo:~$ ls /etc/udev/rules.d
70-persistent-cd.rules  70-persistent-net.rules  README

In this case, it’s apparently 70-persistent-net.rules (never mind the numbers at the beginning). That’s where the configuration happens. We should now open the file:

tomo@tomo:~$ sudo vim /etc/udev/rules.d/70-persistent-net.rules

And find the lines describing the two network adapters. In this case:

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:11:5b:99:fc:3e”, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

and

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:10:5c:8a:ff:20″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″

As we see, the adapter with MAC address 00:11:5b:99:fc:3e is named eth0 and the one with MAC 00:10:5c:8a:ff:20 is eth1. We switch those names to get:

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:11:5b:99:fc:3e”, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″

and

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:10:5c:8a:ff:20″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

Then save the file:

[CTRL] + [C] :w [ENTER]

Reboot the system and that’s it.