| by Arround The Web | No comments

How to Change Network Interface Naming Policy on Ubuntu/Debian/RHEL/CentOS/Fedora/Rocky Linux

Predictable network interface names are:

  1. Stable across reboots
  2. Fixed/consistent even if the hardware is added or removed
  3. Fixed/consistent even if defective/damaged hardware is replaced
  4. Stateless and does not require any explicit configuration files

For system security and ease of use, predictable network interface names are very important. So, major Linux distributions use “systemd” and “udev” to assign predictable names to the network interfaces of your computer.

Currently, there are a few network interface naming policies that you can use on Ubuntu, Debian, RHEL, CentOS, Fedora, Rocky Linux, and other popular Debian/Ubuntu-based or RPM-based Linux distributions. In this article, we will discuss the available network interface naming policies of Linux and show you how to switch to the one that you want.

Topic of Contents:

  1. Available Network Interface Naming Policies
  2. The Network Interface Naming Policy Currently Being Used
  3. Changing the Network Interface Naming Policy
  4. Checking If the New Network Interface Naming Policy Is Being Used
  5. Configuring the Custom Names for Network Interfaces
  6. Conclusion

Available Network Interface Naming Policies

Currently, the available network interface naming policies are:

  1. kernel – In this policy, the kernel does not rename the predictable network devices, i.e. lo (the loopback interface)
  2. database – In this policy, the udev hardware database which is “hwdb” is used to assign the network device names.
  3. onboard – In this policy, the index number provided by the BIOS/firmware of your computer is used to name the onboard network devices, i.e. eno1, eno2.
  4. slot – In this policy, the PCIE hot-plug slot index number provided by the BIOS/firmware of your computer is used to name the network devices, i.e. ens1, ens2.
  5. path – In this policy, the physical location of the hardware is used to name the network devices, i.e. enp1s0, enp1s2, enp1s0f0, enp1s0f1.
  6. mac – In this policy, the mac address of the network device is appended to the network interface name, i.e. enx000c294cd7e8.

The Network Interface Naming Policy Currently Being Used

The default network interface naming policy configuration file on most of the popular Linux distributions is in the “/usr/lib/systemd/network/99-default.link” path.

You can open the default network interface naming policy configuration file “/usr/lib/systemd/network/99-default.link” with the nano text editor as follows:

$ sudo nano /usr/lib/systemd/network/99-default.link

The order of the network interface naming policies to be used is listed in the “NamePolicy” section[1].

Here, “keep” has the highest priority. What “keep” does is if a name is already assigned to a network interface, systemd/udev will keep using the same name again and again.

Then, it will try to set the kernel names. If the kernel naming policy fails, use the database, onboard, slot, and path, respectively.

You can also set an alternative name for the network interfaces using the “AlternativeNamesPolicy” option in the same way[2]. A naming policy that is not used for actual network interface naming is used as an alternative naming policy depending on the order set in the “AlternativeNamesPolicy”.

A screenshot of a computer Description automatically generated

As you can see, the slot network interface naming policy, by default, is used to name the actual network interfaces and the path network interface naming policy is used to give an alternative name to the network interface on Ubuntu 22.04 LTS. A different naming policy and alternative naming policy may be used by default on other Linux distributions.

$ ip a

A screenshot of a computer Description automatically generated

Changing the Network Interface Naming Policy

To change the network interface naming policy, open the “/usr/lib/systemd/network/99-default.link” configuration file with the nano text editor as follows:

$ sudo nano /usr/lib/systemd/network/99-default.link

Type in your desired network interface naming policy in the “NamePolicy” section and the alternative network interface naming policy in the “AlternativeNamePolicy” section.

Once you’re done, press <Ctrl> + X followed by “Y” and <Enter> to save the “99-default.link” file.

A screenshot of a computer Description automatically generated

For the changes to take effect, reboot your computer as follows:

$ sudo reboot

Checking If the New Network Interface Naming Policy Is Being Used

Once your computer boots, run the “ip” command to verify whether the network interface names changed accordingly. As you can see, the mac network interface naming policy is used to set the real names for the network interface and the path network interface naming policy is used to set the alternative names for the network interfaces.

$ ip a

A screenshot of a computer Description automatically generated

In this example, we used the path naming policy for the real name and the mac naming policy for the alternative name of the network interfaces, respectively.

A screenshot of a computer program Description automatically generated

Configuring the Custom Names for Network Interfaces

Besides using the predefined network interface naming policies, you can also set the custom names for the network interfaces of your computer. To learn how to set the custom names for your network interfaces, read this article.

Conclusion

In this article, we discussed the available network interface naming policies of modern Linux distributions. We also showed you how to use the different network interface naming policies on Ubuntu/Debian, RHEL/Rocky Linux/CentOS/Fedora, and other Ubuntu/Debian-based or RPM-based modern Linux distributions.

Share Button

Source: linuxhint.com

Leave a Reply