The cart is empty

Managing network interfaces in Linux is an essential part of system configuration, especially when working with servers or specific networking setups. One common task is renaming a network interface from its default name, such as "eth0", to a custom identifier that better suits your needs. This article will guide you through the process of renaming a network interface in Linux using system tools.

Reasons for Renaming a Network Interface

Renaming network interfaces can be useful for several reasons:

  • Easier management: If you have multiple network interfaces, renaming each based on its function (e.g., "internal", "external") makes it easier to manage.
  • Compatibility with scripts: Some scripts or networking configurations might require specific interface names to function properly.
  • Simplified multi-interface management: For servers or complex configurations, using logical names for interfaces can simplify administration.

Steps to Rename a Network Interface

There are several ways to rename a network interface in Linux. In this guide, we will focus on using udev rules and system tools available in modern distributions like Debian and Ubuntu.

1. Identifying the Current Network Interface Name

First, you need to identify the current name of the network interface you wish to rename. You can do this by running the following command:

ip link show

The output will look something like this:

2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:1a:2b:3c:4d:5e brd ff:ff:ff:ff:ff:ff

In this case, the interface name is "enp3s0".

2. Creating a udev Rule to Rename the Network Interface

To rename the network interface in modern Linux distributions, you will use udev rules. These rules allow you to change the interface name during system startup. First, create a new rule file in the /etc/udev/rules.d/ directory.

Open a terminal and create a new file, such as 10-network.rules:

sudo nano /etc/udev/rules.d/10-network.rules

In this file, add a rule like this:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:1a:2b:3c:4d:5e", NAME="new_name"

In this rule, replace:

  • ATTR{address} with the MAC address of your device (you can get it from the output of ip link show or ifconfig).
  • NAME with the new name you want to assign to the network interface (e.g., "internal_lan").

3. Restarting udev Service and Network Interface

After editing the rule, restart the udev service to apply the new rule:

sudo systemctl restart udev

For the changes to take effect, you can also restart the network interface:

sudo ip link set enp3s0 down
sudo ip link set enp3s0 up

Alternatively, you can reboot the system:

sudo reboot

After the reboot, the network interface should have the new name specified in the rule.

4. Verifying the Change

Once the system has restarted, check if the network interface has been renamed successfully:

ip link show

The new network interface name should now be displayed in the output.

Alternative Method: Using systemd.link Files

If your Linux distribution uses systemd, you can also rename network interfaces using systemd link files. These files allow you to configure various properties of network interfaces, including the name.

Steps:

  1. Create a new file in the /etc/systemd/network/ directory. For example:
    sudo nano /etc/systemd/network/10-rename.link
    ​
  2. Add the following configuration to the file:
    [Match]
    MACAddress=00:1a:2b:3c:4d:5e
    
    [Link]
    Name=new_name
    ​
  3. Restart the systemd service:
    sudo systemctl restart systemd-udevd
    ​

 

After this, the network interface will be renamed to "new_name".

 

Renaming a network interface in Linux is a relatively straightforward process that can be done using udev rules or systemd.link files. Both methods offer flexibility and allow you to rename interfaces based on various criteria such as the MAC address. By renaming interfaces, you can ensure better organization and more efficient management of your network settings in your system.