Migrate network device names to the udev standard of Debian 9 (Stretch)

botond published 2019/07/14, v - 17:20 time

Content

 

Introductory

Debian has been available since the release of 9 (Stretch) introduced a new network interface naming scheme. Names of previously used Ethernet devices (e.g. eth0) or WLAN device names (for example, wlan0), etc. - a newly installed Debian 9 Stretch system - uses names like enp5s7, Respectively wlp2s0. However, this change does not affect the previous systems Updated from Debian 8 (Jessie)so that the network can continue to work with the previous settings. The udev so Debian 9 (Stretch) still manages these old network names, but They are no longer officially supported by Debian 10 (Buster). Therefore, if you want to upgrade a Debian 9 (Stretch) system to Debian 10 (Buster) that was previously upgraded from Debian 8 (Jessie), which still uses the old network interface names, you need to do this. a small option to switch the use of names to the new udev schema so that the network will continue to work after upgrades to later Debian releases.

In this description, we will migrate to use the new names to make our system compatible with Debian 10 (Buster). Of course, those planning to upgrade to Buster from a newly installed Debian 9 (Stretch) system are not. However, in the lifetime of a server that has been in operation for many years, a full distribution upgrade may occur several times to allow services to be up and running again without a minimum downtime, with minimal downtime. In these cases, however, this setting must be made in advance to avoid network problems after the upgrade.

 

 

Alternative solutions

A workaround could be to switch to a supported mechanism that forces the old naming scheme, such as systemd .link file solution. Another alternative is the net.ifnames = 0 kernel parameter Set.

However, sooner or later you will have to switch to using the new names, so preferably do not use alternative solutions - as these will only delay the problem - but make the following settings here.

 

Transition to use new network device names

Previously I updated my laptop from Debian 8 (Jessie) to Debian 9 (Stretch), so this state now comes in handy to illustrate the setting. So we have a machine upgraded to Stretch, which still uses the old named network interface names, so now we will migrate them to the new schema.

Settings from my desktop SSHI log in via, providing similar conditions as if I were performing the same on a remote server.

Discovering old and new names

First, find out what network device names your system uses. You can do this with the following command:

echo /sys/class/net/[ew]*

This is the output for me:

/sys/class/net/eth0 /sys/class/net/wlan0

So it clearly shows that this machine has one eth0 network card and one wlan0 called WIFI adapter. Currently these names are used.

Next, let's look at which configuration files refer to these names. Running this for each device name can be queried with a grep command:

grep -rnw "eth0" /etc
grep -rnw "wlan0" /etc

Of course, everyone should run a search using the names in their system:

(In this case, the color output of grep commandwhich I previously set in my .bashrc file.)

He has published a few results here, not bad, they can be scolded soon. Of course, this machine is almost a basic installation, and I use it just as a pilot, so there may be a lot more references on a more inclusive machine or on a server.

Now let's find out what names the new udev schema would use in the same system. And this is below udevadm commands to look at each network device separately:

udevadm test-builtin net_id /sys/class/net/eth0 2>/dev/null
udevadm test-builtin net_id /sys/class/net/wlan0 2>/dev/null

I have the output of these commands:

Here is the last line of command output: the future name of the network card enp5s7 and the WIFI adapter wlp2s0. These names are compiled according to the new scheme based on the serial number of the PCI buses on the motherboards and other hardware identifiers, which are assembled into a uniquely identifiable device name.

If the output of the udevadm command also gives an "onboard" name, it will be the primary one. MAC-based names are usually used only for feedback if you can't find the primary name, etc., but may also be required when using USB-based network devices.

The information so far is enough to start the migration.

 

 

Switch to using new names

On a normal machine

To migrate, log in as root on a normal machine (not a virtual machine), if you have not already done so, and rename it to /etc/udev/rules.d/70-persistent-net.rules file, or comment on the lines describing the tools in it. I suggest the latter, so let's open it for editing:

nano /etc/udev/rules.d/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:0x8139 (8139too)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1a:92:fb:6e:48", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x168c:0x001c (ath5k)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1b:9e:3f:4a:cd", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

And with green, we highlight the lines. There must be as many lines as there are network devices in our machine.

On a virtual machine

On virtual machines, the following file must also be deleted as root:

rm /etc/systemd/network/99-default.link

And if the virtual machine virtio uses a network device, in which case even this file:

rm /etc/systemd/network/50-virtio-kernel-names.link

 

If we can, rebuild the initrd update-initramfs command (also as root):

update-initramfs -u

Next, run the grep command again to change the old names in all the configuration files to the new names until the configuration files containing the old names run out.

It is not necessary to overwrite the results that start with comments, but you will never know what comment setting will take effect later, so I suggest that you overwrite any old name occurrences with the new ones.
This could be solved with a sed string replacement command, but in the / etc directory I would rather fix it manually in the configuration files.

Restart machine

Then restart the machine:

reboot

Of course, if this machine is a live server, we should inform users about the restart first and make sure there are no open documents, etc.

Az original description this section was described in reverse, so the restart section came first. However, if you are logged on to the machine over a remote SSH connection, it would not be advisable to restart the machine before repairing the configuration files, as the network may not start up due to lack of proper configuration files, so you will not be able to revert to SSH after restarting. , but we could only finish the job on the console. In the case of a remote server, this would be a very big problem.

 

 

Network Testing

After restarting the machine (after a wait for a remote machine, wait about a while) to log back in (no longer asking for a password because I completed the public key entry) and run as root ifconfig command:

ifconfig

The output of which speaks for itself: He became one enp5s7 network card and one wlp2s0 is called a WLAN device. And once we've been able to log on to SSH, all the networking is working properly, like the internet.

 

Conclusion

After that, our system, which has been upgraded from Debian 8 (Jessie) to Debian 9 (Stretch), uses the new network interface naming scheme, so if the time comes, we can start upgrading our system to Debian 10 (Buster).