How to associate eth0/1/2 with Lan1/2/3

Good morning, everyone.
I am posting here the discussion I started on the Debian forum:

First of all, the operating system in use is a Diet-pi 9.13 64bit.

I am having difficulty understanding how to associate the three physical Ethernet interfaces, named LAN 1, LAN2 and LAN3, on a mini-PC with the standard names used in Linux, eth0, eth1 and eth2.

After performing clean installation a couple of times, I noticed that the operating system always associates eth0 with LAN2. Subsequently, if I edit the etc/network/interfaces file by entering

auto eth0 eth1 eth2
allow-hotplug eth0
allow-hotplug eth1
allow-hotplug eth2

iface eth0 inet dhcp (or static)
iface eth1 inet dhcp (or static)
iface eth2 inet dhcp (or static)

I find that eth1 is associated with LAN3 and eth2 with LAN1.

How does the operating system associate the physical interface with the name eth*?
Is there a way to associate eth0 with Physical LAN1, eth1 with LAN2, and eth2 with LAN3?

I would like to understand how to manage this association, also because the next step would be to clone the system on two other identical mini-PCs and not find the Ethernet interfaces associated randomly.

Thank you for your attention

P.S. original link: how to associate eth0/1/2 with Lan1/2/3 - Debian User Forums

Not really a DietPi issue, more related to the kernel which we don’t maintain for x86. On Debian (and most Linux distros using udev and systemd), the kernel no longer guarantees that a given physical NIC always gets the same classic name like eth0, eth1, etc. Normally, the first adapter which comes online during boot is assigned eth0, the second one eth1, and so on. That’s why you may see your NICs not in order you expect. AS well names can swap on reboot or after hardware changes.

To ensure one physical LAN port always has the same name (e.g., eth0), you can try to set an udev persistent naming rule.

  1. First, list your network interfaces with MAC addresses:
ip link show

You’ll see something like:

2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:11:22:33:44:66 brd ff:ff:ff:ff:ff:ff
4: eth2: ...
  1. Create a custom udev rule:
sudo nano /etc/udev/rules.d/70-persistent-net.rules
  1. Add a rule for your desired card, binding its MAC address to eth0:
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:11:22:33:44:55", NAME="eth0"

(Replace the MAC with your actual NIC’s hardware address.)

  1. Reload udev rules and reboot (or trigger them):
sudo udevadm control --reload-rules
sudo udevadm trigger

Hopefully the physical NIC will be eth0 now :slight_smile:

And using the dietpi-config utility?

This has nothing to do with dietpi-config. Creating udev rules would need to be done manually.