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
Last revisionBoth sides next revision
doc:appunti:linux:sa:if_rename [2021/05/13 17:14] – [With Debian 10 Buster] niccolodoc:appunti:linux:sa:if_rename [2024/04/12 18:01] – [Debian 9 predictable network interface names] niccolo
Line 3: Line 3:
 ===== With Debian 10 Buster ===== ===== With Debian 10 Buster =====
  
-According some sources, there is at least two methods to rename a network interface e.g. from **enx00e04c885302** to something more human like **lan0** or the plain old **eth0**. +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:
- +
-The simplest method should be to add a line into **/etc/network/interfaces** (or to create a new file **/etc/network/interfaces.d/local**) with the following:+
  
 <file> <file>
-rename enx00e04c885302=lan0+#/etc/systemd/network/10-persistent-lan0.link 
 +[Match] 
 +MACAddress=00:e0:4c:88:53:02 
 +[Link] 
 +Name=lan0
 </file> </file>
  
-Another methos should be to create a file **/etc/systemd/network/10-persistent-net.link** with something like+**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> <file>
-#/etc/systemd/network/10-persistent-net.link 
 [Match] [Match]
 MACAddress=00:e0:4c:88:53:02 MACAddress=00:e0:4c:88:53:02
 +OriginalName=eth*
 [Link] [Link]
 Name=lan0 Name=lan0
 </file> </file>
  
-Both seems to work, unfortunately on my XFCE environment, the **NetworkManager** stepped into the play, reverting back the name:+==== 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> <file>
Line 29: Line 36:
 </file> </file>
  
-To keep it simpleI choosed the kernel override option in **/etc/default/grub**:+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> <file>
Line 37: Line 48:
 Followed by **update-grub** and **reboot**. Followed by **update-grub** and **reboot**.
  
-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 itlabelling as //unmanaged//.+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 rebooteven if the Ethernet cards are fixed built-in.
  
 ===== How it worked in the old days of Debian 4 Etch ===== ===== How it worked in the old days of Debian 4 Etch =====
Line 108: Line 119:
 SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:18:e7:22:0b:f7", NAME="eth1" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:18:e7:22:0b:f7", NAME="eth1"
 </file> </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.
 +
 +:!: **ATTENZIONE**: Il file con le regole udev viene comunque ignorato in **Debian 11**.
 +
 ===== Debian 9 Network Interface Naming ===== ===== Debian 9 Network Interface Naming =====
  
doc/appunti/linux/sa/if_rename.txt · Last modified: 2024/04/12 18:01 by niccolo