How to Rename Network Interfaces to eth0 on CentOS
In this article, we will learn about the Linux interface naming. It is written for RHEL-based Linux distributions like AlmaLinux, CentOS and Rocky Linux. You will learn how the network interface on Linux named eth(X), ens(X), eno(X), etc.
Firstly, we will learn about the naming concept of a network interface on the Linux system, including the classic naming scheme, biosdevname, and system udev policy.
1. Traditional Naming Convention
The Traditional Naming Convention is the default traditional interface naming scheme that provided by Linux kernel driver. As we know, the Traditional Naming Convention is such as eth(n) for Ethernet device, wlan(n) for wireless LAN device, and usb(n) for the usbnet.
In the traditional naming convention, all network hardware will be handled as the same by the kernel driver. It’s good enough to tell us about the type of connection, but not much for the nature hardware you’re used to.
2. Biosdevname
The Biosdevname is a project that started by Dell to provide consistent naming of network devices. The Biosdevname is a udev utility helper that provided a consistent naming mechanism for network devices based on the physical location of the hardware as suggested by the system BIOS.
Below is the default policy of naming scheme provided by biosdevname:
- For the onboard network devices, will get named as “em<port>[_<virtual instance>]”
- For add-ons NICs devices, will get named as “p<slot>p<port>[_<virtual instance>]”
More details:
- em = onboard net devices
- <slot> = the respective PCI slot
- <port> = Port number of NICs ( if have multi-port NICs)
- <virtual instance> = the SRIOV and/or NPAR instance index
- The ‘p‘ on add-on NIC is stand as pci slot and port respectly
3. Systemd Udev Rules
Nowadays, some popular Linux distros such as Ubuntu, CentOS, and Debian are using the Systemd as a system and service manager. And since version 197, systemd has been added to the native naming policies and scheme for network interfaces that similar to Biosdevname.
Below is 5 policies of network interface naming for Systemd based system:
- For onboard network devices, it will be named such as ‘eno1’, ‘eno2’, etc.
- For incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers, named as ‘ens1’. This will be applied if the first policy is failed. Mostly used by the virtual machine such as VMWare and KVM.
- Names incorporating physical location of the connector of the hardware (example: enp2s0), are applied if applicable, else falling directly back to scheme 5 in all other cases.
- Names incorporating interface’s MAC address (example: enx78e7d1ea46da), is not used by default but is available if the user chooses.
- The traditional unpredictable kernel naming scheme is used if all other methods fail (example: eth0).
Now we’ve learned about the Linux interface naming convention.
Next, we will show you how to change the network interfaces name to the traditional ‘et0’, eth1, etc. And there’re two ways to do it, change the network interface names through the ‘biosdevname’ and through the ‘systemd udev rules’.
1. Change Interface Name to eth0 by Disabling Biosdevname
As we know at the top, the biosdevname is an udev utility created by Dell for naming network interfaces as suggested by the system BIOS. And by default, the biosdevname package is installed on the Linux system.
To disable the biosdevname on the Linux system, you will need to disable it on the boot level by editing the grub configuration on your system.
Before going any further, let’s check current interfaces on the system using the following command.
ifconfig -a
ip addr
And below is the result.
As a result’ we’ve two network interfaces ‘ens3’ and ‘ens8’.
Next, we will rename both interfaces to ‘eth0’ and ‘eth1’ on our CentOS 8 system by editing the grub configuration and network configuration for each interface.
– Setup Grub2
Go to the ‘/etc/sysconfig/’ directory and edit the ‘grub’ configuration using vim editor.
cd /etc/sysconfig/
vim grub
On the ‘GRUB_CMDLINE_LINUX’ configuration, add the following configuration for disabling the biosdevname and the net.ifnames kernel parameter.
net.ifnames=0 biosdevname=0
Save and close.
After that, generate a new grub configuration using the ‘grub2-mkconfig’ command as below.
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
And you will get the result as below.
– Edit Network Script
Next, we need to rename both network interfaces on the configuration located at the ‘/etc/sysconfig/network-scripts/’ directory.
Go to the ‘/etc/sysconfig/network-scripts/’.
cd /etc/sysconfig/network-scripts/
Rename both interface name to ‘ifcfg-ethX’.
mv ifcfg-enp0s3 ifcfg-eth0
mv ifcfg-enp0s8 ifcfg-eth1
After that, change both interfaces to ‘ethX’ on both files using the sed command below.
sed -i -e 's/enp0s3/eth0/g' ifcfg-eth0
sed -i -e 's/enp0s8/eth1/g' ifcfg-eth1
Now restart the CentOS 8 system.
sudo reboot
– Testing
Once you’ve logged in again, check available network interfaces using the following command.
ifconfig
ip addr
And you will be shown the result as below.
Both network interfaces on the CentOS 8 system have been changed and now are using the traditional naming convention. The network interfaces changed by disabling the ‘biosdevname’ during system boot.
– Optionally
If you want to check details about the changes in the system boot, you can run the following command.
dmesg | grep -i eth
You will see the default interface name has been change to traditional name ‘ethX’, changed through the custom udev rules.
2. Change Interface Name to eth0 using the Udev Rules
Another way to change the network interface name to traditional naming such as eth0 etc is by creating the custom udev rules. And by using the custom udev rules, the network interfaces will be changed after the system.
– Create Custom Udev Rules
Now go to the ‘/etc/udev/rules.d/’ directory and create the custom rule named ’70-persistent-net.rules’ using vim editor.
cd /etc/udev/rules.d/
vim 70-persistent-net.rules
Change the mac address and the default interface ‘ens3’ and ‘ens8’ with your own and paste into it.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:6c:a8:e6", ATTR{type}=="1", KERNEL=="ens3", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:97:cf:33", ATTR{type}=="1", KERNEL=="ens8", NAME="eth1"
Save and close.
– Edit Network Script
Next, go to the ‘/etc/sysconfig/networ-scripts’ directory.
cd /etc/sysconfig/network-scripts/
Rename both interface name to ‘ifcfg-ethX’.
mv ifcfg-enp0s3 ifcfg-eth0
mv ifcfg-enp0s8 ifcfg-eth1
After that, change both interfaces to ‘ethX’ on both files using the sed command below.
sed -i -e 's/enp0s3/eth0/g' ifcfg-eth0
sed -i -e 's/enp0s8/eth1/g' ifcfg-eth1
Now reboot the CentOS 8 server.
sudo reboot
– Testing
Once you’ve logged in again, check all available network interfaces using the following commands.
ifconfig
ip addr
And you will get the new interface ‘ethX’ that has been assigned.
– Optionally
If you want to check details about the changes in the system boot, you can run the following command.
dmesg | grep -i eth
You will see the ‘ensX’ name is changed to the traditional name ‘ethX’, changed through the custom udev rules.
Reference
Đăng ký liền tay Nhận Ngay Bài Mới
Subscribe ngay
Cám ơn bạn đã đăng ký !
Lỗi đăng ký !
Add Comment