Rename Network Interfaces
Something kind of interesting I stumbled on was moving some virtual machines around to a different ESXi host that doesn't have to same storage backend. So they were copied over manually and then imported within VMware vCenter. The machines were running Red Hat and although they were connecting to the same network the operating system was using a different interface name like ens33
instead of ens192
.
While not a huge problem it was just that configuration was already present on the ens192
interface with network manager and instead of just adding the IP address to the new network interface I wanted to keep the same interface name and settings.
So this type of thing can happen anytime in VMware and probably other hypervisors as changing the NIC type, removing it, and adding it back, all can change the name of the interface. So keeping it consistent helps us because we could have:
- Software or applications might be looking at the interface name to bind to. Even system services like IPTABLEs, firewalld, etc.
- We could have scripts that also look for a specific interface name.
- And we want consistent names across our devices. (At least I do 😊)
How To:
This is a pretty easy process we first want to create a folder if one does not exist already:
sudo mkdir -p /etc/systemd/network
We then want to use vi
or some other text editor to create the .link
file:
sudo vi /etc/systemd/network/10-ens192.link
ip link show
will output the hardware address.
[Match]
MACAddress=00:0a:29:ab:cd:ef
[Link]
Name=ens192
sudo dracut -f
command which is used to generate the initramfs at boot. When we created the .link file it may not be recognized at boot since this is early in the operating system boot up process. Running this command helps to make that the initramfs is loaded with these new settings.
After that command completes running a reboot like sudo reboot
will reboot the system and for this example use the ens192
interface which in network manager already has the existing network profile like the IP address, subnet mask, gateway, etc. So when we reboot and the system is back online our we should be able to connect via IP and see that our ens192
is back.