Prevent Virtual Machines from Saving Network Interface udev Rules

I use a lot of VirtualBox VMs. A problem that I have frequently is that when cloning an Ubuntu VM and changing its MAC address is that it won’t be able to initialize the network (as seen in a previous post). I found a permanent fix for this!

Before you clone your VM, you can block the creation of the udev rule that remembers your MAC address/interface bindings.

sudo rm $rules && sudo mkdir $rules

That’s it! Clone away. Now that there is a directory where the udev rule is normally written, the rule won’t be written. It will just fail silently, and the bindings (e.g. MAC address 00:11:22:33:44:55 maps to eth0) will be generated dynamically upon boot. The MAC address won’t change, and the order of your interfaces won’t change, so there’s really no drawback.

This entry was posted in virtualization and tagged , , , , . Bookmark the permalink.

6 Responses to Prevent Virtual Machines from Saving Network Interface udev Rules

  1. Pingback: Clone Ubuntu VMs in VirtualBox | splat operator

  2. Elliott Hoffman says:

    You can simply delete or rename 70-persistent-net.rules prior to cloning. No need to make the directory. When your clone boots up for the first time, it will re-build the rules file with the new MAC address. The rules file is just a cache.

    • force says:

      What? No. The whole point is that you have to create the directory so that the file doesn’t get auto-generated. That’s the entire point of the hack.

      • Nicolas says:

        This is quite an old post, but from a quick read, it seems sort of like there was a misunderstanding – wasn’t Elliot just saying that you can delete the file temporarily to make the clone, but why bother preventing it from being recreated after you’ve already made the clone successfully?

        That said, I have no idea what that rules file is for, or why it even exists if it can be dynamically generated at boot – care to explain?

  3. michdev says:

    sudo rm /etc/udev/rules.d/70-persistent-net.rules
    sudo touch /etc/udev/rules.d/75-persistent-net-generator.rules

    And problem is gone forever.

  4. FFIO says:

    Thank you for your posts about this problem! The information you’ve shared saved me a bunch of time and solved my problem. I saw the comments and wanted to share what I found.

    I installed an Ubuntu 12.04 Server VM and ran through my usual process of locking things down and updating packages to make this my “master” VM to clone from. I initially made a few clones that hung when starting up networking, and your other posts helped get those going. I saw Elliot’s comment and wanted to test for myself, so on my “master” I moved 70-persistent-net.rules to 70-persistent-net.rules.BAK. I shutdown the VM, made a clone and it fired right up without issue.

    sudo mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.BAK

Leave a Reply to michdev Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>