DevSnippets

Home » Linux » Network Interface name change while updating 22.04

Network Interface name change while updating 22.04

Linux Network Interface name change while updating 22.04 1 views

Code

Step 1: Create a udev rule

Create a persistent name rule (via udev)
Create /etc/udev/rules.d/10-persistent-net.rules (you can pick any filename ending in .rules):

sudo nano /etc/udev/rules.d/10-persistent-net.rules


Add a rule for each interface using its MAC address:

# Change em1 to eth0
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="3d:ea:7f:54:bc:f0", NAME="eth0"

# Change em2 to eth1
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="4g:ea:7f:54:bc:f1", NAME="eth1"

# Change p1p1 to eth2
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="2h:ea:7f:4c:9b:8e", NAME="eth2"

# Change p1p2 to eth3
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="6c:ea:7f:4c:9b:8f", NAME="eth3"


Make sure the MAC addresses match the ones from ip a.

Step 2: Update Netplan

If you rename interfaces, update your /etc/netplan/01-network-config.yaml:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 1.215.37.46/29
      gateway4: 1.215.37.41
      nameservers:
        addresses: [192.168.1.6, 192.168.1.7]
      routes:
        - to: 1.1.3.106/32
          via: 1.215.37.41
        - to: 1.99.1.138/32
          via: 1.215.37.41

    eth1:
      addresses:
        - 1.215.37.54/29
      routes:
        - to: 1.1.28.36/32
          via: 1.215.37.49

    eth2:
      addresses:
        - 1.215.37.61/29
        - 1.215.37.62/29   # for alias
      nameservers:
        addresses: [192.168.1.6, 192.168.1.7]
      routes:
        - to: 1.201.101.0/24
          via: 1.215.37.57
        - to: 1.201.97.10/32
          via: 1.215.37.57

    eth3:
      addresses:
        - 1.10.0.98/24
      gateway4: 1.10.0.97

Step 3: Apply changes

Reload udev rules:
sudo udevadm control --reload
sudo udevadm trigger

sudo netplan try


Apply Netplan:
sudo netplan apply


Check interfaces:
ip a

Explanation

When you update Ubuntu (for example, from 20.04 to 22.04), it’s quite common to see network interface names change — like from eth0 to something like enp94s0f0 or eno1.

Here’s why it happens and what you can do about it:

Why it happens

Ubuntu 22.04 uses “Predictable Network Interface Names” (from systemd-udevd).
These names are based on your hardware’s BIOS, firmware, and PCI slot information, rather than simple numbering (eth0, eth1, etc.).

So, after an upgrade, your old interface names might change if:

The system’s hardware IDs are read differently.

The NICs are detected in a new order.

udev rules were reset or changed.

You switched from ifupdown or networking.service to Netplan (the default in Ubuntu 22+).

Rate this snippet

Click to rate

Have a Better Solution?

Know a more efficient way to solve this problem? Share your own code snippet and help the community!

Submit Your Version