Gentoo: Rename logical interface names in Linux using udev and nameif
Recently I was tasked with setting up a router using a Linux server. This device has 4 NIC's (net, local, db/web, other) and the owner would like them organized as they are plugged in on the back of the box. The NIC's are:Intel Corporation 82547EI Gigabit Ethernet Controller (built in)
D-Link System Inc RTL8139 Ethernet (rev 10) (PCI)
Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01) (PCI)
D-Link System Inc RTL8139 Ethernet (rev 10) (PCI)
The first Intel NIC is built into the motherboard and should be eth0. The first D-Link, eth1, the second Intel eth2 and the last D-Link, eth3. With both modules (e1000 and 8139too) built as modules in the kernel, the folks at #gentoo on FreeNode suggested using udev and nameif to accomplish the renaming.
To do this, I setup a /etc/mactab such as:
eth0 MY:MA:CA:DD:RR:S0
eth1 MY:MA:CA:DD:RR:S1
eth2 MY:MA:CA:DD:RR:S2
eth3 MY:MA:CA:DD:RR:S3Custom udev rules must be setup in order to rename the current ethX devices, otherwise nameif will not work as the names are already taken by the devices the kernel loads. To accomplish this, I created a new file called /etc/udev/rules.d/10-udev.rules, with the following content:
KERNEL="eth*", SYSFS{address}="my:ma:ca:dd:rr:s0", NAME="e0"
KERNEL="eth*", SYSFS{address}="my:ma:ca:dd:rr:s1", NAME="e1"
KERNEL="eth*", SYSFS{address}="my:ma:ca:dd:rr:s2", NAME="e2"
KERNEL="eth*", SYSFS{address}="my:ma:ca:dd:rr:s3", NAME="e3"The MAC address must be lower-case (!!) when writing these rules. Since I'm lazy, I ran the following command to retrieve the lower-case verison of your MAC address:
# udevinfo -a -p /sys/class/net/eth0Or
# udevinfo -a -p /sys/class/net/eth0 | grep address | sed 's/"/ /g' | awk '{print $2}'Finally, the nameif process must be run before starting up your adaptors (net.lo, net.ethX, etc.). To accomplish this, I added /sbin/nameif to /etc/conf.d/local.start, and ran:
# rc-update add local bootRebooting the system should now rename your NIC's to e0, e1, eX, and then back to eth0-X based on your MAC addresses setup in /etc/mactab.
Resources:
http://www.science.uva.nl/research/air/wiki/LogicalInterfaceNames
http://forums.gentoo.org
#gentoo on irc.freenode.net



