Renaming a Linux network interface immediately
Summary
In November 2019 Manuel Schmitt notes, as a reminder to self, how to rename a Linux network interface immediately. Instead of running udevadm control and udevadm trigger after changing udev rules, the command ip link set OLDNAME name NEWNAME is enough. Up to and including Linux 6.1, however, this only works while the interface is down.
What the kernel allows
Up to Linux 6.1, the kernel function dev_change_name refuses to rename an active interface with the error EBUSY unless the driver sets the special flag IFF_LIVE_RENAME_OK. Renaming therefore usually requires ip link set dev OLDNAME down first and up again afterwards.
Since Linux 6.2, active interfaces may be renamed as well. The kernel notes this in the log with the suffix while UP.
Alternative names instead of renaming
There are also alternative interface names: ip link property add dev DEVICE altname NAME attaches a second name without changing the first. Kernel support for this arrived with Linux 5.5.
A change made with ip link only lasts until the next reboot. The name only becomes permanent through udev rules, systemd link files or the distribution's network configuration.
Ideas
- ip link changes the interface name directly without triggering udev again.
- An immediate change saves udevadm control and udevadm trigger in this case.
- Older kernels require the interface to be down for this.
- Alternative names add a name without replacing it.
- The command separates a runtime fix from the permanent naming rule.
Insights
- Short operations notes prevent rare commands from being researched again every time.
- A successful runtime change is not yet a persistent configuration.
- Whether a command works on a system often depends on the kernel version.
Facts
- The documented command is ip link set OLDNAME name NEWNAME.
- Up to Linux 6.1, renaming an active interface returns EBUSY.
- Since Linux 6.2, renaming active interfaces is allowed.
- The kernel has supported alternative interface names since Linux 5.5.
References
Remarks
- The post does not mention that on kernels before 6.2 the interface must be taken down first; over SSH on that very interface, this cuts the connection.
Recommendations
- Only rename the interface carrying your SSH session when you have console access.
- Check dependent firewall, bridge and monitoring rules before renaming.
- Also store the desired name in the persistent network configuration.
Read the original article on Hostblogger
Found a mistake or have something to add? Get in touch.
Links to the original source and the Web Archive open in a new tab.