1. Overview

In Linux, network interfaces are essential components that allow communication between the operating system and the network. These interfaces are assigned default names like eth0, eth1, ens33, and so on based on various factors, such as hardware configuration and device driver order.

However, there might be situations where we need to rename a network interface to provide it with a more meaningful or descriptive name, resolve naming conflicts, or align with our system’s organizational conventions. In this tutorial, we’ll explore different methods to rename a network interface in Linux.

2. Identify the Network Interface Using ip and ifconfig

Before renaming a network interface, it’s essential to identify the current name of the interface. To do this, we can use the ip command or the ifconfig command to list all network interfaces along with their current names.

Firstly, let’s use the ip command to list the network interfaces:

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0

This command output shows the network interfaces’ information. It displays details about two interfaces: lo (loopback) and eth0 (Ethernet 0). The information includes their status, MTU (Maximum Transmission Unit), queueing discipline, state, mode, group, MAC address, and other relevant settings.

Secondly, let’s use ifconfig to list the network interfaces:

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 17  bytes 1462 (1.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet  netmask
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Similar to the ip command, ifconfig also displays the network interface information, including network interface name, MAC address, MTU information, and so on.

3. Temporary Renaming Network Interface Using ip

The ip command allows us to temporarily rename a network interface for the current session without making permanent changes to the system configuration. This can be particularly useful for testing or troubleshooting purposes.

Let’s use the ip command to temporarily rename the network interface eth0 to neweth0. Firstly, we need to disable the network interface, which we’ll be renaming:

$ sudo ip link set dev eth0 down

After disabling eth0, we can rename eth0 to neweth0:

$ sudo ip link set dev eth0 name neweth0

Finally, let’s enable renamed network interface:

$ sudo ip link set dev neweth0 up

After executing the above commands, the network interface will be renamed to neweth0 until the next system reboot.

4. Permanent Renaming Network Interface Using udev Rules

For Ubuntu and Debian-based systems, the preferred method to make interface name changes persistent across reboots is by using udev rules.

Let’s open the udev rules file related to network interfaces using a text editor with administrative privileges. The file is named 70-persistent-net.rules and is found in the /etc/udev/rules.d/ directory. If there is no such file, we can create one ourselves:

$ sudo nano /etc/udev/rules.d/70-persistent-net.rules

After opening the 70-persistent-net.rules file, locate the line corresponding to the network interface we want to rename, and modify the NAME parameter with the new desired name:

# Modify ATTR{address} with MAC of the network interface and NAME paramter with the new desired name.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="02:42:ac:11:00:02", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="neweth0" 

Let’s save the udev rules file after making the necessary changes.

We need to reboot our Linux system to apply the permanent network interface renaming. Upon restart, we can confirm the network interface has been successfully renamed by using the ip or ifconfig command, as explained above in section 2.

5. Conclusion

In this article, we explored methods for renaming network interfaces either temporarily or permanently.

The temporary renaming method using the ip command allows for session-specific changes, which is useful for testing. Additionally, the use of udev rules, particularly for Ubuntu and Debian systems, to achieve permanent renaming across reboots. By following these straightforward methods, we can streamline network control and maintain a well-organized and functional Linux environment.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.