Sunday, 29 April 2018

How to rename a network interface on Centos/RHEL 7



In Centos / RHEL 7, a new NIC naming scheme is the predictable naming rule is adopted by default like ens192, enp3s0 and eth0 so on. To disable the predictable naming rule we can pass "net.ifnames=0" kernel parameter during boot.


This article describes how to revert the naming convention as eth0, eth1 so on by following the below steps:

Edit the default grub configuration file /etc/default/grub and append the parameters net.ifnames=0 biosdevname=0 next to GRUB_CMDLINE_LINUX

[root@linuxcnf ~]# vi /etc/default/grub
….
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 biosdevname=0  rhgb quiet"

Rebuild the Grub configuration: Run the following command to rebuild GRUB configuration with updated kernel parameters as below:

[root@linuxcnf ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.21.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.21.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.17.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.17.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.5.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.5.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-0eec2e1713a64ff191af6ad0d005b83b
Found initrd image: /boot/initramfs-0-rescue-0eec2e1713a64ff191af6ad0d005b83b.img
done

[root@linuxcnf ~]#


Edit the interface configuration: Here we are assuming that the interface name is enp3s0 and the new interface name should be eth0. Run the following command and change the following parameters values for interface name:

[root@linuxcnf ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp3s0
......
NAME=eth0
DEVICE=eth0
......

Rename the configuration file name:

[root@linuxcnf ~]# mv /etc/sysconfig/network-scripts/ifcfg-enp3s0 /etc/sysconfig/network-scripts/ifcfg-eth0

Disable Network Manager:

Follow the article to Disable Network Manager in Centos 7.

Finally, reboot the machine:

[root@linuxcnf ~]# reboot

Verify the changes. Hope everything should be OK.

No comments:

Post a Comment