Persistently rename a Linux network interface without Udev / Reboot

Thanks to netplan (default in ubuntu 18.04) this is now particularly easy. You can set the interface name based on macaddress or driver:

Edit an existing .yaml configuration file in /etc/netplan/ or create a new one:

sudo nano /etc/netplan/config.yaml

Here is an example with MAC address matching. Names are set with 'set-name' and matched by the MAC address of the interface:

network:
  ethernets:
    wan:
      match:
        macaddress: 00:ab:cd:ef:12:34
      addresses: 
        - 10.5.1.2/16
      dhcp4: true
      optional: true
      set-name: wan0
    lan:
      match:
        macaddress: 00:ab:cd:ef:12:45
      addresses: 
        - 10.6.1.1/16
      optional: true
      set-name: eth0
  version: 2

Save the .yaml file and apply the configuration with:

sudo netplan apply

A reboot may be required to apply the name change.


Knowing the ip command is nice, but there are persistent ways to configure using existing scripts, and yes, udev.

One thing you can dois map a NIC of a specific MAC address to a name. Append something like this to /etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="xx:xx:xx:xx:xx:xx", NAME="eth0"
  • Changing Network Interfaces name Ubuntu 16.04
  • Linux Rename Eth0 Network Interface Card Name [ Udev ]

As of 2021 there is a move away from udev rules (although they still work fine) and a move towards doing it in systemd, to keep all the network configuration in one place.

To set a persistent network device, create /etc/systemd/network/10-eth0.link with the following contents. The filename must start with a number and end with .link but the rest is not important and up to you. You need one file for each network interface you want to rename.

[Match]
# This is the MAC address of the card to change.  You can also
# match against other properties like PCI/USB slot.
MACAddress=00:11:22:33:44:55

[Link]
# This is the name to assign.  It must not conflict with any existing
# device, so be careful if you use a name like eth0 which can fail
# unexpectedly if you plug in another device that ends up on eth0 first.
Name=lan0

# You can also change the MAC address at the same time if you like.
# Make sure you follow the MAC address numbering rules or you can run
# into problems, e.g. if you assign a broadcast MAC address by mistake.
MACAddress=02:00:00:00:00:10

At the time of writing systemd will not re-apply .link files once the system is up and running (even if you restart systemd-networkd), so you'll need to reboot in order to confirm it can apply the change successfully.