Change interface names in Linux
From Internetworkpro
[edit] Introduction
I found that I needed a reliable way to maintain interface names on my USB Ethernet based lab, so I wanted a way to obtain interface name persistence under Linux, so I can reload/undock/stop dynamips without having to worry about ethernet names changing in the order they start up. With 14 usb ethernet NICs, this is a very real possibility.
[edit] Using udev
Udev is the new 'hotplug' (or was always the old one, depends on how you look at it. On CentOS, we can create a file that runs before /etc/udev/rules.d/60-net.rules (The ifup/down scripts).
I created the file /etc/udev/rules.d/55-jps.rules and specified the mac addresses of my usb ethernet devices.
Somehow, the first line of 60-net.rules [shown below]
ACTION=="add", SUBSYSTEM=="net", IMPORT{program}="/lib/udev/rename_device"
SUBSYSTEM=="net", RUN+="/etc/sysconfig/network-scripts/net.hotplug"
did not kick in and rename the new SW* device to eth*.
/etc/udev/rules.d/55-jps.rules
KERNEL=="eth*", SYSFS{address}=="00:40:05:8e:e0:a3", NAME="SW1Fa01"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8e:dd:90", NAME="SW1Fa03"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8e:d9:7c", NAME="SW1Fa05"
KERNEL=="eth*", SYSFS{address}=="00:50:ba:82:9c:4c", NAME="SW2Fa02"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8f:40:0c", NAME="SW2Fa04"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8f:3f:d7", NAME="SW2Fa06"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8f:36:20", NAME="SW2Fa024"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8e:df:1d", NAME="SW3Fa03"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8e:e3:fc", NAME="SW3Fa05"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8f:34:19", NAME="SW3Fa024"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8e:e0:73", NAME="SW4Fa04"
KERNEL=="eth*", SYSFS{address}=="00:40:05:8f:34:8b", NAME="SW6Fa06"
[edit] using ifrename
This method is not recommended, since the distributions 'network scripts' will not run in time for this to complete. Regardless, it is still an option.
Create the file /etc/iftab and specify switch names and mac addresses:
SW1_Fa0-1 mac 00:40:05:8E:E0:A3 SW1_Fa0-3 mac 00:40:05:8E:DD:90 SW1_Fa0-5 mac 00:40:05:8E:D9:7C SW2_Fa0-2 mac 00:50:BA:82:9C:4C SW2_Fa0-4 mac 00:40:05:8F:40:0C SW2_Fa0-6 mac 00:40:05:8F:3F:D7 SW2_Fa0-24 mac 00:40:05:8F:36:20 SW3_Fa0-3 mac 00:40:05:8E:DF:1D SW3_Fa0-5 mac 00:40:05:8E:E3:FC SW3_Fa0-24 mac 00:40:05:8F:34:19 SW4_Fa0-4 mac 00:40:05:8E:E0:73 SW4_Fa0-6 mac 00:40:05:8F:34:8B
And run the binary "ifrename".
ifconfig -a | grep SW
SW1_Fa01 Link encap:Ethernet HWaddr 00:40:05:8E:E0:A3 SW1_Fa03 Link encap:Ethernet HWaddr 00:40:05:8E:DD:90 SW1_Fa05 Link encap:Ethernet HWaddr 00:40:05:8E:D9:7C SW2_Fa02 Link encap:Ethernet HWaddr 00:50:BA:82:9C:4C SW2_Fa04 Link encap:Ethernet HWaddr 00:40:05:8F:40:0C SW2_Fa06 Link encap:Ethernet HWaddr 00:40:05:8F:3F:D7 SW2_Fa024 Link encap:Ethernet HWaddr 00:40:05:8F:36:20 SW3_Fa0 Link encap:Ethernet HWaddr 00:40:05:8E:DF:1D SW3_Fa05 Link encap:Ethernet HWaddr 00:40:05:8E:E3:FC SW3_Fa024 Link encap:Ethernet HWaddr 00:40:05:8F:34:19 SW4_Fa04 Link encap:Ethernet HWaddr 00:40:05:8E:E0:73 SW6_Fa06 Link encap:Ethernet HWaddr 00:40:05:8F:34:8B

