Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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|improve this answer
    
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? –  user1527227 Jul 11 at 18:51
    
The PCI address above contains the slot number - I've added a little explanation. –  garethTheRed Jul 11 at 21:07
    
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. –  user1527227 Jul 22 at 19:33
    
Is it the slot number or the function number (the bit after the dot) that changes? It should be the latter. –  garethTheRed Jul 22 at 19:48
    
THanks! please see updated question @garethTheRed –  user1527227 Jul 22 at 20:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.