Renaming Network Interfaces Without Rebooting
Introduction
When running a server that requires high availability, a user may not have the luxury to perform a reboot after making a configuration change.
The following guide will explain how to rename a network interface, without the need for a reboot.
Problem
To change the names of network interfaces without rebooting the server.
Resolution
Prerequisites
Access to the root
user account or a user with escalated privileges.
Method 1 - ip link set
To temporarily change the name of an interface, use the ip link set
command.
Bring the network interface that you wish to rename down:
sudo ip link set <INTERFACE_NAME> down
Rename the interface:
sudo ip link set <INTERFACE_NAME> name <NEW_INTERFACE_NAME>
Enable the newly renamed interface:
sudo ip link set <NEW_INTERFACE_NAME> up
Please note your changes will be lost if you reboot your server.
Method 2 - udev rules by MAC Address
Check under /etc/udev/rules.d/
that you have a 70-persistent-net.rules
file. If the file is not there, create it with touch /etc/udev/rules.d/70-persistent-net.rules
Confirm the interface you wish to edit by using ip -brief address show
. You will see a similar output as in the below example:
[root@Rocky-Linux-9-5-Test-Machine ~]# ip -brief address show
lo UNKNOWN 127.0.0.1/8 ::1/128
enp8s0 UP <PUBLIC_IP>/24
Open /etc/udev/rules.d/70-persistent-net.rules
with your text editor of choice and modify the NAME
field of the interface you wish to change. A before and after example follows:
Before:
[root@Rocky-Linux-9-5-Test-Machine ~]# cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<PUBLIC_IP_HERE>", NAME="enp8s0"
After:
[root@Rocky-Linux-9-5-Test-Machine ~]# cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<PUBLIC_IP_HERE>", NAME="new-name-1"
Bring the network interfaces down with ip link set <INTERFACE_NAME> down
. In the author's case, the interface was enp8s0
:
ip link set enp8s0 down
Use the udevadm control
command to reload the udev rules and request device events from the kernel with udevadm trigger
:
udevadm control --reload-rules; udevadm trigger --subsystem-match=net --action=add
Confirm that the network interface was renamed with ip -brief address show
. The author correctly found this to be the case:
[root@Rocky-Linux-9-5-Test-Machine ~]# ip -brief address show
lo UNKNOWN 127.0.0.1/8 ::1/128
new-name-1 DOWN <PUBLIC_IP>/24
Bring the link back up using ip link set <NEW_INTERFACE_NAME> up
. Please see the following example:
ip link set new-name-1 up
Observe that the interface is up and has been renamed without requiring a reboot:
[root@Rocky-Linux-9-5-Test-Machine ~]# ip -brief address show
lo UNKNOWN 127.0.0.1/8 ::1/128
new-name-1 UP <PUBLIC_IP>/24
Even if the machine is rebooted, the changes will still be present.
Conclusions
With the methods above, you should be able to rename a network interface and avoid having to reboot.