Consistent network interface name ubuntu using pci slot

6,146

You should have a file at /etc/udev/rules.d/70-persistent-net.rules which contains a line similar to the following:-

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="04:01:07:ab:6e:01", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Make a backup of this file (outside of the rules.d) and edit the original to:-

SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:00:03.0", NAME="eth0"

where the KERNELS value can be gleaned from the 1st column of lspci -D

0000:00:03.0 Ethernet controller: Red Hat, Inc Virtio network device

The PCI address above breaks down as Domain:Bus:Slot.Function, so the device above is fitted to slot 3.


Note: I haven't got access to the console of the VM I used while writing this (I'm connected by SSH), so I can't check it, as I'll be locked out if it goes wrong. The bottom line is - be careful doing this as you may lock yourself out of a remote system; you'll be fine on a local system.

Share:
6,146

Related videos on Youtube

LUIS FRANCO
Author by

LUIS FRANCO

Updated on September 18, 2022

Comments

  • LUIS FRANCO
    LUIS FRANCO almost 2 years

    One can set consistent interface naming via mac address by modifying /etc/udev/rules.d/70-persistent-net.rules.

    • Can you establish consistent interface naming by PCI slot number? (I tried but failed)
    • Is there any other method to define consistent interface naming rather than MAC address?

    I am using Ubuntu 14.04.


    Modifying 70-persistent-net.rules per pci slot did not work in the case I had a 4 port NIC plugged into the top most pci slot:

    $ lspci -D | grep -i ether

    0000:04:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    0000:04:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    0000:05:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    0000:05:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    0000:0b:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
    0000:0c:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
    

    This is the file I used: /etc/udev/rules.d/70-persistent-net.rules

    # This file was automatically generated by the /lib/udev/write_net_rules
    # program, run by the persistent-net-generator.rules rules file.
    #
    # You can modify it, as long as you keep each rule on a single
    # line, and change only the value of the NAME= key.
    
    
    # PCI device 0x8086:0x10d3 (e1000e)
    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="aa:bb:cc:dd:ee:ff", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
    
    # PCI device 0x8086:0x10d3 (e1000e)
    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:aa:bb:cc:dd:ee", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
    
    SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:04:00.0", NAME="eth2"
    SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:04:00.1", NAME="eth3"
    SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:05:00.0", NAME="eth4"
    SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:05:00.1", NAME="eth5"
    

    Now if I plug in a two port NIC in the same slot:

    0000:02:00.0 Ethernet controller: Intel Corporation 82580 Gigabit Fiber Network Connection (rev 01)
    0000:02:00.1 Ethernet controller: Intel Corporation 82580 Gigabit Fiber Network Connection (rev 01)
    0000:06:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
    0000:07:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
    

    You can see the PCI slot numbers changed.

  • LUIS FRANCO
    LUIS FRANCO almost 10 years
    Thanks @garethTheRed. But can't this PCI domain number change depending upon how many devices are plugged into the motherboard? Are you sure that the pci address is fixed to the slot number?
  • garethTheRed
    garethTheRed almost 10 years
    The PCI address above contains the slot number - I've added a little explanation.
  • LUIS FRANCO
    LUIS FRANCO almost 10 years
    So I have been looking at your answer and playing around with different NIC's. I noticed that if I plug in different NIC's with a different number of interfaces, the slot number changes! Is there any way to account for this? I will be constantly installing and removing NIC's with a different number of interfaces.
  • garethTheRed
    garethTheRed almost 10 years
    Is it the slot number or the function number (the bit after the dot) that changes? It should be the latter.
  • garethTheRed
    garethTheRed almost 10 years
    Well, I'm flummoxed now! It blows my understanding of PCI straight out of the window. My laptop's listing of PCI slots is more in keeping with my answer - there are many different numbers after the second colon (the slot ID) whereas yours are always zero for the slot ID with many different bus IDs (after the 1st colon). Of course, mine aren't all Ethernet cards as I only have one built-in port, but that shouldn't make a difference as I understand it (or understood it!)
  • LUIS FRANCO
    LUIS FRANCO almost 10 years
    I think it has to do with how Linux enumerates PCI devices... I think when you have different slots or different pci devices plugged in different combinations, the linux kernel numbers them differently.... thats just my guess. So if you have a fixed configuration, you could probably pull it off but now when the devices are changing.. @garthTheRed