CentOS 8 / RHEL 8 uses a consistent and predictable device name for network interfaces. This feature helps us in locating and differentiating network interfaces.
Due to this predictable naming, your machine’s network interface name might have got changed to ensXX or enpXsX from eth0.
Here, we will see how to change network interface name to eth0 on CentOS 8 / RHEL 8.
Current Network Interface Name
Contents
If you see the output of ip a command below, my CentOS 8 / RHEL 8 system is having a network adapter called enp0s3.
ip a
Output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:cb:58:58 brd ff:ff:ff:ff:ff:ff inet 192.168.0.10/24 brd 192.168.0.255 scope global noprefixroute enp0s3 valid_lft forever preferred_lft forever inet6 2406:7400:bf:e32d:db66:4e78:fa1f:d781/64 scope global dynamic noprefixroute valid_lft 299sec preferred_lft 119sec inet6 fe80::34ec:d538:4198:41ec/64 scope link noprefixroute valid_lft forever preferred_lft forever
You can confirm that the Ethernet device got renamed during the system boot by using the dmesg command.
dmesg | grep -i eth
Output:
[ 3.365646] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:cb:58:58
[ 3.365651] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
[ 3.368598] e1000 0000:00:03.0 enp0s3: renamed from eth0
Disable Consistent Interface Device Naming
To regain the ethX back, edit the grub file.
vi /etc/default/grub
Look for GRUB_CMDLINE_LINUX and add the following net.ifnames=0.
FROM:
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet"
TO:
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 rhgb quiet"
Generate a new grub file using the grub2-mkconfig command.
grub2-mkconfig -o /boot/grub2/grub.cfg
Update Network Interface Configurations
Rename the network interface’s configuration file from ifcfg-enp0s3 to ifcfg-eth0.
mv /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-eth0
Edit the file and update the name of the network device based on the DHCP/ Static IP address for eth0.
READ: Install and configure DHCP server on CentOS 8 / RHEL 8
READ: Install and configure DHCP server on CentOS 7 / RHEL 7
DHCP
If your machine receives an IP address from DHCP server, then:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Update below lines in interface files so that the network card can get an IP address from the DHCP server.
FROM:
TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="dhcp" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="enp0s3" DEVICE="enp0s3" ONBOOT="yes" IPV6_PRIVACY="no"
TO:
TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="dhcp" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" NAME="eth0" DEVICE="eth0" ONBOOT="yes"
Static
If your infrastructure does not have a DHCP server, then you may need to configure a static IP address for the network interface.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
FROM:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="enp0s3"
DEVICE="enp0s3"
ONBOOT="yes"
IPADDR="192.168.0.10"
PREFIX="24"
GATEWAY="192.168.0.1"
DNS1="192.168.0.1"
DNS2="8.8.8.8"
IPV6_PRIVACY="no"
TO:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
IPADDR="192.168.0.10"
PREFIX="24"
GATEWAY="192.168.0.1"
DNS1="192.168.0.1"
DNS2="8.8.8.8"
IPV6_PRIVACY="no"
Reboot your system.
reboot
Verify Network Interface Name
After the system reboot, go and check whether the interface name is changed to eth0.
ip a
Output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:cb:58:58 brd ff:ff:ff:ff:ff:ff inet 192.168.0.10/24 brd 192.168.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 2406:7400:bf:e32d:8b39:a313:a396:8dd9/64 scope global dynamic noprefixroute valid_lft 296sec preferred_lft 116sec inet6 fe80::f17b:a620:a0c1:d594/64 scope link noprefixroute valid_lft forever preferred_lft forever
Conclusion
That’s All. Please share your thoughts in the comments section.