I faced one issues in which one of my KVM virtual machine has ethernet cards like ens2 and ens7. So i thought I should rename these Network Ethernet cards and name them in order like ens0 and ens1. So in this post we would see HowTo rename Network Ethernet cards in CentOS7/RHEL7.

For this, i have CentOS7 latest as of now in Nov 2017.

SetUP

[root@host1 ~]# uname -r
3.10.0-693.5.2.el7.x86_64
[root@host1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)

So as already mentioned we have ens2 and ens7 network Ethernet Cards like mentioned below in ifconfig output.

[root@host1 ~]# ifconfig
ens2: flags=4163  mtu 1500
        inet 192.168.122.100  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::2dda:5f82:85cf:1904  prefixlen 64  scopeid 0x20
        ether 52:54:00:5f:d0:28  txqueuelen 1000  (Ethernet)
        RX packets 22  bytes 4590 (4.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 33  bytes 5131 (5.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens7: flags=4163  mtu 1500
        inet 192.168.122.101  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::cb5f:a41d:8546:ea0  prefixlen 64  scopeid 0x20
        ether 52:54:00:5f:d0:26  txqueuelen 1000  (Ethernet)
        RX packets 22  bytes 4590 (4.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 33  bytes 5131 (5.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

We need make it ens0 and ens1. So let’s start renaming above Network Ethernet cards like mentioned below.

Here we use ip command for this purpose.

[root@host1 ~]# ip link set down ens2
[root@host1 ~]# ip link set ens2 name ens0
[root@host1 ~]# ip link set down ens7
[root@host1 ~]# ip link set ens7 name ens1

[root@host1 ~]# ip link set up ens0
[  286.378333] 8139cp 0000:00:02.0 ens0: link up, 100Mbps, full-duplex, lpa 0x05E1
[root@host1 ~]# ip link set up ens1
[  288.494226] 8139cp 0000:00:07.0 ens1: link up, 100Mbps, full-duplex, lpa 0x05E1

Now we could observe that Network Ethernet card name has been change and named as we want and mentioned above.

[root@host1 ~]# ifconfig
ens0: flags=4163  mtu 1500
        inet 192.168.122.100  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::2dda:5f82:85cf:1904  prefixlen 64  scopeid 0x20
        ether 52:54:00:5f:d0:28  txqueuelen 1000  (Ethernet)
        RX packets 22  bytes 4590 (4.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 33  bytes 5131 (5.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens1: flags=4163  mtu 1500
        inet 192.168.122.101  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::cb5f:a41d:8546:ea0  prefixlen 64  scopeid 0x20
        ether 52:54:00:5f:d0:26  txqueuelen 1000  (Ethernet)
        RX packets 22  bytes 4590 (4.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 33  bytes 5131 (5.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

But still in next reboot it will change to earlier one, for this we have to make them persistent through editing it system file named /usr/lib/udev/rules.d/60-net.rules

[root@host1 ~]# cat /usr/lib/udev/rules.d/60-net.rules
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="52:54:00:5f:d0:28", NAME="ens0"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="52:54:00:5f:d0:26", NAME="ens1"

Now we permanent rename Network Ethernet cards name to required one.