Renaming a Network Interface Card with SystemD UDEV Rules
Assuming the following for this example:
- Physical Device Path = /sys/class/net/eth1
- Device Name = enx7cc2c6494cfb
- Serial = 007CC2C6494CFB
- MAC Address = 7c:c2:c6:49:4c:fb
First check what attributes you wish to match from your UDEV Device.
In this case we’ll use ID_USB_SERIAL_SHORT
as it’s an ASIX USB NIC.
udevadm info /sys/class/net/eth1 | grep ID_USB_SERIAL_SHORT
E: ID_USB_SERIAL_SHORT=007CC2C6494CFB
If you wish to view all attributes for the device or the device doesn’t have “ID_USB_SERIAL_SHORT” you may check what attributes are available by executing the command without GREP
udevadm info /sys/class/net/eth1
Then create your systemd link device.
nano /etc/systemd/network/10-enx7cc2c6494cfb.link
[Match]
Property=ID_USB_SERIAL_SHORT=007CC2C6494CFB
[Link]
Name=enx7cc2c6494cfb
MACAddress=7c:c2:c6:49:4c:fb
Finally restart the systemd related service for udev triggers:
systemctl restart systemd-udev-trigger
Manual Reference:
- Systemd Link File Man Page: https://manpages.debian.org/bookworm/udev/systemd.link.5.en.html