Change systemd network interface name ensxx to eth0

Change systemd network interface name ensxx to eth0 1

Introduction

In Systemd Network on Linux server like Red Hat Enterprise Linux 7.x, CentOS 7.x, Oracle Linux server the interface device name will be different from Linux version 6. We may get random names similar to ens123 or en133. In some case, if the name needs to be renamed as eth0 or eth1 its possible. However, going backwards is not advisable and not a good practice. Anyhow, we need to adhere to our infrastructure requirements so let see how to rename interface from new name to old name.

There are two ways to accomplish it.

Method 1: Create a udev rule and rebuild the grub.
Method 2: Install bisodevname and reboot the server.

Before changing with the interface names let us verify the current interface name.

# ip a
CentOS 7 interface name
RHEL or CentOS 7 interface name before changed

Method 1: Create a udev rule and rebuild the grub.

Step 1: Mask the default interface names in Systemd network.

By default udev rule will assign a fixed name, we need to make the udev to not assign with any name. By creating a soft link from /dev/null to udev rule file we can mask it.

# ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules

mask udev of Systemd Network
mask UDEV for random named interface

Step 2: Create a Custom name for the interface using udev

Now create your own custom udev rules for your interface, As per our requirement, it needs to be eth0. But you can define any name like prod0, dev0 or test0.

The custom file which we are creating should be in order before the default udev rules file (80-net-name-slot.rules), example our file should be 70-net-name-slot.rules to load before the default one.

Make a copy of existing file from /usr/lib/udev/rules.d/ and alter the required parameters.

# cp -pv /usr/lib/udev/rules.d/80-net-name-slot.rules /etc/udev/rules.d/70-net-name-slot.rules
create udev rule for interface
create udev rule for the interface name

We are only adding with the interface name as NAME!=”eth0″. Refer below the figure for the same.

# vi /etc/udev/rules.d/70-net-name-slot.rules
change parameters n udev rule file
change parameters n udev rule file

We have completed with creating a custom udev rule, By following let’s rebuild the grub, configure the interface and reboot the server.

Step 3: Add kernel parameters and rebuild the grub.

Then edit the grub and add with kernel parameters

# ls -lthr /etc/default/grub
# vi /etc/default/grub

We need to make changes to the line starting with “GRUB_CMDLINE_LINUX=”, Refer below picture for the same.

net.ifnames=0 and biosdevname=0

net.ifname biosdevname 0
net.ifname biosdevname 0
# grub2-mkconfig -o /boot/grub2/grub.cfg
rebuild grub
rebuild grub

Step 4: Create a new interface file for eth0.

Now we need to create an interface file for eth0, made a copy of existing interface “ifcfg-ens33” to “ifcfg-eth0” and make sure to remove the UUID from the configuration, else create with a new UUID using “uuidgen“.

# cp -pv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Copy of interface file
interface configuration from old to a new interface name

Once above all steps are carried out then reboot the server and verify the interface name.

# reboot
# ip a
interface name after change
interface name after the change

Method 2: Install bisodevname and modify boot parameter.

To perform the above requirement by installing a package will work only on a server BIOS which running with SMBIOS 2.6 and higher versions.

Step 1: Install the biosdevname package

# yum install biosdevname

Once the above package installed biosdevname=0 will be available as a boot option which will rename the interfaces to eth0.

That’s it we have completed with creating a custom udev rule to rename the unpredictable interface names in systemd network on CentOS or RHEL based operating Systems.

Read More articles related to Linux Networking

Conclusion

Many production running application may have dependencies on the legacy method. We need to make infra requirement fulfil by making few changes to the server which will help the business to up and running without any interrupt. In this guide, we have seen how to make a systemd network interface name to old name format. More tricks and tips are coming on the way make sure to subscribe with us to get updated information.