VirtualBox and external dhcp management with dnsmasq
I use VirtualBox like many for my development VMs. One of mine problems with VirtualBox is, sometimes, that we want to manage their IPs in a more complex fashion than what’s possible with its internal DHCP server (when using “host-only” interfaces), mostly because it doesn’t allow static IP configuration.
It’s possible to disable this DHCP server and use another server, like dnsmasq. This DHCP server, which also is a DNS forwarder, is very light and can be installed on a developement server without bothering local network.
Configuration I use for my VMs is the following:
- Network/Adapter1: Attached to NAT;
- Network/Adapter2: Host-only Adapter; Name: vboxnet0
First step is to disable VirtualBox’s DHCP server. You can do this in the VirtualBox GUI or using the command line:
You’ll have to reboot all VMs to make sure this setting is considered. Unless this, the old DHCP server will still work and will provide an answer before dnsmasq.
Then, we can install dnsmasq, enable its DHCP server and only bind it on the VirtualBox’s vboxnet0 network interface (that manages “host-only” adapters).
And modify the /etc/dnsmasq.conf configuration file:
Finally, start dnsmasq:
We’ll check it works correcly by reading logs on the host and on the guest:
For more information about dnsmasq, check Dnsmasq page on Ubuntu’s website.