How to set persistent NIC device name with PCI slot via udev instead of MAC address in Red Hat Enterprise Linux 6

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 6

Issue

  • Is it possible to create custom udev rules to use the PCI address of network card for persistent naming instead of the MAC address?

Resolution

  • First make sure the standard biosdevname feature will not fulfill your needs. More information is at Solution 159723

    • Ensure that console access is available in the event there are issues impacting connectivity during this process

    • If biosdevname does not meet your requirements, start by identifying the PCI address of your Ethernet interfaces with lspci

      # lspci -D | grep Ethernet
      0000:03:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
      0000:03:00.1 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
      0000:03:00.2 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
      0000:03:00.3 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
      
    • Create an /etc/udev/rules.d/60-persistent-net.rules as it needs to come before the RHEL generated 70-persistent-net.rules udev rule. Note the use of NAME:= to disallow later changes to value.

      # 0000:03:00.0 Ethernet controller: NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01) was eth0
      ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:03:00.0", NAME:="primary"
      
      # 0000:03:00.1 Ethernet controller: NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01) was eth1
      ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:03:00.1", NAME:="app1"
      
      # 0000:03:00.2 Ethernet controller: NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01) was eth2
      ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:03:00.2", NAME:="app2"
      
      # 0000:03:00.3 Ethernet controller: NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01) was eth3
      ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:03:00.3", NAME:="backup"
      
    • Modify /etc/sysconfig-network/scripts/ifcfg-* files to utilize new names in the DEVICE= value.

      # grep ^DEVICE= ifcfg-* | grep -v =lo$
      ifcfg-app1:DEVICE="app1"
      ifcfg-app2:DEVICE="app2"
      ifcfg-backup:DEVICE="backup"
      ifcfg-primary:DEVICE="primary"
      
    • Use udevadm to test rules to make sure name setting is working

      # udevadm test /class/net/eth0 2>&1 | grep NAME
      udev_rules_apply_to_event: NAME 'primary' /etc/udev/rules.d/60-persistent-net.rules:2
      
  • Reboot the system and review that the changes have been made as expected.

NOTE: This was tested on system that is NOT using NetworkManager (ie. NM_CONTROLLED=no in ifcfg-* files)

Diagnostic Steps

Some Red Hat documents for reference:

Some public site references:

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.

Comments