devops2025-04-25·11 min·108/348

Renaming Network Interfaces on Linux: From eth0 to Whatever You Need

Methods for renaming Linux network interfaces, including udev rules, systemd-networkd, and NetworkManager approaches.

Introduction

Linux no longer guarantees that your first network interface will be called eth0. Predictable Network Interface Names assign names like enp0s3 or ens192 based on hardware location. While this is useful in servers with many NICs, it can be inconvenient for scripts, configuration files, and muscle memory. This post covers the various methods for renaming network interfaces on Linux and their tradeoffs.

Environment

The examples use Ubuntu 22.04 LTS with systemd-networkd as the network backend, and a system with two NICs currently named enp0s3 and enp0s8.

ip link show
# 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
# 2: enp0s3:  mtu 1500 qdisc fq_codel state UP
# 3: enp0s8:  mtu 1500 qdisc fq_codel state UP

Problem

You want to rename enp0s3 to wan and enp0s8 to lan for clarity. But you cannot just edit a config file and restart networking, because the names are assigned by the kernel at boot time through udev.

Analysis

Network interface names in Linux are determined at boot in this order:

  1. Kernel default: The kernel assigns eth0, eth1, etc.
  2. udev rules: The 80-net-setup-link.rules or custom rules rename interfaces
  3. NetworkManager or systemd-networkd: Can apply renames via configuration

The naming scheme enp0s3 means: en (ethernet), p0 (PCI bus 0), s3 (slot 3). This is deterministic across reboots but not human-friendly.

There are three main approaches to renaming:

  • udev rules: Most flexible, works with any network backend
  • systemd-networkd: Clean integration if you are already using it
  • NetworkManager: For desktop or NetworkManager-managed servers

Solution

Method 1: udev rules (most reliable)

Create a custom udev rule:

sudo nano /etc/udev/rules.d/70-custom-naming.rules

Add the following:

# Match by MAC address (most reliable)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:11:22:33:44:55", NAME="wan"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:11:22:33:44:56", NAME="lan"

Find your MAC addresses first:

cat /sys/class/net/enp0s3/address
# 00:11:22:33:44:55

cat /sys/class/net/enp0s8/address
# 00:11:22:33:44:56

Apply the rules:

sudo udevadm control --reload-rules
sudo udevadm trigger --subsystem-match=net

Method 2: systemd-networkd.link

If using systemd-networkd, create link files:

sudo nano /etc/systemd/network/10-wan.link
[Match]
MACAddress=00:11:22:33:44:55

[Link]
Name=wan
sudo nano /etc/systemd/network/20-lan.link
[Match]
MACAddress=00:11:22:33:44:56

[Link]
Name=lan

Restart networking:

sudo systemctl restart systemd-networkd

Method 3: NetworkManager

sudo nmcli device status
# enp0s3  connected  to wan-connection
# enp0s8  connected  to lan-connection

sudo nmcli connection modify wan-connection interface-name wan
sudo nmcli connection modify lan-connection interface-name lan

sudo systemctl restart NetworkManager

Method 4: ip link (temporary, for testing)

sudo ip link set enp0s3 down
sudo ip link set enp0s3 name wan
sudo ip link set wan up

sudo ip link set enp0s8 down
sudo ip link set enp0s8 name lan
sudo ip link set lan up

This is temporary and lost on reboot.

Verify the rename:

ip link show
# 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
# 2: wan:  mtu 1500 qdisc fq_codel state UP
# 3: lan:  mtu 1500 qdisc fq_codel state UP

Update network configuration:

After renaming, update your network configs:

# /etc/systemd/network/10-wan.network
[Match]
Name=wan

[Network]
DHCP=yes
sudo systemctl restart systemd-networkd

Lessons Learned

Always use MAC addresses to identify interfaces, not bus位置. MAC-based matching is deterministic and does not change when you move NICs between slots. Test with ip link set ... name ... first to ensure the new name does not conflict. And keep a backup of your original network configuration before making changes. A typo in a udev rule can lock you out of a remote server.


This blog does not accept any external sponsorships, affiliate marketing, or ad revenue.