Assign new IP address when cloning a snapshot with VirtualBox

This is for discussing general topics about how to use VirtualBox.
Post Reply
Phoebus
Posts: 4
Joined: 22. Dec 2016, 00:13

Assign new IP address when cloning a snapshot with VirtualBox

Post by Phoebus »

Hi,

I am cloning a snapshot of a VM (android emulator) and get its IP address in the following way:

vboxmanage clonevm <uuid> --snapshot <suid> --name my_clone --register
vboxmanage startvm my_clone
vboxmanage guestproperty get my_clone androvm_ip_management
Value: 192.168.56.101
This yields me the same ip address as the snapshot. If I power it off and start it again though, another IP address in the subnet work range is assigned (that is what I want to happen).

vboxmanage controlvm my_clone poweroff
vboxmanage startvm my_clone
vboxmanage guestproperty get my_clone androvm_ip_management
Value: 192.168.56.102

Can I achieve to assign a new IP address to the clone right away without the need of restarting it?

The original VM has 2 network adapters, one host-only and one NAT adapter.

Thanks in advance
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by socratis »

The IP assignment is something that is done at the OS (software) level, not at the hardware (VirtualBox) level. You cannot do it from VirtualBox, as much as you can't have your Dell/HP/Acer/Mac assign an IP from the BIOS.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Phoebus
Posts: 4
Joined: 22. Dec 2016, 00:13

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by Phoebus »

Thank you for your response.

I understand that. My goal is not to assign a certain IP address to the emulator, merely to have one that differs from the snapshot.
I figured out that if I issue the following command between cloning and starting, the clone has indeed a different IP address assigned, however the launching of the vm takes much longer.

vboxmanage modifyvm my_clone --nic2 nat

However, this faces me with another problem - can I wait via vboxmanage until the vm is completely loaded?
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by mpack »

You need to change the clone's MAC address, that should force the clone to be assigned a different IP by the DHCP server.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by socratis »

If you do not specifically state that you want the same MAC addresses (-- options keepallmacs|keepnatmacs), they are reinitialized by default. Ch.8.9: VBoxManage clonevm.

But, I'm not quite sure what Phoebus means when they talk about:
Phoebus wrote:This yields me the same ip address as the snapshot. If I power it off and start it again though, another IP address in the subnet work range is assigned (that is what I want to happen).
As opposed to what? The only scenario that I can see this happening is if the OP is cloning the VM while in SavedState. Ouch. In that scenario of course the MAC addresses will not be reinitialized. You can't change the hardware on the fly. Expect a turbulent flight ahead...

Phoebus, can you describe step-by-step the cloning process? Also, can you explain the following?
Phoebus wrote:vboxmanage guestproperty get my_clone androvm_ip_management
There is no such guest property that I know of in VirtualBox. Where did that come from?
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Phoebus
Posts: 4
Joined: 22. Dec 2016, 00:13

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by Phoebus »

I clone a snapshot of the VM, so I guess it is indeed in a saved state. That probably explains why it has the same IP address and why it changes after rebooting. I wanted to clone a snapshot so that it boots up fast for the user after cloning since it otherwise takes up to two minutes. But if I want to have separate IPs for the clones I guess I cannot do it in that way.

I think androvm_ip_management property is special to Android VMs. My goal was to get the IP address of the VM and thus I enumerated all of the guestproperties and found that one.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by socratis »

Phoebus wrote:I think androvm_ip_management property is special to Android VMs.
It shouldn't. There are no special per type-of-VM properties, AFAIK.

My feeling is that you're not using VirtualBox, but a software based on VirtualBox. If not, where did you get the VM from? Having a special guest property means that there are guest additions installed. And there are no known GAs available for Android.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Phoebus
Posts: 4
Joined: 22. Dec 2016, 00:13

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by Phoebus »

I used genymotion emulation software to create the VM, but afterwards vboxmanage to further interact with it.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Assign new IP address when cloning a snapshot with VirtualBox

Post by socratis »

Thanks for clarifying that. Now, back to another problem. If you clone a VM while in saved state, the MAC address does not get reinitialized. What that means is that if you ever launch original and clone in parallel, you'll have major network problems. Avoid it. You may be saving a minute or two, but it's going to come back and bite you.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply