In this post we will see How can we rename Interface name in CentOS/Redhat Machines.

[root@dev-centos6 ~]# cat /etc/redhat-release 
CentOS release 6.10 (Final)

[root@dev-centos6 ~]# uname -r
2.6.32-754.2.1.el6.x86_64

Now in this Virtual machine, that we cloned from a another machine have one interface eth1, we like to rename it to eth0. So Let’s see how could we do soooo.

1. Check and edit interface configuration file

In CentOS/RedHat machines, interface configuration files are located in /etc/sysconfig/network-scripts, like below.

[root@dev-centos6 network-scripts]# ls ifcfg-eth0 
ifcfg-eth0

[root@dev-centos6 network-scripts]# grep DEVICE ifcfg-eth0
DEVICE="eth0"

For rename it another name, we just need to check file name and DEVICE mentioned in inteface file.

If we need to work on other parameters for interface. We should need to double check this file for every detail in this file regarding interface, file name, Device name, Mac address, required IP address etc. Any wrong detail mentioned in file would reflect on interface.

2. Check and Edit udev interface rules

There is file udev rules file /etc/udev/rules.d/70-persistent-net.rules in CentOS/RedHat Machines
This udev net rules are used to identify interfaces during start of udev and create automatically through sh script /lib/udev/write_net_rules. This contain information regarding interfaces, we need to check edit as per requirment…

[root@dev-centos6 rules.d]# egrep -v "^#|^$" 70-persistent-net.rules 
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:5B:55:A8", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:5b:55:a8", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

As per above output we have two entries for same interfaces. But we need to eth0 not eth1, So we will delete lines contain NAME=eth1.

Always run udevadm trigger command after editing this file.

3. change interface through IP command

Now we still have same eth1 interface, that we need eth0. For same we need to use IP command like below.

befreo run this command,from where we name reflect ..

[root@dev-centos6 ~]# lspci | grep -i net
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device


[root@dev-centos6 ~]# cd /sys/devices/pci0000\:00/0000\:00\:03.0/virtio0/net/
[root@dev-centos6 net]# ll
total 0
drwxr-xr-x 5 root root 0 Sep  1 10:48 eth1

See we have only one interface device connected on PCI slot mentioned above and has same reflected on system path that has directory eth1

[root@dev-centos6 net]# pwd
/sys/devices/pci0000:00/0000:00:03.0/virtio0/net

[root@dev-centos6 net]# ls
eth1
[root@dev-centos6 net]# ip link set eth1 name eth0
[root@dev-centos6 net]# ls
eth0
[root@dev-centos6 net]# ifup eth0

Determining IP information for eth0... done.
[root@dev-centos6 net]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 52:54:00:5B:55:A8  
          inet addr:192.168.123.107  Bcast:192.168.123.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fe5b:55a8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21693 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14933 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:74703676 (71.2 MiB)  TX bytes:1010818 (987.1 KiB)

Now we have rename interface name from eth1 to eth0