LINUX SNIPPET
Contents
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
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.
Thanks, it worked for me without stress
I am glad it did
Worked like a CHAMP! SO MUCH EASIER than other procedures I’ve read out there!
THANKS!!
You are welcome Tom. Glad it was helpful.
Works until reboot, because we have not disabled the biosdevnames in the grub file, no?
If we add HWADDR of that specific nic it is resolved. Thanks a lot!!
You are welcome Saran.
This is not working for RHEL9
Thanks for the feedback. I’ll look into it and provide a solution for RHEL 9 if its not working
The change is applied but I lose the change after rebooting the server. Any idea ?
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.
Thank you very much, it works even after reboot and server upgrade if I put HWADDR parameter line in config text.
You are welcome.
Please subscribe to our YouTube channel to get more contents like this: https://www.youtube.com/@tekneed
Thank you.
Thanks!! This was clear and worked perfectly.
You are welcome, David.
very simple than other links.
Glad it was helpful.
it worked, but after reboot it change it back to old names.
Version : CentOS v7.9.2009
It should work. Did you include the MAC address? Kindly watch the video https://www.youtube.com/watch?v=lWCFg-hI2Is