Wednesday, March 20, 2013

how to rename the interface in linux


Rename network interfaces
Prerequisites
§  ifrename tool which is a part of the wireless_tools package.
§  udev package, which is already installed, of course.
Generic network interfaces
Option 1: udev
Create /etc/udev/rules.d/10-network.rules file with content like following:
 SUBSYSTEM=="net", ATTR{address}=="00:1e:58:48:33:08", NAME="lan"
 SUBSYSTEM=="net", KERNEL=="tap1", NAME="vpn"
 SUBSYSTEM=="net", KERNEL=="tap5", NAME="qemu"
Note: Make sure to use the lower-case hex values in your udev rules. It doesn't like uppercase.
Note: Note that the example above avoids names such as eth0, eth1, etc... and instead uses names that are not initially assigned. Trying to rename using names like eth0, eth1, etc... may fail.
Note: If using systemd, you may find it necessary to inform your network service to hold until the network device has been renamed. This may be achieved by adding the following to the [Unit] section of your network.service file:
 Requires=systemd-udev-settle.service
 After=systemd-udev-settle.service
Option 2: ifrename
Run ifrename directly
 # ifrename -i eth0 -n lan
or create config file (/etc/iftab), for example:
lan            mac 00:0C:6E:C6:94:81
internet       mac 00:0C:6E:C6:94:82
and run
 # ifrename -c /etc/iftab
Example:
How to rename the interface in linux using ifrename 


__tmp469514561 Link encap:Ethernet  HWaddr 00:1F:29:60:B6:A5
__tmp1982053100 Link encap:Ethernet  HWaddr 00:26:55:D6:91:1B


Create a iftable file and include the new NIc with mac address and execute the ifrename command mentioned below

itab - 
eth12 mac 00:26:55:d6:91:1b
eth14 mac 00:1f:29:60:b6:a5



ifrename -i eth0 -n lan
ifrename -i __tmp469514561 -n eth14
ifrename -i __tmp1982053100 -n eth12




PPP interfaces
Add into /etc/ppp/ip-up script the following lines:
 IF=$1
 ip link set dev $IF down
 /usr/sbin/ifrename -i $IF -n <NEWNAME>
 ip link set dev <NEWNAME> up
where <NEWNAME> is the new name for the ppp interface





1 comment: