# [SOLVED] Renaming network devices

## Kresp

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:

```

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.

```

$ 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

----------

## sandbox95

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

```
#

# /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

----------

## charles17

 *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

----------

## NeddySeagoon

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.

----------

## Kresp

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:

```

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

```

Thanks, guys!

----------

## chiefbag

 *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

```
GRUB_CMDLINE_LINUX="net.ifnames=0"
```

----------

## NeddySeagoon

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 

```
dmesg | grep eth0
```

 on your system

----------

## chiefbag

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

```
[    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
```

```
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"
```

```
eix -I udev | grep "\["

[I] sys-fs/eudev

[U] sys-fs/udev-init-scripts

[U] virtual/libudev

[U] virtual/udev
```

```
cat /etc/default/grub | grep GRUB_CMDLINE_LINUX

GRUB_CMDLINE_LINUX="real_root=/dev/sda4 net.ifnames=0 rootfstype=ext4"
```

----------

## NeddySeagoon

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.

----------

## chiefbag

 *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

```
[    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
```

----------

## donjames

 *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.
> ...

 

Hi,

Where was 

```

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

```

entered?

Thanks,

donjames

----------

