How to Configure Network Interface Link Settings and Renaming in Ubuntu Using systemd.link

Modern Linux operating systems rely on predictable network interface naming schemas (such as enp3s0 or wlp2s0) to prevent hardware interface ordering confusion across system reboots. However, in enterprise server clusters, multi-port network router appliances, container virtualization nodes, and specialized testbeds, system administrators frequently need to override automated hardware names, enforce custom naming conventions (e.g., wan0, lan1, storage0), or adjust physical link properties before higher-level network daemons like Netplan, NetworkManager, or systemd-networkd configure IP addressing.

In Ubuntu, the native mechanism for managing link-layer interface policies is systemd.link. Processed early in the boot sequence by the systemd-udevd daemon, declarative .link configuration files match network adapters based on hardware attributes—such as permanent MAC addresses, PCI topology paths, or driver classifications—and apply link-layer settings including persistent renaming, MTU sizing, MAC address policies, and hardware offload toggles.

Understanding How systemd.link Operates in the Boot Cycle

When the Linux kernel discovers a network interface card (NIC), it assigns a default kernel name (such as eth0) and generates a udev event. The systemd-udevd daemon intercepts this event and scans configuration directories for matching .link files.

If a matching .link file is identified, udev renames the interface and configures link-layer attributes *prior* to exposing the device to user-space network managers. This separation guarantees that whether your system utilizes Netplan with systemd-networkd or NetworkManager backends, the physical link properties are already established cleanly.

Configuration File Locations and Precedence Order

Link configuration files follow a standardized filename naming schema (*.link) and are scanned across three directories in order of administrative precedence:

  1. /etc/systemd/network/*.link — Local administrator link policies (highest priority).
  2. /run/systemd/network/*.link — Ephemeral runtime link configurations created by daemons.
  3. /usr/lib/systemd/network/*.link — Operating system vendor and distribution default link policies (lowest priority).

Files are processed in lexicographical order based on their numerical prefix (e.g., 10-wan.link executes before 99-default.link). To override Ubuntu’s default predictable naming scheme for a specific adapter, choose a prefix lower than 99.

Deconstructing the systemd.link Syntax

A .link file consists of two primary sections:

  • [Match]: Defines hardware criteria used to uniquely identify the physical or virtual adapter. Multiple conditions act as a logical AND operation.
  • [Link]: Declares the link policies and physical attributes to apply to matched devices.

Common matching attributes include:

  • MACAddress= — The factory MAC address of the adapter (e.g., 52:54:00:12:34:56).
  • Path= — The hardware bus path (e.g., pci-0000:03:00.0).
  • Driver= — The Linux kernel driver module (e.g., e1000e, r8169, mlx5_core).
  • Type= — The hardware interface classification (e.g., ether, wlan).

Assigning a Persistent Custom Interface Name

To demonstrate a standard deployment, consider an enterprise gateway server equipped with two physical Ethernet adapters. The administrator wants to identify the primary uplink as wan0 and enforce jumbo frame MTU support.

First, identify the adapter’s permanent hardware MAC address and PCI path using ip link:

ip -d link show enp3s0

Create a dedicated link configuration file in /etc/systemd/network/:

sudo nano /etc/systemd/network/10-wan.link

Add the following configuration block:

[Match]
MACAddress=00:1a:4b:16:89:3c
Type=ether

[Link]
Description=Primary High-Speed WAN Uplink
Name=wan0
MTUBytes=9000
WakeOnLan=magic

Save and close the file. The directive Name=wan0 instructs udev to rename the adapter to wan0, while MTUBytes=9000 enforces an initial Maximum Transmission Unit of 9,000 bytes for jumbo frame support.

Configuring Dynamic MAC Address Policies

In addition to static hardware renaming, systemd.link provides centralized control over MAC address generation. For virtual machines or edge testing rigs that require address privacy or automated spoofing, use MACAddressPolicy=:

[Match]
OriginalName=en*

[Link]
MACAddressPolicy=random

Supported policies include:

  • persistent: Uses a stable, deterministic MAC address calculated from the machine ID and interface name across reboots.
  • random: Generates a completely randomized, ephemeral MAC address every time the link is initialized.
  • none: Retains the physical EEPROM factory MAC address.

Testing Link Policies and Verifying with udevadm

Before rebooting, verify that udev correctly parses your .link file and matches the target hardware adapter using the udevadm test-builtin command:

udevadm test-builtin net_setup_link /sys/class/net/enp3s0

The diagnostic output displays the evaluated link file and confirms the intended policies:

Parsed configuration file /etc/systemd/network/10-wan.link
Matches device: yes
ID_NET_NAME=wan0
net_setup_link: Description='Primary High-Speed WAN Uplink'
net_setup_link: Name='wan0'
net_setup_link: MTU=9000

To apply the link renaming without a full system reboot, trigger a udev device event:

sudo udevadm trigger --action=add /sys/class/net/enp3s0

Run ip link to verify that the network adapter is now named wan0 with the specified MTU:

ip link show wan0

Updating Initramfs for Early Boot Network Links

If your Ubuntu system mounts its root filesystem over iSCSI or NFS, or if network interfaces are required during the initramfs boot phase, update your initial RAM disk to bundle the new .link configuration:

sudo update-initramfs -u

By leveraging systemd.link, Ubuntu administrators gain declarative, reliable control over network interface identities, jumbo frame initialization, and link-layer policies across hardware infrastructure.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.