Linux Network Interface Naming: Difference between revisions

From Leo's Notes
This page was last edited on 20 June 2020, at 18:23.
Created page with "Do you have network interfaces that no longer start at 0 (eg: eth0, em1, etc...)? == Edit udev Rules == To renumber the interfaces, you can edit the udev rules at: /etc/u..."
 
updated content
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
Do you have network interfaces that no longer start at 0 (eg: eth0, em1, etc...)?
Traditionally, network interfaces on Linux are enumerated as <code>eth[0...n]</code>, where the first device being probed on start up is assigned <code>eth0</code> and so on. Modern Linux utilizing systemd will assign network interfaces based on a [https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ Predictable Network Interface naming scheme] which corresponds the network name to its hardware location. For example, an interface is named <code>wlp2p1</code> because it is a wireless device located at a PCI bus 2, slot 1. The motivation for this is to deterministically set network adapter names on systems with multiple adapters.  


== Edit udev Rules ==
== Predictable Network Naming ==
Systems using the predictable network naming scheme will be named according to the following (simplified) rules. For the full description of these rules in greater detail, see the [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/consistent-network-interface-device-naming_configuring-and-managing-networking Red Hat documentation for RHEL 8 on predictable network naming].
{| class="wikitable"
|+
!Prefix
!Suffix
|-
|
* <code>en</code> - ethernet
* <code>wl</code> - wireless LAN
* <code>ww</code> - wireless wide area network
|
* <code>o''N''</code> - onboard device, where N is the onboard index
* <code>s''N''</code> - hot plug, where N is the slot index
* <code>x''MAC''</code> - based on MAC address
* <code>p''N''/s''X''</code> - for devices connected on a bus, where N is the bus number and X is the slot number.
|}
For example: eno0 is the first onboard ethernet device, while enp0s0 is the first ethernet device connected to the first bus on the first slot.


To renumber the interfaces, you can edit the udev rules at:
==Revert back to the traditional {{code|eth[0..N]}} naming scheme==
  /etc/udev/rules.d/70-persistent-net.rules
You can revert back the old naming scheme using any one of the following methods as outlined on [https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ this systemd page].  


Remove lines defining the extraneous interfaces that you don't want. Once done, ensure that your network configs are correct (RedHat based only)
#You create your own manual naming scheme by creating your own <code>''custom''.link</code> files within <code>/etc/systemd/network/</code> which defines the specific name you wish to use. The description for this file is outlined at https://www.freedesktop.org/software/systemd/man/systemd.link.html<nowiki/>{{Highlight
| code = # Match based on MAC address (and device path if uncommented)
[Match]
MACAddress=00:a0:de:63:7a:e6
# Path=pci-0000:02:00.0-*


cd /etc/sysconfig/network-scripts/
# Link properties
ls ifcfg*
[Link]
Name=eth0
| lang = text
}} In the example above, the device matching the given MAC address will have its name set to eth0.
#You pass {{code|1=net.ifnames=0}} to the kernel on boot by setting it in the boot loader. This is not recommended on systems with multiple network interfaces as they may be assigned names inconsistently across reboots. This should be safe on systems with only one network adapter. You set this kernel argument this by editing {{code|/etc/default/grub}}, appending <code>net.ifnames=0</code> to the kernel command line, applying it with {{code|grub2-mkconfig -o /boot/grub2/grub.cfg}}, and then rebooting.
#You disable the assignment of fixed names by symlinking <code>/etc/systemd/network/99-default.link</code> to <code>/dev/null</code> and rebuilding initrd.


Ensure the scripts matches up to the interfaces you defined in the udev rules. Once completed, reboot the machine.
==Renumbering network interfaces==
If your system is relying on udev rather than systemd-udevd (and thereby using systemd's predictable network interfacing naming scheme), after inserting and removing network interfaces, your network interface now has a non-zero number. For example, after inserting and replacing a network interface twice, the primary interface is now named <code>eth2</code>. Systems affected by this problem includes RHEL 6 or prior.
 
To rename interfaces so that it starts back at <code>eth0</code>, edit the udev rules defined in {{code|/etc/udev/rules.d/70-persistent-net.rules}}. Remove lines defining the extraneous interfaces that you don't want. Once done, ensure that your network configs in <code>/etc/sysconfig/network-scripts/</code> matches up to your new network interface names.
 
Reboot to apply.
 
==See Also==
 
*[[Udev Rules]]
*https://access.redhat.com/solutions/2435891
*https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/ch-consistent_network_device_naming
*https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/consistent-network-interface-device-naming_configuring-and-managing-networking
 
{{Navbox Linux}}
[[Category:Linux]]

Latest revision as of 18:23, 20 June 2020

Traditionally, network interfaces on Linux are enumerated as eth[0...n], where the first device being probed on start up is assigned eth0 and so on. Modern Linux utilizing systemd will assign network interfaces based on a Predictable Network Interface naming scheme which corresponds the network name to its hardware location. For example, an interface is named wlp2p1 because it is a wireless device located at a PCI bus 2, slot 1. The motivation for this is to deterministically set network adapter names on systems with multiple adapters.

Predictable Network Naming

Systems using the predictable network naming scheme will be named according to the following (simplified) rules. For the full description of these rules in greater detail, see the Red Hat documentation for RHEL 8 on predictable network naming.

Prefix Suffix
  • en - ethernet
  • wl - wireless LAN
  • ww - wireless wide area network
  • oN - onboard device, where N is the onboard index
  • sN - hot plug, where N is the slot index
  • xMAC - based on MAC address
  • pN/sX - for devices connected on a bus, where N is the bus number and X is the slot number.

For example: eno0 is the first onboard ethernet device, while enp0s0 is the first ethernet device connected to the first bus on the first slot.

Revert back to the traditional eth[0..N] naming scheme

You can revert back the old naming scheme using any one of the following methods as outlined on this systemd page.

  1. You create your own manual naming scheme by creating your own custom.link files within /etc/systemd/network/ which defines the specific name you wish to use. The description for this file is outlined at https://www.freedesktop.org/software/systemd/man/systemd.link.html
    # Match based on MAC address (and device path if uncommented)
    [Match]
    MACAddress=00:a0:de:63:7a:e6
    # Path=pci-0000:02:00.0-*
    
    # Link properties
    [Link]
    Name=eth0
    
    In the example above, the device matching the given MAC address will have its name set to eth0.
  2. You pass net.ifnames=0 to the kernel on boot by setting it in the boot loader. This is not recommended on systems with multiple network interfaces as they may be assigned names inconsistently across reboots. This should be safe on systems with only one network adapter. You set this kernel argument this by editing /etc/default/grub, appending net.ifnames=0 to the kernel command line, applying it with grub2-mkconfig -o /boot/grub2/grub.cfg, and then rebooting.
  3. You disable the assignment of fixed names by symlinking /etc/systemd/network/99-default.link to /dev/null and rebuilding initrd.

Renumbering network interfaces

If your system is relying on udev rather than systemd-udevd (and thereby using systemd's predictable network interfacing naming scheme), after inserting and removing network interfaces, your network interface now has a non-zero number. For example, after inserting and replacing a network interface twice, the primary interface is now named eth2. Systems affected by this problem includes RHEL 6 or prior.

To rename interfaces so that it starts back at eth0, edit the udev rules defined in /etc/udev/rules.d/70-persistent-net.rules. Remove lines defining the extraneous interfaces that you don't want. Once done, ensure that your network configs in /etc/sysconfig/network-scripts/ matches up to your new network interface names.

Reboot to apply.

See Also