Naming Ethernet Network Interfaces for Management Control Randy Dunlap (rddunlap AT osdl.org) Member of the Technical Staff Recently, on the Linux Kernel Mailing List, it was noted that changing from a 2.4 kernel to a 2.5 kernel caused the ethernet interfaces to be enumerated and named in the opposite order. Of course, this causes problems for any applications relying on a named interface connecting to a specific network. In particular, the following two mail threads provide the motivation for me to write this article: NICs trading places http://marc.theaimsgroup.com/?l=linux-kernel&m=104888957013124&w=2 ...and... NIC renaming does not rename /proc/sys/net/ipv4 http://marc.theaimsgroup.com/?l=linux-kernel&m=104894039918678&w=2 You can have better control over your network interfaces by using some simple tools and avoid these problems altogether. The default Ethernet network interface names are eth0, eth1, eth2, etc. These cause the following configuration files to be created: /etc/sysconfig/network-scripts/ifcfg-eth# Instead of simply relying on the default "eth*" naming scheme, you can name your ethernet interfaces to indicate their actual use, using the "nameif" utility. Here are the steps to do that: 1. Select the logical interface names that you want to use. I have a dual-ported Intel gigabit ethernet adapter, but I only use one port of it. I am naming the in-use port "ethmain" and the other port "ethbackup". This setup has an additional advantage for me: it keeps the second ethernet port from being initialized and timing out, which makes startup faster. 2. Most Linux init scripts (that I know of) search for network interface config files named like so: "/etc/sysconfig/network-scripts/ifcfg-eth*". You can keep one or more of these from being used at all by renaming the one(s) that should not be used (initialized). In my case, I renamed 'ifcfg-eth1' to 'not-ifcfg-ethbackup'. For the network interface config files that you do want to use, rename them with their selected interface names. For example, in my case, I renamed 'ifcfg-eth0' to 'ifcfg-ethmain'. 3. Now edit the 'ifcfg-eth*' files to contain their correct network interface names. For example, for 'ethmain', I have: DEVICE=ethmain BOOTPROTO=dhcp NETMASK=255.255.255.0 ONBOOT=yes 4. Now create (or edit) the file '/etc/mactab'. This file tells the 'nameif' utility which Ethernet MAC addresses to associate with logical interface names. You can use '#' for comments in this file. Here is my '/etc/mactab' file: # ethmain is my primary network interface ethmain 00:07:E9:09:08:E8 # ethbackup is a second network interface; I don't init it. # ethbackup 00:07:E9:09:08:E9 5. The final step is to modify '/etc/init.d/network' to run 'nameif' during init. This can be added in any of several places in that file or in some other init script. Here is a snippet of that script that shows where I added it in '/etc/init.d/network'. # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 # RDD: add 'nameif' usage; uses /etc/mactab nameif || echo "nameif: reports error" # if the ip configuration utility isn't around we can't function. [ -x /sbin/ip ] || exit 1 Summary: With just a little file editing and the use of one small utility program ('nameif'), you can have better control over your Linux network interfaces. And if you have lots of network interfaces, keeping them named consistently is the first step to keeping them managed. Try it... it's easy. P.S.: Another utility that you can use to setup and control network interfaces is 'ip'. For more information on 'ip', see 'man 8 ip' or the file '/usr/share/doc/iproute-2.4.7/ip-cref.ps' (if it's included in your Linux distribution). ###