0

I create VirtualBox guests in a LAN where IP addresses are assigned by DHCP.
If I close the VirtualBox guest and then choose Save the machine state, the VirtualBox guest Bridged-Adapter IP address is not released back to the DHCP (so that if I later start the VirtualBox guest, it'll have an IP address).

My question: if I remove (delete) the VirtualBox guest, will the IP address be released, or will it be lost to the DHCP pool?

Edit 1:

The comments I received compel me to add that when a VirtualBox guest is turned off in a save state, the IP address is kept somewhere in the VirtualBox ecosystem.
Then, if the VirtualBox guest is turned on after the DHCP has revoked the lease, then we'd have two machines on the LAN with the same IP address, to the great joy of all LAN users.

Edit 2:

From the replies, I gather that the consensus is that once the DHCP lease time is passed, regardless if there's a guest still 'holding' the IP address - the IP address will be released.
Thanks to all who took the time to reply.

7
  • 3
    As far as I know it depends on the dhcp lease time. In case the lease time is reached (e.g. 7 days) the address will be released an back in the pool. Commented Feb 27, 2019 at 23:01
  • 3
    One would imagine that the same thing happens when you take a PC and turn off, unplug it and never turn it on again.
    – Attie
    Commented Feb 27, 2019 at 23:02
  • 3
    Possible duplicate of Basic DHCP Leasing Commented Feb 27, 2019 at 23:03
  • Thanks for your comment @MarvinMcFly: please see Edit 1.
    – boardrider
    Commented Feb 27, 2019 at 23:53
  • 1
    Thanks for your comment @Attie: please see Edit 1.
    – boardrider
    Commented Feb 27, 2019 at 23:53

3 Answers 3

3

This will depend on the DHCP server lease setting. The address assigned to it will not be available for use until the DHCP lease expires, or you manually clear it on the DHCP server.

Edit:

If you have the VM offline for longer than the DHCP lease, that wont be an issue. When the VM comes online, it should update the system's time to current. At that point, the VM will see the lease is expired and make a new request to the DHCP server.

If you want to keep the IP address of a machine the same, use static IP assignments, or use DHCP reservations.

4
  • Please see Edit 1 in the OP.
    – boardrider
    Commented Feb 27, 2019 at 23:55
  • @boardrider Updated my answer
    – Keltari
    Commented Feb 28, 2019 at 1:43
  • My answer to @Andy: """ Unfortunately, [...], our experience is different: we had occasions (until we suggested to people not to stop VirtualBox guests in save state) that we found two machines with the same IP on our LAN, with the accompanying chaos. """
    – boardrider
    Commented Feb 28, 2019 at 2:10
  • 1
    The VM will only update its time if it realizes it's been suspended and resumed, which in VirtualBox requires the full "additions" package to be installed, for example. It's not a guaranteed thing that always happens on all VMs. Commented Feb 28, 2019 at 5:57
2

When a VirtualBox guest is turned off in a save state, the IP address is kept somewhere in the VirtualBox ecosystem

This assertion is false.


It's possible (probable) that the guest OS will be frozen in a state thinking that it has a valid lease for the IP address assigned to its interfaces, and this state will be recorded in the dumped virtual machine's memory.

However, VirtualBox has no control or intrinsic knowledge of the IP address on a virtual interface - it provides virtual hardware, not a whole Ethernet / IP stack. If the VirtualBox interface is able to report an IP address associated with a particular interface, then this is only becaure the guest is running services to support this feature.

If the guest OS is restored / unfrozen after the lease has expired, then (if the DHCP client is written correctly) it will realise that the lease has expired... though there may be a delay here as the guest might have no knowledge of time passing while it was frozen... If the client uses the wrong clock (e.g: CLOCK_REALTIME vs. CLOCK_MONOTONIC on Linux) to base its lease expiration on, then there might be a window where the guest OS and another host are attempting to use the same IP.

Once unfrozen, it should make a new request to the DHCP server promptly... A DHCP request may include a "please could I have this IP again?" type request, but there is no guarantee that it'll get the same IP, that depends entirely on how long the DHCP server keeps reservations for, and whether another system has taken the address in the meantime.

0

Your edit does not change the answer to the question. You won't get duplicate IPs if you sleep a machine and bring it back online. When a machine comes online it always follows the some steps in DHCP to determine what it needs to do. If the machine wakes from sleep, it checks the current time versus the time of expiry on its lease. If the lease is not expired, it can keep using the same IP address. If the machine is booting from scratch or has no existing lease, it always asks for DHCP.

4
  • 1
    One remark: in theory a virtual machine may not be aware there was a time gap in its operation. Instead of "the machine wakes from sleep" we should consider "the hypervisor unfreezes the machine". Commented Feb 28, 2019 at 1:30
  • Unfortunately, @Andy, our experience is different: we had occasions (until we suggested to people not to stop VirtualBox guests in save state) that we found two machines with the same IP on our LAN, with the accompanying chaos.
    – boardrider
    Commented Feb 28, 2019 at 2:07
  • Did you install guest additions? This should, among other things, alert the guest that it has just been unfrozen.
    – Andy
    Commented Feb 28, 2019 at 18:17
  • Yes @Andy, guest additions are installed.
    – boardrider
    Commented Feb 28, 2019 at 22:55

You must log in to answer this question.

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