11

I had one VM in my VirtualBox and wanted to use it as a template/image so I cloned it. Then I launched both the original and the clone simultaneously (to simulate a server cluster for something I was working on), however, both instances were assigned the same IP address. Is this perhaps a bug in our DHCP, which I think VirtualBox uses to get IP addresses? Or perhaps something in the way I set up my VMs? Anyway, I am ultimately interested in resolving this issue so that I can two VMs of the same image concurrently.

5
  • On VMWare, if you started a previously used VM from a different path, it asked if you copied it or moved the VM to be able to avoid such situations... How did you clone the VM?
    – ppeterka
    Oct 7, 2013 at 20:51
  • i'm afraid this is not the situation here...
    – amphibient
    Oct 7, 2013 at 20:52
  • 1
    It is possible that you copied the machine with the MAC (Ethernet) address. That is one of differences between copying and moving in VMware as mentioned by ppeterka. Could you please check the addresses? Could you also please describe how exactly did you clone the machine? Oct 7, 2013 at 21:12
  • yes, when i ran ifconfig -a, it showed the same MAC address for both (displayed as HWaddr)
    – amphibient
    Oct 7, 2013 at 21:34
  • but the way i cloned it was in UI, just right-clicked the VM and hit Clone
    – amphibient
    Oct 7, 2013 at 21:36

7 Answers 7

16

You may also need to change the machine-id:

Works on Ubuntu (Guest VM):

sudo rm -f /etc/machine-id
sudo dbus-uuidgen --ensure=/etc/machine-id
sudo rm /var/lib/dbus/machine-id
sudo dbus-uuidgen --ensure
reboot

You can also try this parameter in the Ubuntu netplan configuration file:

      dhcp4: yes
      dhcp-identifier: mac
2
  • dhcp-identifier: mac solved the issue for me. My issue was: I cloned Ubuntu 20.10 image, regenerated MAC address, but still got the same Host-Only Adapter IP address assigned.
    – ygor
    Nov 16, 2021 at 8:45
  • 1
    machine-id trick worked for me. dbus-uuidgen should be done in guests, not in the host. I'm running Virtual Box v6.1.32 on Ubuntu 21.04. Jan 26, 2022 at 2:39
13

This is known as an IP conflict and can cause major headaches on the network.

You can re-initialize the MAC address of the cloned VM; that just means generate a new random one. On your cloned VM click Settings >> Network >> Advanced then click the two circular arrows to generate a new MAC. Your VM will need to be off. When it boots your DHCP server should assign the VM a different IP address.

Also FYI, when you cloned your VM you should have seen a checkbox with the words "reinitialize MAC", that would have cloned the VM and generated a new MAC instead of cloning it.

If you were curious, cloning a VM is often used to make a full backup of the VM, in this case you would want the MAC and IP to be the same in case you had to use the backup. For your case of cloning the VM to build a cluster you'll want to re-initialize the MAC on every clone.enter image description here

Update 1 In response to your comments from 10/8/2013.

Make sure the IP address is not statically set. You mentioned in your question that the VM should be getting it's IP from DHCP. If thats the case the config should look something like the following. For debian based systems it will be found at /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

For redhat based systems the networking configuration is at /etc/sysconfig/network-scripts/ifcfg-eth0

Your second comment mentioned that eth0 is missing. Do you have an eth1? Since your computer changed mac addresses, the OS keeps the original mac as eth0 and usually assigns eth1 to the new mac. To reset the eth* devices so you have an eth0 and not an eth1 you'll need to clear the udev networking rules.

Messing with networking can get hairy. One option would be to delete your cloned VM and clone the original again and check "reinitialize mac". I'm not certain it will fix your problem but it might.

5
  • 4
    I did that and restarted both VMs but they were still assigned the same IP :(
    – amphibient
    Oct 8, 2013 at 14:39
  • the clone does not have eth0 when i run ifconfig
    – amphibient
    Oct 8, 2013 at 14:42
  • I updated my answer to address the issues you wrote about in the comments.
    – tbenz9
    Oct 9, 2013 at 18:09
  • @amphibient, I re-created your problem and was able to solve it easily by deleting everything out of the /etc/udev/rules.d/70-persistent-net.rules file and rebooting. Good luck!
    – tbenz9
    Oct 10, 2013 at 4:58
  • thx for your answer - out of curiosity, if you had two VM clones with the same IP, is there a way of differentiating them in some way?
    – BenKoshy
    Oct 19, 2023 at 9:30
3

I got the same IP 10.0.2.15 VM's when I cloned Ubuntu on Mac.
To solve the issue I first shutdown the VM's.
Then for each VM
I select settings, then click Network tab, then changed attached to: Bridged Adapter
then I click advanced, select allow all for promiscuous mode,
finally refresh the MAC address to change the MAC address. Click Ok.
Now Start the VM's and you will get the different IP addresses.
I got 192.168.0.14 for first and 192.168.0.15 for second. They were pingable from host Mac too.

enter image description here

3
  • 1
    Thanks, this worked perfectly.
    – Raj
    Nov 10, 2021 at 10:22
  • For some reason, this gives me only IPv6 adresses for the two hosts, but no IPv4. VB DHCP seems to be disabled when doing this...
    – kebs
    Mar 13, 2023 at 9:41
  • 2023 This one worked rest all refresh and other things did not work
    – silentsudo
    Jan 7 at 5:45
0

Please read about available adapters in VirtualBox (https://www.virtualbox.org/manual/ch06.html#networkingmodes). If you want connection just between VMs then for your tests will be more suitable Internal Network adapter. However from you comment I get that you are using NAT.

I checked below scenario on VirtualBox 5.0.2 on host Mint 17.2 and guests Fedora 21:

Create main VM with default NAT adapter. Create Linked clone (https://www.virtualbox.org/manual/ch01.html#clone) with MACs reinitialization. Cloned and original VM have same values in file:

/etc/sysconfig/network-scripts/ifcfg-enp0s3

however

ip a

shows different MAC addresses on each one.

When I updated HWADDR in that file according to link/ether value from ip command and changed UUID with new one using

uuidgen

then despite the same IP on these (enp0s3) interfaces on original and cloned VMs, external network (Internet) was working well.

0

I came across this same situation today. I was using a NAT adapter and a Host-only Ethernet Adapter for my Solaris VM. The IP of the clone changed when I refreshed the Host-Only adapter's mac address.

0

I solve this problem by running this:

sudo su
echo -n > /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id
-3

I understand your pain. I cloned my vm. Generated new Mac on oracle virtual box, Booted clone up, changed hostname and updated the network-scripts file with new mac.

When rebooted, it still used same ip from dhcp. Interface is on Nat setting.

:(

Dave

1
  • 1
    Kind and friendly but not an answer to the question. Jan 17, 2019 at 16:03

You must log in to answer this question.

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