0

It turns out that I'm trying to create a portable distro while getting prepared for any kind of hardware failure.

I'm creating (or restoring) a Debian distro by multistrap (or from my backups) and requiring the resulting disk to be bootable on a new (mostly compatible) hardware, including a VirtualBox machine.

As I asked before, one of the few required things for a "portable distro" is handling the network interfaces' names.

For example, on the real machine, first ethernet device is named as enp2s0 and in VirtualBox, it's named as enp0s3. How am I supposed to generate a /etc/network/interfaces file on boot?

Is there a more generic way to remap the network interface names (by symbolic links, maybe) and let every application use those names (the role names) without the necessity to know the real network interface names of the underlying hardware?

7
  • one way to fix it is to revert to the old interface names: eth0, etc. A tricky issue is to make it prefer the fastest, not the first interface -- ifupdown is pretty inept at handling it nicely.
    – user313992
    Commented Dec 25, 2019 at 10:29
  • The touch /etc/udev/rules.d/80-net-setup-link.rules trick didn't work on Debian 10.
    – ceremcem
    Commented Dec 25, 2019 at 10:38
  • It works for me on Debian 10, both on a vanilla version, and on my customized one.
    – user313992
    Commented Dec 25, 2019 at 10:49
  • 1
    Also see the "I don't like this, ..." section here
    – user313992
    Commented Dec 25, 2019 at 11:02
  • Here is my ifconfig output after a reboot: gist.github.com/ceremcem/fe29b009ba02f283bf34abe55b9dee27 What is the black magic behind touch .../80-net-setup-link.rules?
    – ceremcem
    Commented Dec 25, 2019 at 11:02

1 Answer 1

1

There are several ways you could solve this.

The most familiar way would probably be to disable the new network interface naming scheme by using the boot option net.ifnames=0, or by overriding /lib/systemd/network/99-default.link with ln -s /dev/null /etc/systemd/network/99-default.link, or by masking the udev rule file that actually implements the new-style names with ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules... see the Debian Wiki for more info on various ways to revert to the classic naming scheme. Then you could rewrite your /etc/network/interfaces to just use eth0.

The most flexible way would probably be to stop using static /etc/network/interfaces and switch to NetworkManager. It will automatically default to using DHCP on a network interface that has an active link, if there is no further configuration. That would automatically handle even cases when you have multiple NICs but only one (not necessarily the first one) is actually plugged in.

Or you could do your own thing, by writing a custom script that will read ip link show output (or the links in /sys/class/network) and rewrite /etc/network/interfaces (or whatever your actual network configuration file is) to suit. Then you could add the script as a systemd service with Wants=network-pre.target, Before=network-pre.target, After=module-init-tools.service and probably DefaultDependencies=no. This should allow the script to run as part of the early system set-up, after all modules have been loaded but before the network configuration begins.

3
  • I'm already using my own network-manager so I'll stick with "do your own thing" approach. Wouldn't that be an issue if I completely omit /etc/network/interfaces for the rest of the system services if I register my (or anyone's) network manager to the systemd? Doesn't anyone need to use that file directly?
    – ceremcem
    Commented Dec 25, 2019 at 11:21
  • Sorry, I mixed up your suggestions, you are suggesting to re-generate the /etc/network/interfaces on every boot (which satisfies my needs). What is the "predictable name" (thus the ID section) of ip link show output? Is it the sequence number of the command output?
    – ceremcem
    Commented Dec 25, 2019 at 11:26
  • If ip link show is tricky to parse, you could just look at links in /sys/class/network to find the network interface names, make an exception for lo, and then either test the interfaces for active links, rename them as you see fit, or whatever.
    – telcoM
    Commented Dec 25, 2019 at 11:29

You must log in to answer this question.

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