User Tools

Site Tools


doc:appunti:linux:sa:if_rename

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:linux:sa:if_rename [2018/01/24 12:12] – [Debian 9 Network Interface Naming] niccolodoc:appunti:linux:sa:if_rename [2023/12/15 16:28] (current) – [With Debian 10 Buster] niccolo
Line 1: Line 1:
 ====== Renaming network interfaces ====== ====== Renaming network interfaces ======
 +
 +===== With Debian 10 Buster =====
 +
 +How to rename a network interface from e.g. **enx00e04c885302** to something more human like **lan0**? The preferred method is to create a file **/etc/systemd/network/10-persistent-lan0.link** (one file for each interface to be renamed) with something like this:
 +
 +<file>
 +#/etc/systemd/network/10-persistent-lan0.link
 +[Match]
 +MACAddress=00:e0:4c:88:53:02
 +[Link]
 +Name=lan0
 +</file>
 +
 +**WARNING**: You cannot use this method to safely assign the default kernel names (''eth0'', ''eth1'', ...) in your preferred order; this is because if systemd tries to rename an interface using a name which is already assigned by the kernel (e.g. it tries to swap ''eth0'' and ''eth1''), it fails. So the target **Name** must not potentially conflict with the names assigned by the kernel.
 +
 +**WARNING**: This method has an additional problem if you need to create a **VLAN**. When the system creates e.g. the **lan.602**, its MAC address matches the systemd snippet, so systemd tries to assign to it the name (**lan0** in the example above) but the name already exists, so the interface remains with a temporary name e.g. **rename5**.
 +
 +A workaround can be the following: tell the kernel to use the old ''ethX'' schema (passing the **net.ifnames=0** option), then instruct systemd to act only on **%%eth*%%** network interfaces:
 +
 +<file>
 +[Match]
 +MACAddress=00:e0:4c:88:53:02
 +OriginalName=eth*
 +[Link]
 +Name=lan0
 +</file>
 +
 +==== NetworkManager interfering with rename ====
 +
 +Both methods seen above seem to work, unfortunately on my XFCE environment, the **NetworkManager** stepped into the play, reverting back the name:
 +
 +<file>
 +NetworkManager[581]: <info>  [1620916630.3558] device (eth0):
 +   interface index 10 renamed iface from 'eth0' to 'enx00e04c885302'
 +</file>
 +
 +If you want to **manage the interface using NetworkManager** from the user session, be sure that the interface is not referred by **/etc/network/interfaces** or any snippet file into ''/etc/network/interfaces.d/''. If the interface is configured by ''/etc/network/interfaces'', NetworkManger will ignore it, labelling as //unmanaged//.
 +
 +==== Use the old naming schema (eth0, ...) ====
 +
 +If you want to use the old naming schema (eth0, eth1, ...) enable the kernel override option in **/etc/default/grub**:
 +
 +<file>
 +GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
 +</file>
 +
 +Followed by **update-grub** and **reboot**.
 +
 +Beware that by using that schema the card's assigned name depends upon the time when the kernel discover the interfaces, in some cases you may find the names swapped after a reboot, even if the Ethernet cards are fixed built-in.
 +
 +===== How it worked in the old days of Debian 4 Etch =====
  
 In a modern Linux system, network interface drivers are compiled as modules. Generally there is a subsytem that provides loading kernel modules automatically. Debian GNU/Linux Etch uses ''**udev**'' for that. In a modern Linux system, network interface drivers are compiled as modules. Generally there is a subsytem that provides loading kernel modules automatically. Debian GNU/Linux Etch uses ''**udev**'' for that.
Line 8: Line 59:
  
  
-===== udev =====+==== udev ====
  
 In a Debian Etch box, check the **''/etc/udev/rules.d/z25_persistent-net.rules''**. This file is updated at bootstrap when new network interfaces are found. It contains a persistent mapping of MAC addresses to interface names. In a Debian Etch box, check the **''/etc/udev/rules.d/z25_persistent-net.rules''**. This file is updated at bootstrap when new network interfaces are found. It contains a persistent mapping of MAC addresses to interface names.
Line 24: Line 75:
 </code> </code>
  
-===== ifrename =====+==== ifrename ====
  
 You configure this userspace program writing the configuration file''**/etc/iftab**'': You configure this userspace program writing the configuration file''**/etc/iftab**'':
Line 57: Line 108:
   * **s0** Slot #0   * **s0** Slot #0
   * **f1** Function #1 (eg. a dual porta LAN has two //functions//).   * **f1** Function #1 (eg. a dual porta LAN has two //functions//).
 +
 +Per disabilitare questa funzione, chiamata **[[https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/|Predictable Network Interface Names]]** è possibile aggiungere l'opzione kernel **net.ifnames=0** ad esempio in ''/etc/default/grub'', opzione **GRUB_CMDLINE_LINUX**.
 +
 +Se è installato la //helper utility// di udev chiamata **biosdevname**, è opportuno passare al kernel anche il parametro **biosdevname=0**.
 +
 +Avendo attivato l'opzione **net.ifnames=0** può essere comunque desiderabile una persistenza nell'assegnare il nome all'interfaccia , considerato che il kernel assegna i nomi legacy **eth0**, **eth1**, etc. in base all'ordine di rilevamento hardware, che è non deterministrico. È possibile quindi creare un file **/etc/udev/rules.d/70-network.rules** con l'assegnamento statico in base al MAC address, ad esempio
 +
 +<file>
 +SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:30:67:9a:75:0b", NAME="eth0"
 +SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:18:e7:22:0b:f7", NAME="eth1"
 +</file>
 +
 +**ATTENZIONE**: Pare che **il file con le regole udev viene ignorato** se manca l'opzione **net.ifnames=0** nella cmdline del kernel! Questo almeno è accaduto con Debian 11.7 e kernel 5.10.0-23-amd64.
  
 ===== Debian 9 Network Interface Naming ===== ===== Debian 9 Network Interface Naming =====
doc/appunti/linux/sa/if_rename.1516792323.txt.gz · Last modified: 2018/01/24 12:12 by niccolo