4

I'm trying to rename a network interface on an Ubuntu 16.04 VPS, but am unable to do so. Systemd names my primary network interface enp0s3. I want to rename this interface to eth0.

According to the systemd.link documentation I created a file called /etc/systemd/network/10-eth0.link with the following content:

[Match]
MACAddress=08:00:27:f7:57:e5

[Link]
Name=eth0

The MAC address matches the one given in the ip a output for the interface. I also renamed the enp0s3 entries to eth0 in the /etc/network/interfaces file. Although, when I reboot the machine, the interface is still named enp0s3.

The following entries in the dmesg output are interesting to me:

e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:f7:57:e5
e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
e1000 0000:00:03.0 enp0s3: renamed from eth0

So apparently, it starts out as eth0, but is then renamed back to enp0s3 again. I am not sure why?

When I try to debug the link file, I get the following output:

$ sudo udevadm test-builtin net_setup_link /etc/systemd/network/10-eth0.link
calling: test-builtin
=== trie on-disk ===
tool version:          229
file size:         6841778 bytes
header size             80 bytes
strings            1755242 bytes
nodes              5086456 bytes
Load module index
timestamp of 'etc/systemd/network' changed
Parsed configuration file /lib/systemd/network/99-default.link
Parsed configuration file /etc/systemd/network/10-eth0.link
Created link configuration context.
unable to open device '/sys/etc/systemd/network/10-eth0.link'

Unload module index
Unloaded link configuration context.

The line about it being unable to open the device seems odd. I'm not sure why it's trying that, there is no etc directory under /sys at all, should I create it?

Any insights into why my interface name doesn't stick is very welcome.

6

According to https://www.freedesktop.org/software/systemd/man/systemd.link.html, the default naming policy is:

#  /usr/lib/systemd/network/99-default.link
[Link]
NamePolicy=kernel database onboard slot path
MACAddressPolicy=persistent

So I suspect you might want to add the following line to your eth0.link:

NamePolicy=mac

I haven't tested this, so I am not certain, but I suspect the issue is that you Match on MAC, but there is no naming policy to make that stick.

Each of the policies may fail, and the first successful one is used. The name is not set directly, but is exported to udev as the property "ID_NET_NAME", which is, by default, used by a udev rule to set "NAME". If the name has already been set by userspace, no renaming is performed

It is just a guess though.

You should also be able to just disable the default.link, at least per https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/

On some openSUSE systems I run, I had a similar issue, which (in addition to having had to use the 99-default.link 'trick') was resolved by creating two files under /etc/udev/rules.d (see https://unix.stackexchange.com/questions/118272/80-net-setup-link-no-longer-functions-when-i-downgraded-systemd, https://wiki.archlinux.org/index.php/Network_configuration#Device_names and https://wiki.gentoo.org/wiki/Udev/Upgrade_Guide):

sudo touch /etc/udev/rules.d/80-net-setup-link.rules (or just make sure an empty file of that name is in that location)

AND

I created /etc/udev/rules.d/10-persistent-network.rules:

ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*", ATTR{tx_queue_len}="1000"

In your case, you could actually use that file to set the name you want:

ACTION=="add", SUBSYSTEM=="net",ATTR{address}=="08:00:27:f7:57:e5",NAME="eth0"
  • This is an interesting suggestion. Although setting the NamePolicy and disabling the default link both did not change anything. The interface is still renamed to enp0s3 after a reboot. – Oldskool Mar 10 '17 at 14:54
  • Thank you for adding additional details to your answer. Adding the udev rules files did the trick! – Oldskool Mar 10 '17 at 16:04
2

I've tried all of the above. Nothing works. I have been researching constantly for 2 weeks.

I did find an answer AND IT WORKS. Here:

https://superuser.com/questions/914646/renaming-network-interface-with-systemd

The post contains a link to Lennart's notes, which help not at all. read the post and you should win.

Here is how I got it to work:

Step 1: sudo nano /etc/udev/rules.d/70-local-net-names.rules

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="74:da:38:68:55:c1", NAME="wlan1"

This file needs to be ordered before /usr/lib/udev/rules.d/80-net-setup-link.rules

This works on Debian Stretch. It should work on Ubuntu as well.

  • In my Debian Stretch, the file is /lib/udev/rules.d/80-net-setup-link.rules, not at /usr/lib/... – Lenne Oct 3 '17 at 15:11
1

Acording to systemd docs, this is due to the new Predictable Network Interface Names

Docs say you have three options to disable that behaviuor, and probably the third one is the easiest one:

  1. You disable the assignment of fixed names, so that the unpredictable kernel names are used again. For this, simply mask udev's .link file for the default policy: ln -s /dev/null /etc/systemd/network/99-default.link

  2. You create your own manual naming scheme, for example by naming your interfaces "internet0", "dmz0" or "lan0". For that create your own .link files in /etc/systemd/network/, that choose an explicit name or a better naming scheme for one, some, or all of your interfaces. See systemd.link(5) for more information.

  3. You pass the net.ifnames=0 on the kernel command line

  • I tried all three of these solutions, unfortunately the name still did not change. Something is still overruling it. – Oldskool Mar 10 '17 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.