How to rename/change network interface name on RedHat Core OS?

2.5k views Asked by At

I have installed Red Hat core os network interface name and my network interface name comes as ens1f1,ens1f2..etc. I want to change/rename it to eth1, eth2. How can I achieve this?

sh-4.4# ifconfig 
ens1f0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 40:a6:b7:43:c8:70  txqueuelen 1000  (Ethernet)
        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

ens1f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 40:a6:b7:43:c8:71  txqueuelen 1000  (Ethernet)
        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

ens1f2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 40:a6:b7:43:c8:72  txqueuelen 1000  (Ethernet)
        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

Also I don't see ens1f1 interface file at /etc/sysconfig/network-scripts/ifcfg-ens1f1 location

1

There are 1 answers

2
sseLtaH On

In order to rename your NIC, you will need to bring it down.

$ sudo ifdown ens1f0

Once down, you may now rename the card

$ sudo ip link set ens1f0 name eth0

Rename the config file

$ sudo mv /etc/sysconfig/network-scripts/ifcfg-ens1f0 /etc/sysconfig/network-scripts/ifcfg-eth0

Confirm the NIC is available

$ ip a

Edit the config file

$ hwaddr=$(ip a | sed -n '/eth0/{n;s/[^0-9]*\(.*\)/\1/p}')
$ sudo sed -i '\#NAME\|DEVICE#{s/ens1f0/eth0/}' /etc/sysconfig/network-scripts/ifcfg-eth0
$ sudo sed -i "s/\(HWADDR=\).*/\1$hwaddr/" /etc/sysconfig/network-scripts/ifcfg-eth0

Bring the NIC back up

$ sudo ifup eth0