How to rename a network interface in 20.04

My main ethernet interface is called enp2s0, but some software requires me to name it to eth0.

How can I rename it?

I tried creating /etc/udev/rules.d/10-rename-network.rules (as per this post), creating /etc/udev/rules.d/70-persistent-net.rule and editing /etc/network/interfaces.

The contents of /etc/udev/rules.d/10-rename-network.rules were:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="ff:ff:ff:ff:ff:ff", NAME="eth0"

with ff:ff...:ff replaced with the mac address of enp2s0.


Using netplan which is the default these days.. File /etc/netplan/50-cloud-init.yaml file.

Find the target devices mac/hw address using the lshw command:-

ilshw -C network

You'll see some output which looks like:-

root@ys:/etc# lshw -C network
  *-network
       description: Ethernet interface
       physical id: 2
       logical name: eth0
       serial: dc:a6:32:e8:23:19
       size: 1Gbit/s
       capacity: 1Gbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bcmgenet driverversion=5.8.0-1015-raspi duplex=full ip=192.168.0.112 link=yes multicast=yes port=MII speed=1Gbit/s

So then you take the serial

dc:a6:32:e8:23:19

Note the set-name option..

This works for the wifi section as well.

network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: <YOUR MAC ID HERE>
            set-name: eth0

Then then to test this config run..

netplan try

When your happy with it

netplan apply

Open "etc/netplan/01-network-manager-all.yaml" with any text editor and copy paste text from down bolow and don't forget to paste your own "mac addresses"

# Let NetworkManager manage all devices on this system
  network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: fc:15:b4:bn:34:g5
            set-name: eth0
        wlan0:
            dhcp4: true
            match:
                macaddress: 00:22:34:f4:d3:45
            set-name: wlan0

and save the file after that use

netplan try

netplan apply