54

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
  • 71,754
zerkms
  • 1,472
  • How did you change eth1 to eth0? Did you just rename the device file? If so, that's not an effective way to do it (and you should expect the change to be reverted by a successful restart of the udev daemon). If you used some other method, please describe it in detail, and please also give the complete and exact text of any error messages you're seeing when you run the commands you've tried (for restarting the udev daemon or reloading its rules). You can edit your question to provide this information. – Eliah Kagan Nov 25 '11 at 01:11
  • @Eliah Kagan: updated. ps: why should it be reverted? It shouldn't ;-) – zerkms Nov 25 '11 at 01:13
  • udev dynamically generates your devices in /dev. If you restart it, it will regenerate them according to its rules. Changes made directly to them are not, generally speaking, persistent. It looks like restarting udev is working fine, but that you just haven't properly changed the device names. – Eliah Kagan Nov 25 '11 at 01:15
  • @Eliah Kagan: udev only adds (not modifies) new rules if it cannot find the one for particular device. If there is a rule that matches - it just follows it without modifications. – zerkms Nov 25 '11 at 01:17
  • @Eliah Kagan: and I changed it properly. Just believe I do can change one char in a line ;-) (also reboot helpes, and this proves that everything is fine with rules) – zerkms Nov 25 '11 at 01:19
  • And you're saying you think that a manually created or modified entry in the /dev filesystem has an instant, automatically created rule in /lib/udev/rules.d (as a file or an entry in an existing file) matching it? I have never heard of such behavior. Is that working for you? – Eliah Kagan Nov 25 '11 at 01:25
  • @Eliah Kagan: nono, I don't modify dev-fs manually. But restarting udev (any of proposed solutions) doesn't change /dev-fs, at least on my ubuntu box – zerkms Nov 25 '11 at 01:27
  • Ah, OK. I see what you're saying. So, to verify that you cannot make the change happen without rebooting, are you reverting the change and then rebooting and then attempting to make it again without rebooting (since you said that you have already rebooted and that did help)? – Eliah Kagan Nov 25 '11 at 01:29
  • @Eliah Kagan: added an explanation of my whole case, hope it will help to get the idea why I got in stuck – zerkms Nov 25 '11 at 01:35

10 Answers10

35

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
  • 580
  • 4
    I believe sudo udevadm trigger --action=change is safer, as per this email about what's safe and not safe to do about udev: https://lists.ubuntu.com/archives/ubuntu-devel/2009-January/027260.html – Ehtesh Choudhury Mar 11 '13 at 19:14
  • Indeed, and it's called /etc/udev/rules.d/70-persistent-net.rules – msanford Mar 06 '15 at 01:10
  • Under Ubuntu 15.04 udevadm trigger locked up my X11 session and threw me back to my login screen. – Ian D. Allen Jul 21 '15 at 17:15
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.

  • 1
    Ubuntu 15.04 with all devices listed in /etc/network/interfaces (so Network Manager leaves them alone): All I needed to do was edit /etc/udev/rules.d/70-persistent-net.rules then do #2, #3, #5. No need to stop all networking; no need for anything else. – Ian D. Allen Jul 21 '15 at 18:13
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!

5

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
  • 117,780
3

This should do it safely:

sudo reload udev

As I have used this command with no issues.

Basharat Sialvi
  • 24,046
  • 8
  • 62
  • 82
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,117
  • 10
  • 38
  • 46
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
  • 1
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
  • 70,465
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.