Hi everyone,
Is there a way to do DHCP address reservation on Host-Only network?
By that i mean: assign specific address (eg. 192.168.56.120) to specific VM (with host-only adapter)
Host-Only network - DHCP address reservation?
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: Host-Only network - DHCP address reservation?
AFAIK, no, there is no address reservation scheme in the VirtualBox DHCP server. However many simple home routers also do not have an IP reservation scheme but you can still use a static IP address, you just choose one that fits the netmask and is never likely to be assigned by DHCP.
Also look at the "VBoxManage dhcpserver" commands discussed in the user manual. As mentioned I see no obvious way to reserve an IP address, but I do see a way to limit the range of IP address which the DHCP server will hand out.
Or you can switch off the DHCP server and use static IPs exclusively. I don't imagine that you're having to manage a very large network this way.
Also look at the "VBoxManage dhcpserver" commands discussed in the user manual. As mentioned I see no obvious way to reserve an IP address, but I do see a way to limit the range of IP address which the DHCP server will hand out.
Or you can switch off the DHCP server and use static IPs exclusively. I don't imagine that you're having to manage a very large network this way.
Re: Host-Only network - DHCP address reservation?
Thanks @mpac
I workarounded it by:
1. temporary reducing pool to only 1 desired address
2. starting up VM (letting it get the only available IP in the pool)
3. shutting down VM
4. reverting pool to normal
At the next boot that VM gets now desired IP (assigned on a previous boot).
I workarounded it by:
1. temporary reducing pool to only 1 desired address
2. starting up VM (letting it get the only available IP in the pool)
3. shutting down VM
4. reverting pool to normal
At the next boot that VM gets now desired IP (assigned on a previous boot).
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: Host-Only network - DHCP address reservation?
I don't believe that can be safely assumed. Yes, the guest OS may now have a preferred IP address which the DHCP may or may not honor, or possibly it's just still inside the lease period of your initial test.
Long term I don't believe yours is a real solution, I suggest you use the solution I outlined above involving limiting the pool and using a static IP that's outside the pool but inside the netmask.
-
- Site Moderator
- Posts: 20945
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Windows, Linux
Re: Host-Only network - DHCP address reservation?
In the main Virtualbox configuration folder ".Virtualbox" , there is a ".leases" file for each Host-Only and NAT Network. This file ties a particular IP address to a particular MAC address.
It could be possible to get the network set up just the way you want it then copy that file. When Virtualbox is shut off completely and the background VboxSVC service is off, writing the copy back over the original should theoretically reset Virtualbox to the desired network settings.
Note that the file gets re-written at various times (there's also a "-prev" version of the file, implying regular re-writes by VboxSVC service, like the VMs' .vbox files). So writing the copy back over the original would clear what new settings have been made, possibly damaging other newer Virtualbox networks.
Some reasonable scripting could reassemble a new .leases file with new info in place and the desired old info kept.
Virtualbox does not have any ability to automate this kind of tweak. It is strictly a roll-your-own.
It could be possible to get the network set up just the way you want it then copy that file. When Virtualbox is shut off completely and the background VboxSVC service is off, writing the copy back over the original should theoretically reset Virtualbox to the desired network settings.
Note that the file gets re-written at various times (there's also a "-prev" version of the file, implying regular re-writes by VboxSVC service, like the VMs' .vbox files). So writing the copy back over the original would clear what new settings have been made, possibly damaging other newer Virtualbox networks.
Some reasonable scripting could reassemble a new .leases file with new info in place and the desired old info kept.
Virtualbox does not have any ability to automate this kind of tweak. It is strictly a roll-your-own.
-
- Volunteer
- Posts: 5678
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: Host-Only network - DHCP address reservation?
Like any decent DHCP server, the VirtualBox DHCP server remembers the assignment of IP addresses to MAC addresses, so the workaround of the OP will work as expected (as long as the MAC addresses aren't changed, of course).
The assignments are saved in files that can be found in the VirtualBox global configuration directory and whose names end with ".leases". After rebooting the host and before executing any VirtualBox component, one can edit the files by hand, in case that one wishes to configure multiple assignments. AFAIK, the "VBoxManage dhcpserver" command doesn't offer an option to configure the assignments.
The assignments are saved in files that can be found in the VirtualBox global configuration directory and whose names end with ".leases". After rebooting the host and before executing any VirtualBox component, one can edit the files by hand, in case that one wishes to configure multiple assignments. AFAIK, the "VBoxManage dhcpserver" command doesn't offer an option to configure the assignments.
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: Host-Only network - DHCP address reservation?
IMO, if one can avoid manually editing VirtualBox config files then one should do so. Even worse is to have a script modifying them.
I don't see any useful risk/reward balance here. The already suggested solution is risk free.
I don't see any useful risk/reward balance here. The already suggested solution is risk free.