How To Rename NIC In Linux (CentOS / RHEL 7 & 8)

LINUX SNIPPET

You will learn how to rename NIC in Linux without the need of editing UDEV file

How To Rename Network Interface Card (NIC) In RHEL / CentOS 7&8

1. verify the NICs on the system.

[root@HQPRD2 ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:dc:f5:94 brd ff:ff:ff:ff:ff:ff
    inet 192.168.170.216/24 brd 192.168.170.255 scope global noprefixroute dynamic ens33
       valid_lft 1539sec preferred_lft 1539sec
    inet6 fe80::5353:948b:670:3326/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
[root@HQPRD2 ~]#

2. Bring down the NIC you want to rename and verify that “state UP” has turned to “state DOWN”

[root@HQPRD2 ~]# ifdown ens33
[root@HQPRD2 ~]# ifconfig ens33 down

3. rename the NIC to the desired name. In my case, I will rename the NIC to “tekneed”

[root@HQPRD2 ~]# ip link set ens33 name tekneed

4. confirm it’s been renamed.

[root@HQPRD2 ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: tekneed: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 00:0c:29:dc:f5:94 brd ff:ff:ff:ff:ff:ff
    inet 192.168.170.216/24 brd 192.168.170.255 scope global noprefixroute dynamic ens33
       valid_lft 1539sec preferred_lft 1539sec
    inet6 fe80::5353:948b:670:3326/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
[root@HQPRD2 ~]#

5. Rename the NIC configuration file in network-scripts directory

NOTE: You may or may not need this step

[root@HQPRD2 ~]# mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-tekneed

6. Edit the NIC configuration file and replace the old device name with the new one as highlighted in yellow. Also make sure the “HWADDR” field is included

[root@HQPRD2 ~]# vi /etc/sysconfig/network-scripts/ifcfg-tekneed
how to rename a NIC in Linux

NOTE: The HWADDR parameter is the MAC address of the NIC which can been seen when you use the command, “ip a” to verify the NICs on the system.

7. Bring up the renamed NIC.

[root@HQPRD2 ~]# ifconfig tekneed up
[root@HQPRD2 ~]# ifup tekneed

8. verify the NIC is up

[root@HQPRD2 ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: tekneed: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:dc:f5:94 brd ff:ff:ff:ff:ff:ff
    inet 192.168.170.205/24 brd 192.168.170.255 scope global noprefixroute dynamic tekneed
       valid_lft 1572sec preferred_lft 1572sec
[root@HQPRD2 ~]#

9. You may reboot your system to verify it is persistent across reboot.

[root@HQPRD2 ~]# reboot

This is how to rename NIC in Linux. This process may not apply for all Linux distributions though.

Your feedback is welcomed. If you love others, you will share with others.

19 Comments

  1. In case, the change is lost after rebooting. You have to edit the file /etc/udev/rules.d/70-persistent-net.rules and check the mac address are the good one.

Leave a Reply

Your email address will not be published.


*