Who among us has not experienced the joy of rebooting a multi-homed Linux server, and found that our network interfaces have come up in a different order, and been assigned different names by the kernel? This is especially amusing when doing a kernel upgrade on multiple servers, and all of them do the random-re-assignment dance. Sure, everyone knows we have all the time in the world for useless tasks like re-configuring network cards, but still, there must be a better way.

Of course there is a better way, else I would not be writing this article. The ifrename utility, by the esteemed Jean Tourrilhes of the Wireless Tools for Linux project, assigns permanent, arbitrary names to all types of network interfaces: ISA, PCI, USB, CardBus, and PCMCIA. This means you can easily give your devices sensible names like "lan", "wan", and "dmz", or use their driver names, instead of being stuck with the uninformative eth0/eth1 etc. naming scheme. ifrename is part of the wireless-tools package.

Users of Red Hat and Red Hat-spawned systems like Fedora, White Box, CentOS and so forth, already have the ability to staple their network interfaces immovably in place, which we shall get to presently. Debian is the bigger problem child when it comes to managing multiple network interfaces, so we'll start there.

ifrename on Debian
ifrename is available as a separate package for Debian. It installs ready to go to work, with a boot script and configuration file already in place. The configuration file is /etc/iftab. A simple configuration looks like this:

Then you must use these names in /etc/network/interfaces, and in every script that uses interface names.

I chose the names "lan" and "wan" for my two PCI Fast Ethernet interfaces, and mapped them to their MAC addresses. MAC addresses are unique for every device, so they make good identifiers for this. How do you find the MAC number? With either the ifconfig -a command, or the ip command, like this:

The ip command is part of the iproute package. While the iproute maintainers seem to want the net-tools suite to go away, which includes ifconfig, netstat, nameif, route, mii-tool, and arp, it's OK to have both, as each one has its uses. (See Resources.)

What about hotpluggable network cards, like USB or laptop cards? As long as your hotplug system is working, no problem. Same song, same dance. Check out Jean Tourrilhes' Hotplug.txt page for help with tweaking hotplug cards on Debian.

You may use other static criteria, like driver name, IRQ, base address, or other arcane goodies as listed in man iftab.

Reboot, and when the system comes back up ifconfig -a or ip link show will show your new device names.

Boot Script
Debian comes with an init script for ifrename, which can be used on any system. If you want to use ifrename on a different system, you must have a boot script. Other systems don't always include an init script for ifrename. Here is the entire script. Naturally you may tweak it to suit, and mind your filepaths:

Take a look at the $IFRENAME -d -p line. The -d flag is Debian-specific; it loads only the drivers for interfaces named in /etc/network/interfaces. -p tells ifrename to probe for the interface modules, and load any that are not already loaded. This is a nice feature that doesn't hurt anything if it's not needed, and it makes sure that the correct drivers get loaded.

The Debian init script also includes the -t flag, which I have deleted. This allows interface name-swapping. For example, when one interface is down, a second interface can take its name. There may be times when you want this to happen; me, I want them to stay put.

The Red Hat Way
Red Hat handles this naming business in a different way. Suppose you want "lan" and "wan" instead of "eth0" and "eth1." Simply use the DEVICE and HWADDR directives in the /etc/sysconfig/networking/devices/ifcfg-* files:

DEVICE=lan
HWADDR=11:22:33:44:55:66

You can even change the configuration file names to help you keep track, like /etc/sysconfig/networking/devices/ifcfg-lan.
Again, remember to use your new device names in all scripts that include them, like your iptables scripts.

Hardware Tips
When you're building a multi-homed server, the most sure-fire way to determine which card is which is to connect them one at a time to a second PC and ping them. Then use a nice marking pen or sticky label. Using network cards with different drivers also gives you a way to tell them apart.

Resources

Wireless LAN resources for Linux. Thank you Hewlett-Packard for supporting Mr. Tourrilhes and this site. Now if you will get vendors of wireless adapters to support Linux, and to release wireless G adapters that support hostAP mode so us hardy network admins can make our own homegrown Linux access points, life will be pleasant indeed.