Ask Your Question
1

udev rule unable to change interface name

asked 2013-09-11 22:57:13 -0500

Jon Miller gravatar image

updated 2013-09-12 19:52:20 -0500

FranciscoD_ gravatar image

Trying to create udev rules to establish consistent network interface names needed for software that will running on this Fedora 18 installation. I have created /etc/udev/rules.d/70-persistent-net.rules file and have added the following entries:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:17:a4:3f:87:48", PROGRAM="/root/bin/udev-debug.sh before_name=%k eth0?"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:17:a4:3f:87:48", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:17:a4:3f:87:48", PROGRAM="/root/bin/udev-debug.sh after_name=%k eth0?"

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:17:a4:3f:87:49", PROGRAM="/root/bin/udev-debug.sh before_name=%k eth1?"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:17:a4:3f:87:49", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:17:a4:3f:87:49", PROGRAM="/root/bin/udev-debug.sh after_name=%k eth1?"

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:04:23:cd:57:a1", PROGRAM="/root/bin/udev-debug.sh before_name=%k eth2?"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:04:23:cd:57:a1", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:04:23:cd:57:a1", PROGRAM="/root/bin/udev-debug.sh after_name=%k eth2?"

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:04:23:cd:57:a0", PROGRAM="/root/bin/udev-debug.sh before_name=%k eth3?"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:04:23:cd:57:a0", NAME="eth3"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:04:23:cd:57:a0", PROGRAM="/root/bin/udev-debug.sh after_name=%k eth3?"

Obviously /root/bin/udev-debug.sh is a quick script of mine which generates log output:

Called at Thu Sep 12 02:07:14 PDT 2013 with args: before_name=eth0 eth1?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: before_name=eth1 eth0?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: after_name=eth1 eth0?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: after_name=eth0 eth1?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: before_name=eth2 eth3?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: after_name=eth2 eth3?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: before_name=eth3 eth2?
Called at Thu Sep 12 02:07:14 PDT 2013 with args: after_name=eth3 eth2?

Looks like the interfaces names are being enumerated when the drivers are loaded and just never get updated despite my efforts. Here is an excerpt from dmesg:

[    9.504153] tg3.c:v3.130 (February 14, 2013)
[    9.504334] ACPI: PCI Interrupt Link [LNK1] enabled at IRQ 16
[    9.598071] tg3 0000:02:00.0 eth0: Tigon3 [partno(BCM95721) rev 4101] (PCI Express) MAC address 00:17:a4:3f:87:49
[    9.598078] tg3 0000:02:00.0 eth0: attached PHY is 5750 (10/100/1000Base-T Ethernet) (WireSpeed[1], EEE[0])
[    9.598081] tg3 0000:02:00.0 eth0: RXcsums[1] LinkChgREG[0] MIirq[0] ASF[0] TSOcap[1]
[    9.598083] tg3 ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-09-12 22:36:37 -0500

Jon Miller gravatar image

My solution, while not the prettiest, is to use "lanX" names in my udev rules. Since I can not get away from ethX names, I created a script which does the following:

for inf in $(ip link show | sed -r -n 's/^[0-9]+: (lan[0-9]*):.*/\1/p'); do
    new_inf=${inf/lan/eth}
    ip link set dev $inf down
    ip link set dev $inf name $new_inf
done

I then call this script via a systemd.service prior to the network target:

[Unit]
Description=Interface Rename
After=syslog.target
Wants=network.target
Before=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/libexec/infrename
RemainAfterExit=yes

That has the effect of assigning consistent names, as I desire, while still keeping the ethX names. It also means any ifcfg scripts can stay as-is. As I said, it's not pretty but it's working.

edit flag offensive delete link more
0

answered 2013-09-12 03:52:10 -0500

shaiton gravatar image

Could you try with the following instead? It would then be enumerated at early stage.

KERNEL=="eth*", ATTR{address}=="00:04:23:cd:57:a1", NAME="eth3"
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-09-11 22:57:13 -0500

Seen: 1,659 times

Last updated: Sep 12 '13