Change the CentOS 7 interface name after new installed

Solution

Step 1: Edit the /etc/default/grub file

In this case, I will using vim editor,

[root@localhost ~]# vi /etc/default/grub

Step 2: After the file open in vim editor, press I to insert the input. The bottom of the file will show you in INSERT mode

Step 3: Add the options below in GRUB_CMDLINE_LINUX variable.

net.ifnames=0 biosdevname=0

Your configuration file will be like this. In red box the variable that we added

Step 4: After the variable added, press ESC and write wq!  To write and quit from vim editor. The bottom of the editor, will show as below and press ENTER

Step 5: Test the configuration with the grub command below

[root@localhost ~]# grub2-mkconfig

The output will show like this and if the done like the redbox below show mean the configuration are correct

Step 6: If there are no errors apply the change:

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

The output will show like this

Step 7: Next, copy your existing network configuration file to the new interface name. For example, if your interface name was originally ens33

#change the directory to network-scripts directory which is contain all the network interfaces configuration for CentOS 7
[root@localhost ~]# cd /etc/sysconfig/network-scripts
#copy the file from name existing interface name to eth0[root@localhost ~]# cp ifcfg-ens33 ifcfg-eth0

Step 8: Next, open the ifcfg-eth0 file with vim editor and change the variable below:

From

NAME=”ens33”DEVICE=”ens33”

To

NAME=”eth0”DEVICE=”eth0”

You can refer step 2-4 how to use vim to edit the files

The sample of edited file here

Save the file after finish edit the files

Step 9: Remove the old interface config by using command below

[root@localhost ~]# rm -f /etc/sysconfig/network-scripts/ifcfg-ens33

Step 10: Disable NetworkManager by using command below

[root@localhost ~]# systemctl disable NetworkManager

Step 11: Reboot the server

[root@localhost ~]# reboot

Step 12: Restart the network by using command below

[root@localhost ~]# service network restart

When the service restart success the following output will show

You can verify the interface by showing the ip address by using the command below

[root@localhost ~]# ip address

Troubleshooting

If the interface in DOWN state, does not have any ip address / using DHCP to retrieve the IP address, using the following command

[root@localhost ~]# ifup eth0

The output will show like this

After done, try show the ip address one more and your CentOS will get the IP address