LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2011, 12:10 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,689
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
correcting udev network persistent-net rules


I have been using the following to maintain consistency with udev across MAC address changes (e.g. swapping out NIC cards, etc). By default, udev builds rules the first time to associate an interface name with a MAC address, which works fine until the NIC cards are changed, or the system disk is moved to another box that has different MAC addresses (e.g. even in the motherboard):

Code:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth0", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth1", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth2", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth3", NAME="eth3"
The problem with the above "solution" is it will not attempt to correct a different probe order when that happens during kernel initialization. I've never seen such a thing happen with multiple port NIC cards (like motherboards with 2 or 4 ports). But I'm now working with some machines which have 1 NIC on the motherboard and a dual port card plugged in with a different driver. Sometimes the interfaces come up differently.

So I really do need to implement something that makes things consistent. But the MAC address simply cannot do this because it is too volatile (e.g. it can change with NIC cards or motherboard is changed).

The idea I have is to use the BUS address. In the /sys/devices tree this is known as "device". I could code udev rules to match specific devices to specific interfaces. Still there is a problem with mass deployment in that these device bus addresses are not the same on different machines. I do want the setup to be the same. So merely coding specific device addresses and interface names in a udev rule would not accomplish it universally (e.g. each machine might need a different one).

Potentially I could have my own script generate such a configuration for a specific machine. But my question right now is, is there a way to just tell udev to do what it does, but instead of basing the association it stores on the MAC address, base it instead on the BUS device address.

So instead of ending up with /etc/udev/rules.d/70-persistent-net.rules having:
Code:
# This file maintains persistent names for network interfaces.
# See udev(7) for syntax.
#
# Entries are automatically added by the 75-persistent-net-generator.rules
# file; however you are also free to add your own entries.

# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:14:c4:58", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:14:c4:59", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
I would get something that had "ATTR{device}" instead of "ATTR{address}". If udev can do this (somehow), that would be the "right way" I think. But if not, I guess I would have to generate these myself (probably scripted after testing a couple of them).
 
Old 09-19-2011, 02:54 PM   #2
cendryon
Member
 
Registered: Aug 2005
Location: France
Distribution: Slackware64 current
Posts: 82

Rep: Reputation: 30
Hi

You can try DEVPATH instead of ATTR{address}
Code:
# ls -l /sys/class/net/
lrwxrwxrwx 1 root root 0 sept. 19 21:41 /sys/class/net/eth0 -> ../../devices/pci0000:00/0000:00:19.0/net/eth0/
lrwxrwxrwx 1 root root 0 sept. 19 21:41 /sys/class/net/eth1 -> ../../devices/pci0000:00/0000:00:1c.7/0000:05:00.0/0000:06:09.0/0000:0e:00.0/net/eth1/
lrwxrwxrwx 1 root root 0 sept. 19 21:41 /sys/class/net/lo -> ../../devices/virtual/net/lo/
Then your DEVPATH conditions would be
Code:
DEVPATH="/devices/pci0000:00/0000:00:19.0/*"
DEVPATH="/devices/pci0000:00/0000:00:1c.7/0000:05:00.0/0000:06:09.0/0000:0e:00.0/*"
This would only work if in each machine the bus (00: or 0e: ), slot (:19 or :00) and maybe function (.0) in the output of lspci is the same, as is it the last part of the devpath
Code:
# lspci | grep Ethernet
00:19.0 Ethernet controller: Intel Corporation 82579V Gigabit Network Connection (rev 05)
0e:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)
Cheers
 
Old 09-19-2011, 04:11 PM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,689

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
I've gone with the approach of having a script scan /sys/devices and look for NICs in bus address order. It generates a udev rules file with interface names numbered according to that order.

That script is in this thread: http://www.linuxquestions.org/questi...-rules-903234/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reset/remove udev persistent-net-rules cccc Debian 3 06-29-2012 11:46 AM
Slack 13.1 : /etc/udev/rules.d70-persistent-net.rules Ramurd Slackware 10 02-18-2011 09:56 AM
Slackware 13 Network Problem, Odd Problem With 70-persistent net.rules pghsteel Slackware 4 08-16-2010 03:58 AM
70-persistent-net.rules DebianUser Linux - Networking 1 08-07-2010 07:09 AM
cat: /etc/udev/rules.d/70-persistent-net.rules: No such file or directory rcg1984 Linux From Scratch 2 09-17-2008 07:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration