Keeping consistent network interface names with ifrename

Posted by Steve on Fri 23 Feb 2007 at 11:54

If you have multiple ethernet devices upon a system it is useful to make sure they are always given the device names that you expect. This can be useful when you're managing upgrades - or for situations where you accidentally setup a system with eth1 plugged into a switch rather than eth0.

There are several different ways of managing the naming of devices if you're using a dynamic /dev system such as udev or hotplug - but the simplest system which works for most cases is provided by the ifrename package.

Once installed this package will let you rename devices based upon something that shouldn't change their MAC addresses. (Finding MAC addresses of an ethernet device is simple.)

First of all you must install the package:

root@mine:~# apt-get install ifrename
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  libiw28
The following NEW packages will be installed
  ifrename libiw28
..

Once installed you may create a new file /etc/iftab to define the mapping between your ethernet device's MAC addresses and the interface names.

The contents of this file should look similar to this:

eth0 mac 00:17:31:56:BC:2D
eth1 mac 00:16:3E:2F:0E:9C

With this configuration file in place when you reboot next you'll discover that regardless of your kernel upgrading, that the network card with MAC address "00:17:31:56:BC:2D" will be setup as eth0, and that the card with MAC address "00:16:3E:2F:0E:9C" will be known as eth1.

(The actual renaming will happen automatically via the addition of /etc/init.d/ifrename.)

 

 


Posted by arapaho (81.185.xx.xx) on Fri 23 Feb 2007 at 13:31
The same behavior with udev can be obtanined thanks to etc/udev/rules.d/z25_persistent-net.rules:

SUBSYSTEM=="net", DRIVERS=="?*", SYSFS{address}=="00:13:72:89:79:26", NAME="eth0"
SUBSYSTEM=="net", DRIVERS=="?*", SYSFS{address}=="00:13:72:89:79:27", NAME="eth1"

You can edit that file by hand or use write_net_rules sh-script to fill it.

[ Parent | Reply to this comment ]

Posted by Anonymous (141.28.xx.xx) on Wed 4 Apr 2007 at 17:46
Hi,

it's DRIVER, not DRIVERS

[ Parent | Reply to this comment ]

Posted by Anonymous (84.159.xx.xx) on Thu 5 Apr 2007 at 19:20
These lines work for me:

KERNEL=="eth*", SUBSYSTEM=="net", DRIVER=="e1000*", NAME="eth1"
KERNEL=="eth*", SUBSYSTEM=="net", DRIVER=="3c59x*", NAME="eth0"

[ Parent | Reply to this comment ]

Posted by Anonymous (217.86.xx.xx) on Tue 13 Nov 2007 at 12:56
Please review man udev before saying "it's DRIVER, not DRIVERS". Both are correct.
If a driver is already assigned both work. If no driver is assigned, only DRIVERS works.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.149.xx.xx) on Fri 23 Feb 2007 at 13:53
I use ifrename on my firewall, but give the interfaces more memorable names such as eth-wan, eth-lan and eth-dmz.

[ Parent | Reply to this comment ]

Posted by dkg (216.254.xx.xx) on Fri 23 Feb 2007 at 16:43
[ View dkg's Scratchpad | View Weblogs ]
I used ifrename for a while, but found its interaction with ifupdown not quite right in some of the edge cases. If the machine i'm working on has udev, i prefer to use the udev ruleset myself.

This has also been discussed on this site in some users' weblogs.

In etch, at least the files /etc/udev/persistent-net.rules and /etc/udev/persistent-net-generator.rules have a nice automagic interaction to keep nice stable names for your NICs.

[ Parent | Reply to this comment ]

Posted by benji (82.225.xx.xx) on Fri 23 Feb 2007 at 21:10
Udev is quite usefull when you want to keep interface name consistent.

However, I used to copy systems between hard drives, so that I don't have to install multiple instances of the same system. However, udev named my interfaces eth0/eth1 on first machine, eth2/eth3 on second machine (first copy), eth4/eth5 on third, etc.

So I edited /etc/udev/persistent-net.rules to delete references to eth0/eth1 and the second machine was named correctly ;)

[ Parent | Reply to this comment ]

Posted by dkg (216.254.xx.xx) on Fri 23 Feb 2007 at 21:41
[ View dkg's Scratchpad | View Weblogs ]
On machines with a lot of interfaces, i like to give them semantic names to make them easier to remember. So on my laptop, my onboard wired ethernet is "wired", my onboard wireless NIC is "wireless", my 3com PCMCIA 10/100 adapter is "3com", and the firewire network interface is "fw".

easier to remember all around, plus when i plug in an unusual new interface, it can grab the generic "eth0" without my having to think about it.

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Fri 23 Feb 2007 at 23:59
[ View Steve's Scratchpad | View Weblogs ]

I should have mentioned this as a good use for the package.

I tend not to bother with renaming devices except upon Xen hosts which have lots of vifN.0. interfaces.

Steve

[ Parent | Reply to this comment ]

Posted by malcolm (124.168.xx.xx) on Sat 24 Feb 2007 at 01:07
Ensuring network interfaces remain named consistently

http://www.debian-administration.org/articles/463

[ Parent | Reply to this comment ]

Posted by Anonymous (59.176.xx.xx) on Sat 24 Feb 2007 at 04:18
Now that has got to be a sign that a site has truly arrived - when you start getting dupes like slashdot.

PJ

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Sat 24 Feb 2007 at 15:48
[ View Steve's Scratchpad | View Weblogs ]

Too true!

I just had to use the tool recently, and remembered it was one of the packages which has been sat on my articles to write pile for a while. So I figured I'd make a quick overview a couple of nights ago. It didn't cross my mind to search first!

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (84.43.xx.xx) on Sat 3 Mar 2007 at 13:22
Be carefull when using ifrename with vlan in Debian Etch.
Vlan script "/etc/network/if-pre-up.d/vlan" expect raw interfaces name in "/etc/network/interfaces" to be "ethX" in some cases.
You must use "vlan-raw-device <interface name>" in "/etc/network/interfaces" to use raw-network interface with name different from "ethX". In this case resulting vlan interface name always is "vlanXXXX".

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 672 votes ~ 10 comments )