Wednesday, December 21, 2005

» Forcing network interface names

Since udev had its way into SUSE Linux, network interface names are chosen dynamically by udev and not statically any more, as it was with older versions. In some situations, you'd want to force the network interface name (e.g. eth0, eth1) though, and it's not much of an easy task of finding how to do that. /usr/share/doc/packages/sysconfig/README.Persistent_Interface_Names provides a rather detailed explanation of how it works, but unfortunately doesn't give any examples. So to those who aren't udev wizards (i.e. almost everyone on this planet), here's an example of what to write in /etc/udev/rules.d/30-net_persistent_names.rules:
SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:04:23:a7:bf:f4", IMPORT="/sbin/rename_netiface %k eth0"
SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:0b:db:83:84:b0", IMPORT="/sbin/rename_netiface %k eth2"
First, you need to find out the hardware (a.k.a. MAC) address of the network interface you want to name explicitely. You might want to use /sbin/ip address list to help you with that, e.g.:
 1: lo: mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
 2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:04:23:a7:bf:f4 brd ff:ff:ff:ff:ff:ff
    inet 161.90.174.152/23 brd 161.90.175.255 scope global eth0
 3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0b:db:83:84:b0 brd ff:ff:ff:ff:ff:ff
Once you have identified the correct network interface name (which is still the one you'd like to rename), take note of it's hardware address (in the example above, it's 00:04:23:a7:bf:f4 for eth0). Then, go ahead and add a line as above (SUBSYSTEM...) in /etc/udev/rules.d/30-net_persistent_names.rules, obviously putting the proper hardware address behind SYSFS{address}==. The value of IMPORT is what's executed by udev and while the first parameter to /sbin/rename_netiface is a placeholder (%k), the second one is the desired network interface name. Actually, the example above will rename the network interface eth1 into eth2 (for the NIC with the hardware address 00:0b:db:83:84:b0).

4 Comments:

Anonymous Anonymous said...

What's wrong with nameif ?

helios@neurotic:~$ apt-cache search nameif
net-tools - The NET-3 networking toolkit
helios@neurotic:~$ whatis nameif
nameif (8) - name network interfaces based on MAC addresses

07:56  
Anonymous Anonymous said...

I was trying to implement this on my openSUSE 10.2 box, and it turns out the /sbin/rename_netiface file has been moved to /usr/sbin/ifrename. Therefore the IMPORT="/sbin/rename_netiface %k" section should read IMPORT="/usr/sbin/ifrename %k"

05:05  
Blogger Panos said...

I found this very helpful:

http://www.reactivated.net/writing_udev_rules.html

02:18  
Blogger Jason M. said...

This was very helpful in setting up a linux box to flash prism firmware. Apparently prism2_srec expects the interface to be WLAN0 (maybe due to entries for WLAN1,2, etc. missing in /proc). Anyway, with this I was able to flash all the prism cards I have. Thanks

05:47  

Post a Comment

<< Home