14

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.

merc1er
  • 243
  • 1
  • 2
  • 6

3 Answers3

28

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:

lshw -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.

sudo netplan try

When your happy with it

sudo netplan apply
Simon Banks
  • 1,337
6

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

  • this just adds a global NetworkManager connection with the set-name value, does not change the product name of the interface – allanlaal Nov 06 '22 at 00:38
0

The arm64 version of Focal Fossa I have does not have netplan, it uses nmcli, and changing the kernel command line is difficult. I was able to create /etc/udev/rules.d/73-special-net-names.rules (which on this install overrides /usr/lib/udev/rules.d/73-special-net-names.rules) to change the name of a usb attached ethernet port (after using lsusb to find the id 413c:a102) by adding:

ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb", ATTRS{idVendor}=="413c", ATTRS{idProduct}=="a102", NAME="eth0"

and then rebooting.

Zanna
  • 70,465
duanev
  • 101
  • Alternately you could just install the netplan package netplan.io its a lot more friendly then Netplan will do all the hard work for you. – Simon Banks Mar 22 '23 at 17:09