renaming network interface with systemd
Solution 1:
At least on Debian stretch, it seems like you need to update-initramfs -u && reboot
for *.link
files in /etc/systemd/network/
to take effect for existing interfaces.
It seems like the network interfaces get renamed very early during boot from within the initramfs, before the *.link
files in /etc/systemd/network
are available... and once the interface has been renamed once (/sys/class/net/*/name_assign_type=4
), then the the udev-builtin-net_setup_link
will no longer emit ID_NET_NAME
because should_rename
returns false
.
Solution 2:
Are you using systemd-networkd
? I think the .link
files are only relevant if you are (instead of the default NetworkManager or legacy initscripts). (I admit I haven't looked deeply into it yet, though.)
I think what you want is a .rules
file in /etc/udev/rules.d
, something like
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="mac-address", NAME="wan"
(where mac-address
is your actual hex MAC address, of course).
This file needs to be ordered before /usr/lib/udev/rules.d/80-net-setup-link.rules
, so the upstream docs suggest /etc/udev/rules.d/70-my-net-names.rules
.
Solution 3:
For some bad reasons it seems that networkmanager has priority over networkd(who could imagine that?). You can test this as follows:
-
systemctl stop NetworkManager
- unplug the network interface
-
ip addr
Result: /etc/systemd/network/*.link rules are honored
If you start NetworkManager and repeat the test /etc/systemd/network/*.link is not honored anymore. I tested this with the MACAddressPolicy=random
directive