Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Renaming network devices
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Kresp
Tux's lil' helper
Tux's lil' helper


Joined: 17 Oct 2016
Posts: 77

PostPosted: Sun Sep 10, 2017 12:18 am    Post subject: [SOLVED] Renaming network devices Reply with quote

I can not for the life of me figure out how to rename network devices.

I add new rule to /etc/udev/rules.d/, with something like this:
Code:

SUBSYSTEM=="net", ATTR{device}=="0x1539", NAME="eth4"

But it gets completely ignored.
I tried adding net.ifnames=0 to command line too.
I tried matching by DRIVER=="igb", ATTR{device}, ATTR{vendor}, ATTRS{PCI_ID} and card's MAC address. The file with rules reads ok - udev would complain if a rule is malformed. But interface still stays named "eth0" or "enp30s0".
Also, tried both "pci" and "net" subsystems.

All I see in dmesg is interface being added as eth0, then renamed to enp30s0 (or not, if net.ifnames is off) and that's it. My rule does not seem to fire.

Code:

$ sudo udevadm info /sys/bus/pci/drivers/igb/0000\:1e\:00.0
P: /devices/pci0000:00/0000:00:01.3/0000:03:00.2/0000:04:00.0/0000:1e:00.0
E: DEVPATH=/devices/pci0000:00/0000:00:01.3/0000:03:00.2/0000:04:00.0/0000:1e:00.0
E: DRIVER=igb
E: ID_MODEL_FROM_DATABASE=I211 Gigabit Network Connection
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Intel Corporation
E: MODALIAS=pci:v00008086d00001539sv00001462sd00007A31bc02sc00i00
E: PCI_CLASS=20000
E: PCI_ID=8086:1539
E: PCI_SLOT_NAME=0000:1e:00.0
E: PCI_SUBSYS_ID=1462:7A31
E: SUBSYSTEM=pci
E: USEC_INITIALIZED=6425650


Last edited by Kresp on Sun Sep 10, 2017 12:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
sandbox95
n00b
n00b


Joined: 06 Sep 2017
Posts: 7

PostPosted: Sun Sep 10, 2017 2:27 am    Post subject: Reply with quote

I've had luck with the following ~ single generic NIC < adapt as needed:

Code:
#
# /etc/udev/rules.d/60-net.rules
#

SUBSYSTEM=="net", \
ACTION=="add", \
DRIVERS=="?*", \
ATTR{address}=="*", \
ATTR{dev_id}=="0x0", \
ATTR{type}=="1", \
KERNEL=="eth*", \
NAME="eth0"


Last edited by sandbox95 on Sun Sep 10, 2017 10:15 am; edited 1 time in total
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Sun Sep 10, 2017 7:59 am    Post subject: Re: Renaming network devices Reply with quote

Kresp wrote:
All I see in dmesg is interface being added as eth0, then renamed to enp30s0

According to the eudev wiki article, the renaming comes from /lib/udev/rules.d/80-net-name-slot.rules
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54234
Location: 56N 3W

PostPosted: Sun Sep 10, 2017 10:13 am    Post subject: Reply with quote

Kresp,

Do not rename network interfaces to the names used by the kernel.
It appears to be harmless most of the time but horrible hard to diagnose things happen when you get a name collision.
The kernel has no knowledge of the names in use, only the next name it wants to use.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Kresp
Tux's lil' helper
Tux's lil' helper


Joined: 17 Oct 2016
Posts: 77

PostPosted: Sun Sep 10, 2017 12:24 pm    Post subject: Reply with quote

After inspecting output of udevadm info /sys/class/net/enp30s0 --attribute-walk it turned out, it's not the same as /sys/bus/pci/drivers/igb/0000\:1e\:00.0 .
The latter is PCI device with DRIVER=="igb" and the former is in "net" subsystem with DRIVER=="".
That's why it was not matching by driver name.

I ended up with this rule, matching by MAC address, it works now:
Code:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="xx:xx:xx:xx:xx:xx", NAME="internal"


Thanks, guys!
Back to top
View user's profile Send private message
chiefbag
Guru
Guru


Joined: 01 Oct 2010
Posts: 542
Location: The Kingdom

PostPosted: Mon Sep 18, 2017 10:51 am    Post subject: Reply with quote

Quote:
Do not rename network interfaces to the names used by the kernel.


@NeddySeagoon

Would it not be acceptable to use the likes of "eth0" on new systems as there would be no chance of a clash considering the kernel now uses the new naming convention eg. "enp0s3"?

--EDIT--

To answer my own question, maybe not if one was using the following option

Code:
GRUB_CMDLINE_LINUX="net.ifnames=0"
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54234
Location: 56N 3W

PostPosted: Mon Sep 18, 2017 11:50 am    Post subject: Reply with quote

chiefbag,

My kernels still use the ethX names. Are you sure something isn't doing renaming?

I have a static /dev here, so no udev and friends to mess things up.
I don't even have the net.ifnames=0 on my kernel command line as its not needed.

However, whatever the kernel uses, the name sequence needs to be avoided.

Try a
Code:
dmesg | grep eth0
on your system
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
chiefbag
Guru
Guru


Joined: 01 Oct 2010
Posts: 542
Location: The Kingdom

PostPosted: Mon Sep 18, 2017 1:23 pm    Post subject: Reply with quote

I have 2 cards installed on the machine at the moment, below is the dmesg and other info.

Code:
[    5.693996] 8139too 0000:05:01.0 eth0: RealTek RTL8139 at 0xffffc90000080000, 00:0e:2e:XX:XX:XX, IRQ 17
[    5.713980] 8139too 0000:05:01.0 eth1: renamed from eth0
[    5.997827] e1000e 0000:00:19.0 eth0: registered PHC clock
[    5.997830] e1000e 0000:00:19.0 eth0: (PCI Express:2.5GT/s:Width x1) c8:60:00:XX:XX:XX
[    5.997832] e1000e 0000:00:19.0 eth0: Intel(R) PRO/1000 Network Connection
[    5.997876] e1000e 0000:00:19.0 eth0: MAC: 10, PHY: 11, PBA No: FFFFFF-0FF
[    6.572292] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[    9.371094] e1000e: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
[    9.371127] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready



Code:
cat /etc/udev/rules.d/70-net-name-use-custom.rules
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="c8:60:00:XX:XX:XX", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:0e:2e:XX:XX:XX", NAME="eth1"



Code:
eix -I udev | grep "\["
[I] sys-fs/eudev
[U] sys-fs/udev-init-scripts
[U] virtual/libudev
[U] virtual/udev



Code:
cat /etc/default/grub | grep GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX="real_root=/dev/sda4 net.ifnames=0 rootfstype=ext4"
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54234
Location: 56N 3W

PostPosted: Mon Sep 18, 2017 1:40 pm    Post subject: Reply with quote

chiefbag,

I was expecting some enp* names

Swapping network interface names as you appear to do has not been supported by udev for several years.
Your /etc/udev/rules.d/70-net-name-use-custom.rules is how gentoo fixed network device names long time ago.
It was safe with udev support for changing names in the kernels namespace.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
chiefbag
Guru
Guru


Joined: 01 Oct 2010
Posts: 542
Location: The Kingdom

PostPosted: Mon Sep 18, 2017 2:07 pm    Post subject: Reply with quote

Quote:
Your /etc/udev/rules.d/70-net-name-use-custom.rules is how gentoo fixed network device names long time ago.


The rule matching still seems to work with eudev though, but I don't see it referenced in the eudev Gentoo Wiki page?

EUDEV
https://wiki.gentoo.org/wiki/Eudev#Keep_classic_.27eth0.27_naming

UDEV
https://wiki.gentoo.org/wiki/Udev#Persistent_device_names



Code:
[    5.693996] 8139too 0000:05:01.0 eth0: RealTek RTL8139 at 0xffffc90000080000, 00:0e:2e:XX:XX:XX, IRQ 17
[    5.713980] 8139too 0000:05:01.0 eth1: renamed from eth0
Back to top
View user's profile Send private message
donjames
Apprentice
Apprentice


Joined: 19 Dec 2004
Posts: 251
Location: 32°9'50" N 94°50'54" W

PostPosted: Thu Sep 03, 2020 4:19 am    Post subject: renaming network devices Reply with quote

Kresp wrote:
After inspecting output of udevadm info /sys/class/net/enp30s0 --attribute-walk it turned out, it's not the same as /sys/bus/pci/drivers/igb/0000\:1e\:00.0 .
The latter is PCI device with DRIVER=="igb" and the former is in "net" subsystem with DRIVER=="".
That's why it was not matching by driver name.

I ended up with this rule, matching by MAC address, it works now:
Code:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="xx:xx:xx:xx:xx:xx", NAME="internal"


Thanks, guys!


Hi,
Where was
Code:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="xx:xx:xx:xx:xx:xx", NAME="internal"

entered?

Thanks,
donjames
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum