15

I want to rename on Fedora 22 a network interface managed by systemd-networkd (version 219) from the system-assigned name enp2s0 into wan. For that I created the following file /etc/systemd/network/80-wan.link:

[Match]
MACAddress=mac-address
[Link]
Name=wan

However, that have no effect on the system. After rebooting the name is still enp2s0. I see with udevadm that udev picked up the file for configuration but ignored the supplied name:

~> udevadm info /sys/class/net/enp2s0 
P: /devices/pci0000:00/0000:00:1c.1/0000:02:00.0/net/enp2s0
E: DEVPATH=/devices/pci0000:00/0000:00:1c.1/0000:02:00.0/net/enp2s0
E: ID_BUS=pci
E: ID_MM_CANDIDATE=1
E: ID_MODEL_FROM_DATABASE=RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
E: ID_MODEL_ID=0x8168
E: ID_NET_DRIVER=r8169
E: ID_NET_LINK_FILE=/etc/systemd/network/80-wan.link
E: ID_NET_NAME_MAC=enxMacAddress
E: ID_NET_NAME_PATH=enp2s0
E: ID_OUI_FROM_DATABASE=Shuttle Inc.
E: ID_PATH=pci-0000:02:00.0
E: ID_PATH_TAG=pci-0000_02_00_0
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Realtek Semiconductor Co., Ltd.
E: ID_VENDOR_ID=0x10ec
E: IFINDEX=2
E: INTERFACE=enp2s0
E: SUBSYSTEM=net
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/enp2s0
E: TAGS=:systemd:
E: USEC_INITIALIZED=24183

Also there is no mentioning of the new name wan in any logs even after activating udev debugging output. What I am doing wrong?

4 Answers 4

13

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.

2
  • It's the same situation on Ubuntu 18.04 (and probably later too). Thanks for the fix.
    – user381521
    Commented Jan 18, 2020 at 6:15
  • I tried running 'dracut -f' in Fedora to rebuild the initramfs and rebooted, but this didn't solve the problem for me.
    – amcnabb
    Commented Dec 5, 2020 at 20:55
7

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.

2
  • 1
    Yes, I use systemd-networkd. Its docs gives an example of renaming and I do not see why my case does not work. Commented May 17, 2015 at 6:46
  • 1
    In those same docs, you can also see that you can override the udev config by having a link file before debian's or your own distro's 99-default.link. YMMV here, filename-wise. This doesn't appear to be the issue of the OP but for anyone else landing here, make sure your link filename starts with a number lower than 9. Something like 10-eth.link Commented Nov 8, 2020 at 21:57
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

0

Add net.ifnames=0 to kernel boot params for RHEL.

For RHEL7

vim /etc/default/grub 

Edit LINE with GRUB_CMDLINE_LINUX, add net.ifnames=0 to it. Update grub config and reboot

grub2-mkconfig -o /boot/grub2/grub.cfg 
reboot

Check /proc/cmdline that it has added param.

cat /proc/cmdline 

Now systemd config files in /etc/systemd/network/ dir will work, check NIC names.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .