How to assign a specific network interface name in RHEL 7, 8, 9, 10

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 10
  • Red Hat Enterprise Linux 9
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 7

Issue

  • Need to directly control network interface names in RHEL7
  • How to make NIC names persistent across reboots in Red Hat Enterprise Linux 8
  • How do I manually name NICs to names like netX in RHEL 9?
  • Can we configure or assign the interface names using the network initscript in RHEL 10?

Resolution

Note: Do not use ethX style names (eg: eth0, eth1). ethX names are not supported. ethX names do not work as expected.

Select a name outside of the kernel used names (ethX, wlanX, ibX, usbX, etc.) and outside of the systemd used names (enoX, ensX, pXpY, etc).

Suggested valid manual names are:

  • netX style - net0, net1, etc
  • Descriptive words - prod, mgmt, backup, etc

This knowledgebase solution is intended to provide a quick reference only.

For full step-by-step details of all options and steps, please refer to the product documentation:

First, pick a renaming option.

If you pick one of options 1 through 4, update the NetworkManager configuration or ifcfg-file to use the new name.

Option 1 - udev Rules by MAC Address

/etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",ATTR{type}=="1",NAME="net0"

Option 2 - udev Rules by PCI Bus Location

/etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net",ACTION=="add",KERNEL=="eth*",SUBSYSTEMS=="pci",KERNELS=="0000:00:03.0",NAME="net0"
# mkdir -p /etc/systemd/network/

/etc/systemd/network/70-net0.link

[Match]
MACAddress=aa:bb:cc:dd:ee:ff

[Link]
Name=net0

Important note : Ensure systemd link files are named like 70-interface_name.link to ensure correct processing order, see man systemd.link for full explanation.

To get the pci address run the command udevadm info /sys/class/net/enp1s0 | grep ID_PATH and copy the id from ID_PATH=

# mkdir -p /etc/systemd/network/

/etc/systemd/network/70-net0.link

[Match]
Path=pci-0000:01:00.0

[Link]
Name=net0
/etc/systemd/network/70-altname-net0.link

[Match]
MACAddress=aa:bb:cc:dd:ee:ff

[Link]
AlternativeName=net0
AlternativeName=prod

Option 6 - DEPRECATED - initscripts ifcfg-helper

This option is deprecated and will be removed in RHEL 10. It is not recommended.

/etc/sysconfig/network-scripts/ifcfg-net0

DEVICE=net0
NAME=net0
HWADDR=aa:bb:cc:dd:ee:ff

If using NetworkManager, assign the NetworkManager Connection to the new device name

# nmcli connection modify "net0" connection.interface-name "net0"

Reboot.

If using network initscript, assign the ifcfg-file to the new device name

/etc/sysconfig/network-scripts/ifcfg-net0

DEVICE=net0
NAME=net0

Reboot.

Root Cause

With RHEL 7's move to systemd-udev and increasing parallelisation of the boot process, device renaming conflicts were removed from udev. To avoid conflicts, interface names are now generated uniquely based on hardware location:

Where the systemd names are not desirable, there are multiple options for manual naming, presented in the Resolution section above.

To avoid udev naming conflicts now or in the future, names chosen must be outside of the kernel device namespace (ethX, etc) and outside of the systemd device namespace (enoX, ensX, pXpY, etc).

The network configuration method - NetworkManager or initscripts - must then be updated to be aware of the new device configuration.

Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.