How to change network interface names permanently in Linux

Last updated on October 23, 2020 by Dan Nanni

Question: I want to change a network interface name (e.g., eth0) to something else on my Linux. What is a proper way to rename network interfaces on Linux?

In Linux, device name management is handled by udev system. When Linux kernel discovers a new device (e.g., a network interface card) added to the system, it notifies udev daemon of the device event. The udev daemon will then match various device attributes against a set of rules to identify the device, name it, and store its information in udev database.

In case of network devices, udev relies on MAC addresses to assign persistent names to the devices. The MAC address based naming rules are stored in /etc/udev/rules.d/70-persistent-net.rules.

In order to change a network device name, you can thus edit /etc/udev/rules.d/70-persistent-net.rules. If there is no such file, you can create one yourself.

In /etc/udev/rules.d/70-persistent-net.rules, you can assign an arbitrary device name to a particular MAC address. Thus, first find out the MAC address of your network interface, and then define the interface name to that MAC address in the following format.

$ sudo vi /etc/udev/rules.d/70-persistent-net.rules
# interface with MAC address "00:0c:29:43:28:11" will be assigned "eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:43:28:11", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# interface with MAC address "00:0c:29:43:28:1b" will be assigned "eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:43:28:1b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

After editing /etc/udev/rules.d/70-persistent-net.rules, reboot your machine to activate the interface name change.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean