12

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.

3
  • In your research, did you look at this resource
    – graham
    Feb 17, 2021 at 8:24
  • I just tried this, with no success - the network went down when trying sudo netplan try
    – merc1er
    Feb 17, 2021 at 8:46
  • No software / applications should need to know the network interface name ... what sw are you using ?
    – Soren A
    Feb 17, 2021 at 9:03

3 Answers 3

27

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
8
  • Network interface went down after creating this file with this content.
    – merc1er
    Feb 17, 2021 at 9:08
  • Did you replace <MAC 'eth0' [ID1]> with your devices hardware address? Feb 17, 2021 at 9:14
  • If you do ip addr it will list all the devices and part of that output will be your mac id.. e.g. link/ether dc:a6:32:e8:23:19 Feb 17, 2021 at 9:16
  • That's how netplan identifies the device to rename.. Then run.. sudo netplan apply Feb 17, 2021 at 9:17
  • I've added more details to the answer to help you.. Feb 17, 2021 at 9:22
5

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
1
  • this just adds a global NetworkManager connection with the set-name value, does not change the product name of the interface
    – allanlaal
    Nov 6, 2022 at 0: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.

1
  • 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. Mar 22 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .