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.
7 Answers
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
-
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.– ygorNov 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
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.
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.
-
4I did that and restarted both VMs but they were still assigned the same IP :( Oct 8, 2013 at 14:39
-
-
I updated my answer to address the issues you wrote about in the comments.– tbenz9Oct 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!– tbenz9Oct 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?– BenKoshyOct 19 at 9:30
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.
-
1
-
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...– kebsMar 13 at 9:41
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.
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.
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
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
ifconfig -a
, it showed the same MAC address for both (displayed asHWaddr
)Clone