How to reload Ethernet udev rules without reboot
This note detail how to update udev rules for an Ethernet connection and have them take effect without rebooting the machine. The critical part is using rmmod
and modprobe
to remove and re-load the networking module for the Ethernet connection, which effectively “unplugs” and “replugs” the connection, causing the udev rules to take effect. Note that this will cause brief downtime for the specific network interface, but avoids rebooting the entire machine.
First lets run ip addr
to show the interfaces we are starting with:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33u1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff
inet 192.168.0.12/24 brd 192.168.0.255 scope global dynamic ens33u1
valid_lft 2460sec preferred_lft 2460sec
inet6 fe80::20c:29ff:fe1a:4605/64 scope link
valid_lft forever preferred_lft forever
Next we add our udev rule, which should give the Ethernet interface with the MAC address aa:bb:cc:dd:ee:ff
the interface name ethfoo
.
/etc/udev/rules.d/70-persistent-net.rules §
SUBSYSTEM=="net", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="ethfoo"
At this point, most advice online states you only need to run:
udevadm control --reload-rules
udevadm trigger
However this is not enough. It is necessary to unload and reload the module used for networking on that interface.
Examples of module names I’ve come across are:
- ixgbe
- tg3
- e1000
- asix
- vmxnet3
The easiest way to find out which modules applies to your Ethernet connection is to physically unplug the cable (or virtually remove it if running a VM) and then run dmesg | tail
to see the latest dmesg log. You should see something like this:
[11267.360808] usb 1-2: USB disconnect, device number 8
[11267.363008] asix 1-2:1.0 ens33u1: unregister 'asix' usb-0000:02:01.0-2, ASIX AX88772 USB 2.0 Ethernet
Or this:
[ 5740.147559] vmxnet3 0000:03:00.0 ens160: NIC Link is Down
[ 5747.098256] vmxnet3 0000:03:00.0 ens160: NIC Link is Up 10000 Mbps
In the first case I now know that the ens33u1
interface uses the asix
module.
To unload and reload the module I run:
rmmod asix
modprobe asix
Finally I can run ip addr
and see that the udev rules have taken effect - it is now called ethfoo
:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ethfoo: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff
inet 192.168.0.12/24 brd 192.168.0.255 scope global dynamic ethfoo
valid_lft 2460sec preferred_lft 2460sec
inet6 fe80::20c:29ff:fe1a:4605/64 scope link
valid_lft forever preferred_lft forever