Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

stateless persistant network interface names in systemd/udev

User discussion about Debian Development, Debian Project News and Announcements. Not for support questions.
Post Reply
Message
Author
shirish
Posts: 845
Joined: 2010-12-08 12:59

stateless persistant network interface names in systemd/udev

#1 Post by shirish »

Hi all,
Today while upgrading in stretch came across the following in systemd, udev 220-7 the whole shebang :-

Code: Select all

[$] dpkg -l systemd
                                                                                                                
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                           Version              Architecture         Description
+++-==============================-====================-====================-=================================================================
ii  systemd                        220-7                amd64                system and service manager
I had a look at the changelog as use apt-listchanges to go through any news in case it comes in.

Saw these significant bits shared therein :-
$ /usr/share/doc/systemd $ zcat changelog.gz | less

systemd (220-7) unstable; urgency=medium

[ Michael Biebl ]
* Enable seccomp support on arm64 as well.
* Replace the remainder of Fix-paths-in-man-pages.patch with an upstream
provided patch.

[ Martin Pitt ]
* Switch to net.ifnames persistant network interfaces (on new
installations/for new hardware), and deprecate the old
75-persistent-net-generator.rules. See the ML discussion for details:
https://lists.debian.org/debian-devel/2 ... 00170.html
https://lists.debian.org/debian-devel/2 ... 00018.html
- Drop Make-net.ifnames-opt-in-instead-of-opt-out.patch, to use
net.ifnames by default.
- Revert-udev-network-device-renaming-immediately-give.patch: Adjust
patch comment.
- Drop 75-persistent-net-generator.rules, write_net_rules helper and
rule_generator.functions.
- Adjust udev's README.Debian accordingly, and describe the migration.
This needs to happen manually as there is no robust way of doing this
automatically.
- Add udev NEWS file for announcing this change and pointing to udev's
README.
- udev.postinst: Drop write_interfaces_rules().
- udev.postinst: Disable net.ifnames on systems which did not support
75-persistent-net-generator.rules (most importantly, virtualized guests)
to avoid changing network interface names on upgrade.
- LP: #1454254
* fsckd-daemon-for-inter-fsckd-communication.patch: Add fsckd.c to
POTFILES.in.
* ifupdown-hotplug autopkgtest: Fix config name in interfaces.d/, it must
not have a suffix in Debian. Also clean up the file after the test.
* net.agent: When running under systemd, run everything in the foreground.
This avoids killing the forked child in the middle of its operation under
systemd when the parent exits.
* Check during build that systemd and systemd-journald don't link against
anything in /usr, to prevent bugs like #771652 and #788913 in the future.
* Drop Skip-99-systemd.rules-when-not-running-systemd-as-in.patch. The rules
mostly just attach tags systemd specific properties which are harmless
under other init systems, and systemd-sysctl also works there.
* 80-networking.rules: Only call agents for add|remove, as they don't handle
other events.
* Restore udev watches on block device changes. (Closes: #789060,
LP: #1466081)

-- Martin Pitt <mpitt@debian.org> Wed, 17 Jun 2015 22:48:53 +0200
I rebooted and also read the udev README which explains the change in more detail :-

[/usr/share/doc/udev] -
└─[$] zcat README.Debian.gz

Network interface naming
~~~~~~~~~~~~~~~~~~~~~~~~
Since version 197 udev has a builtin persistant name generator which checks
firmware/BIOS provided index numbers or slot names (similar to biosdevname),
falls back to slot names (PCI numbers, etc., in the spirit of
/dev/disks/by-path/), and then optionally falls back to MAC address, and
generates names based on these properties. This provides "location oriented"
names for PCI cards such as "enp0s1" for ethernet, or wlp1s0" for a WIFI card
so that replacing a broken network card does not change the name. As location
based naming does not work well for USB devices, these use a MAC based naming
schema (see /lib/systemd/network/01-mac-for-usb.link).

This has been enabled by default since udev 220-7, which affects new
installations/hardware. Existing installations/hardware which already got
covered by the old 75-persistent-net-generator.rules will keep their interface
names, see below.

You can disable these stable names and go back to the kernel-provided ones
(which don't have a stable order) by putting "net.ifnames=0" into the kernel
command line (e. g. in /etc/default/grub's GRUB_CMDLINE_LINUX_DEFAULT).

See this page for more information:
http://www.freedesktop.org/wiki/Softwar ... faceNames/

Legacy persistant network interface naming
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Debian releases up to 8 ("Jessie") and Ubuntu up to 15.04 had an udev rule
/lib/udev/rules.d/75-persistent-net-generator.rules which fixed the name of a
network interface that it got when its MAC address first appeared in a
dynamically created /etc/udev/rules.d/70-persistent-net.rules file.

This had inherent race conditions (which sometimes caused collisions and
interface names like "rename1"), required having to write state into /etc
(which isn't possible for read-only root), and did not work in virtualized
environments.

This old schema is deprecated in Debian 9 ("Stretch"), and will not
be supported any more in Debian 10.

Migration to the current network interface naming
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On package upgrade systems will keep their current names, but they will need to
be manually migrated by Debian 10 / Ubuntu 18.04 LTS. If you rely on the old
names in custom ifupdown stanzas, firewall scripts or other networking
configuration, these need to be updated to the new names.

First, determine all relevant network interface names: those in
/etc/udev/rules.d/70-persistent-net.rules, or if that does not exist (in
virtual machines), in "ip link" or /sys/class/net/.

Then for all of thse use a command like

grep -r eth0 /etc

Then on "real hardware" machines, rename the file to
70-persistent-net.rules.old; on VMs remove the file
/etc/udev/rules.d/80-net-setup-link.rules instead.

Reboot, adjust configuration files, and test your system.

Custom net interface naming
~~~~~~~~~~~~~~~~~~~~~~~~~~~
In some cases it is convenient to define your own specific names for network
interfaces. These can be customized in two different ways:

* You can create your own names via udev rules, based on arbitrary attribute
and property matches. See man udev(7) for documentation how to write udev
rules. For example, you can create /etc/udev/rules.d/76-netnames.rules with

------------ snip ----------
# identify device by MAC address
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="11:22:aa:bb:cc:33", NAME="eth-dmz"

# identify by vendor/model ID
SUBSYSTEM=="net", ACTION=="add", ENV{ID_VENDOR_ID}=="0x8086", \
ENV{ID_MODEL_ID}=="0x1502", NAME="eth-intel-gb"

# USB device by path
# get ID_PATH if not present yet
ENV{ID_PATH}=="", IMPORT{builtin}="path_id"
SUBSYSTEM=="net", ACTION=="add", ENV{ID_PATH}=="*-usb-0:3:1*", NAME="eth-blue-hub"
------------ snip ----------

The name of the rules file needs to have a prefix smaller than "80" so that
it runs before /lib/udev/rules.d/80-net-setup-link.rules, and should have a
prefix bigger than "75" so that it runs after 75-net-description.rules and
thus you can use matches on ID_VENDOR and similar properties.

* Unless you disabled net.ifnames, you can change the policy
(kernel/bios/path/MAC based naming) in an /etc/systemd/network/*.link file,
for individual devices or entire device classes. See man systemd.link(5) for
details about this. /lib/systemd/network/99-default.link is the default
policy, and /lib/systemd/network/01-mac-for-usb.link makes it use MAC based
names for USB devices.

Hotplugged Network Interfaces
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
After receiving events about network interfaces, net.agent will call
ifupdown using the --allow=hotplug option. This makes the program act
only on interfaces marked with the "allow-hotplug" statement.
E.g: "allow-hotplug eth0" instead of the usual "auto eth0".
Under SysVinit, the loopback interface must always be configured with "auto
lo". Under systemd it is not necessary to explicitly configure "lo".

Using udev with LDAP or NIS
~~~~~~~~~~~~~~~~~~~~~~~~~~~
If the rules files reference usernames or groups not present in the
/etc/{passwd,group} files and the system is configured to use a
network-based database like LDAP or NIS then udev may fail at boot time
because users and groups are looked up well before the network has been
initialized.
A possible solution is to configure /etc/nsswitch.conf like this:

passwd: files ldap [UNAVAIL=return]
group: files ldap [UNAVAIL=return]

The nsswitch.conf syntax is documented in the glibc manual.
This is how I have set up my network interfaces file :-

Code: Select all

[/etc/network]
└─[$] cat interfaces   
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
This is how my /etc/udev/rules.d/ looks after the upgrade :-

Code: Select all

 [/etc/udev/rules.d]
└─[$] ls 
70-persistent-cd.rules  70-persistent-net.rules  i2c_smbus.rules
and this is the output when seeing 70-persistent-net.rules :-

Code: Select all

[/etc/udev/rules.d] - 
└─[$] cat 70-persistent-net.rules                                                                                           
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x10ec:/sys/devices/pci0000:00/0000:00:1c.2/0000:01:00.0 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Now as per documentation I should rename the file 70-persistent-net.rules to 70-persistent-net.rules.old . What I am unsure about is the "Reboot, adjust configuration files, and test your system." According to the udev README.

According to http://cgit.freedesktop.org/systemd/sys ... t_id.c#n20 it seems the name will change from eth0 to something else. How do I find the new name ? Also can anybody comment what configuration files I will have to change besides /etc/network/interfaces ?

Also does this mean that for new installations /etc/udev/rules.d would be empty as far as any net.rules are concerned ?

Update - https://wiki.archlinux.org/index.php/Systemd-networkd seems to have some more info.

Looking forward to know
Intel Dual-Core CPU E5400 (soc 775) @ 2.70GHz, onboard Intel G33, Asus MB P5KPL-AM IN (Intel G31), D-Link 2750u modem+router, 64-bit Debian Testing, Mate 1.26

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: stateless persistant network interface names in systemd/

#2 Post by Head_on_a_Stick »

shirish wrote:How do I find the new name ?

Code: Select all

ip l
deadbang

shirish
Posts: 845
Joined: 2010-12-08 12:59

Re: stateless persistant network interface names in systemd/

#3 Post by shirish »

Head_on_a_Stick wrote:
shirish wrote:How do I find the new name ?

Code: Select all

ip l
Thanx but it's :-

Code: Select all

[$] ip a                                                                                                                          
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.33/24 brd 192.168.1.255 scope global enp1s0
       valid_lft forever preferred_lft forever
I tried all to use the new way and had to revert to the tried and tested method (letting the kernel do its thing).

Failed miserably.

One of the things I am and was unsure of is what should be the name of the file at /etc/systemd/network/??

Should it be /etc/systemd/network/wired.network or /etc/systemd/network/enp1s0.network or /etc/systemd/network/80-dhcp.network

Also is this content enough or should it be something more ?

Code: Select all

/etc/systemd/network/80-dhcp.network
[Match]
Name=enp1s0

[Network]
DHCP=yes
or

Code: Select all

Example 2. /etc/systemd/network/80-dhcp.network
[Match]
Name=en*
[Network]
DHCP=yes
from http://www.freedesktop.org/software/sys ... twork.html

Then on my machine it's :-

Code: Select all

$] sudo grep -r eth0 /etc                                                                                                         
/etc/samba/smb.conf:;   interfaces = 127.0.0.0/8 eth0
/etc/aide/aide.conf.d/31_aide_ifplugd:@@define INTERFACES eth0
/etc/aide/aide.conf.d/31_aide_dhcp3-client:@@define INTERFACES eth0
/etc/avahi/avahi-daemon.conf.backup:#allow-interfaces=eth0
/etc/avahi/avahi-daemon.conf:#allow-interfaces=eth0
/etc/udev/rules.d/70-persistent-net.rules:SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
/etc/vnstat.conf:Interface "eth0"
/etc/dhcp/dhclient.conf:#  interface "eth0";
/etc/dhcp/dhclient.conf:#  interface "eth0";
/etc/dhcp/dhclient.conf.backup:#  interface "eth0";
/etc/dhcp/dhclient.conf.backup:#  interface "eth0";
/etc/dhcp/dhclient.conf.dpkg-dist:#  interface "eth0";
/etc/dhcp/dhclient.conf.dpkg-dist:#  interface "eth0";
/etc/initramfs-tools/initramfs.conf:# Specify a specific network interface, like eth0
/etc/network/interfaces:auto eth0
/etc/network/interfaces:allow-hotplug eth0
/etc/network/interfaces:iface eth0 inet dhcp
Last edited by shirish on 2015-06-18 20:31, edited 1 time in total.
Intel Dual-Core CPU E5400 (soc 775) @ 2.70GHz, onboard Intel G33, Asus MB P5KPL-AM IN (Intel G31), D-Link 2750u modem+router, 64-bit Debian Testing, Mate 1.26

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: stateless persistant network interface names in systemd/

#4 Post by Head_on_a_Stick »

I must admit that your OP was a bit tl;dr so I didn't read it all...

If you want to use systemd-networkd for your ethernet connection, see this quick guide:
http://crunchbang.org/forums/viewtopic.php?id=39823

Otherwise, just change "eth0" to "enp1s0" in /etc/network/interfaces and reboot.
deadbang

shirish
Posts: 845
Joined: 2010-12-08 12:59

Re: stateless persistant network interface names in systemd/

#5 Post by shirish »

Head_on_a_Stick wrote:I must admit that your OP was a bit tl;dr so I didn't read it all...

If you want to use systemd-networkd for your ethernet connection, see this quick guide:
http://crunchbang.org/forums/viewtopic.php?id=39823

Otherwise, just change "eth0" to "enp1s0" in /etc/network/interfaces and reboot.
This doesn't work and there seems to be a bug when you are symlinking

Code: Select all

sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
At least on my system most of the time /run/systemd/resolve/ isn't there. So had to revert fully.

Even just changing the /etc/network/interfaces name convention from "eth0" to "enp1s0" is nogo
Intel Dual-Core CPU E5400 (soc 775) @ 2.70GHz, onboard Intel G33, Asus MB P5KPL-AM IN (Intel G31), D-Link 2750u modem+router, 64-bit Debian Testing, Mate 1.26

fsmithred
Posts: 1873
Joined: 2008-01-02 14:52

Re: stateless persistant network interface names in systemd/

#6 Post by fsmithred »

I fired up an old sid in virtualbox to try this. After the hell of update/upgrade and repairing it in a chroot, I proceeded to try changing to the new name for the network interface. I couldn't find it, and I had to guess at it from the output of lspci. The ip command just showed the old name (eth0).
This:

Code: Select all

00:03.0 Ethernet controller...
Translates to 'enp0s3' which I believe means "ethernet, pci 0, slot 3".

To replace all references to eth0, I ran 'grep -r eth0 /etc' as suggested in the docs (posted above) and then ran

Code: Select all

sed -i 's/eth0/enp0s3/g'  <filename>
on each of the files that grep returned to replace eth0 with enp0s3.

I couldn't get the network to connect with wicd, so I edited /etc/network/interfaces and set up a static IP. There were several reboots in this process, and it eventually worked. Hope that helps.

Post Reply