27

I've set up a virtual machine configured with bridge networking. After making eight clones of it, the new machines can't connect to the network.

I've instructed VirtualBox to re-generate the machines' mac-addresses.

8 Answers 8

26

There are udev rules preventing the new interface from being brought up.

In the Master machine, just delete them before you clone the new machines:

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules

(source)

3
  • The 70-persistent-net.rules comes up in next boot of master machine and cloned vms. Did you face that problem?
    – Manish
    Aug 15, 2012 at 18:56
  • Deleting a file makes the force -f flag unnecessary.
    – k0pernikus
    Aug 6, 2014 at 11:13
  • The -f flag makes the rm command succeed with a status 0 even if the file doesn't exist. Force of habit. :) Aug 8, 2014 at 15:15
6

Refresh your MAC address using Virtual Box machine settings and remove the kernel’s networking interface rules file so that it can be regenerated:

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
sudo reboot

It will work for your clone VM.

3
  • 1
    Personally, I would copy the rules file somewhere rather than just deleting it outright, just in case you need to restore it. Jan 8, 2014 at 9:03
  • this worked for me!
    – lofidevops
    Feb 17, 2014 at 18:06
  • @DavidEdwards If not present, the file is created by the OS during startup. If you really need the old copy (the one with the wrong MAC address,) you could always retrieve it from the original VM. Apr 9, 2014 at 20:13
6

I was dealing with the same problem for months and today I decided I would find a better fix. Here is what I did on the machine I was using as a Template.

For good administration practices back up both files before editing.

You have two offending/target files:

  1. /etc/sysconfig/network-scripts/ifcfg-eth0
  2. /etc/udev/rules.d/70-persistent-net.rules

This will work for a static or dhcp address:

Open /etc/sysconfig/network-scripts/ifcfg-eth0

Delete the MAC Address line: HWADDR=XX:11:22:XX:33:XX
Save the file.

Delete the file /etc/udev/rules.d/70-persistent-net.rules "it will be recreated after you restart the VM"

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules

You can now clone your box and every clone will correctly deploy and display eth0.

If you do not use a template, you may complete these procedures on the actual VM just remember to re-initialize the NIC your in the VM software before you restart the machine.

3
  • This looks like a more complete answer. Can you provide more specifics on the "re-initialize the NIC" part in last paragraph? Also which VirtualBox version were you using?
    – RichVel
    Apr 14, 2016 at 5:11
  • Just as a note, I can't find the /etc/sysconfig directory in Ubuntu 16.04.
    – MakisH
    Oct 19, 2016 at 12:49
  • 1
    @MakisH network interfaces in Debian/Ubuntu are not defined by files in /etc/sysconfig/network-scripts (as you have noticed, there isn't even a /etc/sysconfig directory), but by /etc/network/interfaces . Jan 31, 2018 at 15:18
1

I encountered the same problem on a previous version of VirtualBox and I read somewhere that there was a bug which rendered the "generate new MAC address" tick box useless.

I'm now using Ubuntu 12.04 with VirtualBox 4.2.10. I noticed now that when I created the clone, there was no tick box to "generate new MAC address."

This gave me some problems even if I deleted 70-persistent-net.rules because the system would automatically generate the file on startup with the same MAC address as the original, which made it fail to connect.

But I discovered that in VirtualBox Manager, you can select the clone, go to Settings>Networking>Advanced and generate a new MAC address by ticking the box.

So what I did was to delete 70-persistent-net.rules first, shut down, generate new MAC address and start again, and now it works.

Alternatively, you can delete the file first before you clone. Then generate MAC address, then start the clone. That ought to work as well.

0

I am building parallel computing environment that needs interconnection between the virtual machine through ip network.

I think there is something related to the re-generate the machines' mac-addresses. I had faced the similar problem before.

The original virtual machine has eth0 and eth1. But due to the regenerating process, in my case, the new cloned machine has eth2 and eth3. you can check it by this following command:

ifconfig -a | grep eth

You can check with ifconfig command that in the new cloned machine has only lo registered. Generally, you should have lo, eth0, and eth1 when you type ifconfig command.

That is due to MAC regeneration that in the clone machine, there are eth2 and eth3 Ethernet interfaces instead of eth0 and eth1 in the original machine. You can also check the /etc/network/interfaces in the original machine that in my case will appears like:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static

address 192.168.xxx.xxx
netmask 255.xxx.xxx.0
network 192.168.xxx.0
broadcast 192.168.xxx.255
gateway 10.0.x.xx

May be you can modify your /etc/network/interfaces file and change the eth0 and eth1 with eth2 and eth3, which more or less like this:

auto lo
iface lo inet loopback

auto eth2
iface eth2 inet dhcp

auto eth3
iface eth3 inet static

address 192.168.xxx.xxx
netmask 255.xxx.xxx.0
network 192.168.xxx.0
broadcast 192.168.xxx.255
gateway 10.0.x.xx

So, good luck guys!

0

I deleted 70-persitent-net.rules file but it wasn't re-created after reboot. Then, re-installing guest additions module and rebooting the VM worked for me.

0

I have problem with same ip-address after cloning 3 VMs with Virtual BOX (4.3). SO I have power off the machines and regenerated new mac address and restarted it worked for me.

steps => switch off the cloned VM and then settings => network => advanced => click on refresh MAC address => clik OK. then start VM.

0

I was facing the same issue after cloning ubuntu-server-20.x image. I was using nat-service. What worked for me was the following.

  1. Refresh the mac by going to network setting (small refresh icon next to mac address).
  2. On guest machine, run the following two commands to force refresh ip address from DHCP server.
sudo dhclient -r eth0
sudo dhclient eth0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .