56

I've changed the name of my eth1 interface to eth0. How to ask udev now to re-read the config?

service udev restart

and

udevadm control --reload-rules

don't help. So is there any valid way except of rebooting? (yes, reboot helps with this issue)

  • yes, I know I should prepend the commands with sudo, but either one I posted above changes nothing in ifconfig -a output: I still see eth1, not eth0.

  • I just changed the NAME property of udev-rule line. Don't know any reason for this to be ineffective.

There is no any error in executing of both commands I've posted above, but they just don't change actual interface name in ifconfig -a output. If I perform reboot - then interface name changes as expected.

For development purposes I write some script that clones virtual machines (VirtualBox-driven) and pre-sets them up in some way.

So I perform a command to clone VM, start it and as long as network interface MAC is changed - udev adds the second rule to network persistent rules. Right after machine is booted for the first time there are 2 rules:

  • eth0, which does not exist, as long as it existed in the original VM image MAC
  • eth1, which exists, but all the configuration in all files refers to eth0, so it is not that good for me

So I with sed delete the line with eth0 (it is obsolete and useless in cloned image) and replace eth1 with eth0. So currently I have valid persistent rule, but there is still eth1 in /dev.

The issue: I don't want to reboot the machine (it will take another time, which is not good thing on building-VM-stage) and just want to have my /dev rebuilt with some command so I have ready-to-use VM without any reboots.

Jorge Castro
  • 73,717
zerkms
  • 1,502

10 Answers10

36

I don't know if this helps in reloading the network configuration, but when I modified /etc/udev/rules.d/70-persistent-cd.rules to correct the DVD device link from /dev/dvd1 to /dev/dvd, I had to run

sudo udevadm trigger

to get have the new links created.

akaihola
  • 590
22

You have to combine all the advice given here in the right order:

  1. Bring down the network service networking stop
  2. Unload the driver module from the kernel
    1. Find the name of the module lspci -v and look for "Kernel driver in use:"
    2. modprobe -r <driver module>
  3. Reload the udev rules udevadm control --reload-rules
  4. Trigger the new rules udevadm trigger
  5. Load driver modprobe <driver module>
  6. Restart the network service networking start
  7. (optional) Re-run any iptables scripts that referenced the eth interface name before it was up.

I suspect either step 4 or step 5 isn't really needed, but these steps worked for me. You could check after step 4 with step 2.1 to see if the trigger command already did step 5, edit this answer to reflect your findings if you do.

6

I had a similar problem. Since I didn't want to take the time to reboot, I ran a one liner using Chris Wesseling's suggestion.

/etc/init.d/networking stop && modprobe -r tg3 && udevadm control --reload-rules && udevadm trigger && modprobe tg3 && /etc/init.d/networking start

This worked for me using Ubuntu 12.04.02 server. My nics were using the tg3 kernel module driver, so change tg3 to the module your interfaces are using. I found the ones mine used in /etc/udev/rules.d/70-persistent-net.rules:

PCI device 0x14e4:/sys/devices/pci0000:00/0000:00:1c.4/0000:02:00.1 (tg3) <-kernel module driver for the nic

The one issue I had was a bad route which I fixed with a simple route add command. Thanks for the help Chris!

6

This worked for me (without rebooting)

udevadm control --reload-rules ; udevadm trigger

Kudos to the author of this page: http://memoryfail.wordpress.com/2013/04/02/renaming-network-device-names/

3

sudo /etc/init.d/udev restart should do the trick. Some of the commands you had tried, if run with sudo, might be effective as well.

Eliah Kagan
  • 119,640
3

This should do it safely:

sudo reload udev

As I have used this command with no issues.

rdh
  • 866
1

You need to reload udev to trigger the rule change, but the device won't be renamed unless you unload/reload the driver module.

So modprobe -r e1000 && modprobe e1000 after udev reload should do the trick. Of course, don't do that if you need the network and have only e1000 interfaces.

Peachy
  • 7,235
  • 10
  • 40
  • 47
nodens
  • 11
1

I've been researching this for a while with pretty much the same purpose, and I haven't been able to find a way to change the network interface name in a live system.

The workaround I have gone for is to delete the /etc/udev/rules.d/70-persistent-net.rules file in the template, which means that on the next boot it will see any network card as eth0.

Merlijn
  • 11
0

I followed the instructions in this guide: How to regenerate the /etc/udev/rules.d/70-persistent-net.rules file on Debian/Ubuntu

The solution consists in using the command:

udevadm trigger

that regenerates the /etc/udev/rules.d/70-persistent-net.rules file.

Zanna
  • 72,312
0

So for me on VirtualBox with Ubuntu 12.04, I often switch between ethernet and wireless.

So when my connection changes, I must choose the Bridged Adapter from Devices > Network Settings. Either 'Intel 82579LM Gigabit Network Connection' or 'Intel Centrino Ultimate-N 6300 AGN'.

After doing this, I can run

sudo modprobe -r e1000
sudo service udev restart
sudo modprobe e1000
ping google.com # To test I ran this between each command.

This is just an explanation of my results after reading all the answers above.