Renaming network interfaces using udev


Ever wanted to rename the network interface to something more meaningful ? Well, this is a very simple guide on how to do it using udev.


What is udev

udev is a generic kernel device manager. It runs as a daemon on a Linux system and listens to events the kernel sends out. If a new device is initialized or a device is removed from the system. The udev system provides a set of rules that match against exported values of the event and properties of the discovered device. A matching rule will possibly name and create a device node and run configured programs to set-up and configure the device.


Procedure for changing network interface names


Determine the MAC address of the interface

We need to figure out what is the MAC address of the network interface that we want to rename. The easiest way is to type

ifconfig ifname

Where ifname is the current name of the interface (e.g. eth2, ath1, …)

This produces an output such as the following :

ifname    Link encap:Ethernet  HWaddr 00:04:76:2f:e6:74
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16

The MAC address is the string after HWaddr. In this example, its '00:04:76:2f:e6:74'.


Add a rule file under /etc/udev/rules.d

We need to create a file that tells the Kernel how to name the interface rather than let it follow the default naming rules. Lets call this file 10-local.rules and place it in /etc/udev/rules.d/

Lets assume, you want to rename the interface whose MAC address is “00:04:76:2f:e6:74” to TO-ROUTER. The contents of the 10-local.rules file must be as follows.

SUBSYSTEM=="net", ATTR{type}=="1", ACTION=="add", ATTR{address}=="00:04:76:2f:e6:74",  NAME="TO-ROUTER"

The rule above, tells the Kernel that, if a networking device is plugged and this device's address attribute is “00:04:76:2f:e6:74”, then give the name “TO-ROUTER” to this device .

Udev allows you to do more things such as launching programs when a certain device is plugged. For more information check the links below.


External links

Writing udev rules



Labels: , Wireless Internet Security Coding Network Monitoring

Comment

Enter your comment (wiki syntax is allowed):
FQOPV

Wireless Internet Security Performance RADIUS server Wireless Internet Security Performance RADIUS server