1

I am using VirtualBox 5.2.18 on Ubuntu Server 18.04. I have several VirtualBox guests machines sharing a NAT Network intnet. Currently, intnet has a DHCP server (set up by VirtualBox) that automatically assigns dynamic IP's to the guests. This works fine, but I would like the DHCP server to assign static IP's to specific guests based on their network interface's MAC address. Static IP's can be set inside the guests, but that takes time and is guest OS dependent. Is there a way, in VirtualBox, to assign static IP's to the guests?

There is a an executable in the VirtualBox installation folder called VBoxNetDHCP. Judging by the output of VBoxNetDHCP, it seems to allow for static IP assignment by MAC address. I cannot get it to work though, and documentation for it is virtually nonexistent.

  • 2
    When I do this I use another small VM to provide DHCP, DNS for a fake domain, etc. to my internal network. Using Debian 9 you can go as low as 128mb of ram and perhaps 1.5gb of disk use after install. – ivanivan Aug 20 '18 at 1:15
  • I'm leaning towards doing that, @ivanivan. Do you happen to have a tutorial at hand? – Mohamed Laradji Aug 20 '18 at 20:57
  • I'll post it as an answer, give me a few ... – ivanivan Aug 21 '18 at 0:01
1

Normally when I do things like this (and I do it a lot) I tend to use a VM acting as a network server that does things like DHCP, DNS - both caching for the world and locally spoofing fake.tld - etc.

Simplest way is to do a base, bare install of Debian via the netinstall image - select none of the package groups other than the ssh server option and perhaps "standard utilities".

Once it is up and running, to turn it into a DHCP server for your internal VM network, install the isc-dhcp-server package. Then edit /etc/dhcp/dhcpd.conf

Here's a simple example from mine. This sets a short lease time (5 minutes), sets the client search-domain, etc. to "fake.tld", points their dns queries to 192.168.1.2, and gives out addresses in the range of 10.99.98.80-100 with 24 bits of netmask. Note that the VM doing this must have an adapter configured with an IP within the 10.99.98.0/24 subnet.

In addition to the general pool, I give the device with the MAC address of 80:c1:6e:2b:b6:cd an explicitly defined lease (as well as any other option like a DNS server to use, gateway, etc) for the .110 ip. Any such "static leases" must be for addresses OUTSIDE of your dynamic range, but within the subnet configured in both the config file AND on the network adapter of the machine hosting the service.

When you add a new host and you want it to have a specific IP, simply add another host stanza - the host name doesn't need to match whatever the client sends but it does need to be unique in the file. After you've added it, restart the service service isc-dhcp-server restart

ddns-update-style none;
option domain-name "fake.tld";
option domain-name-servers 192.168.1.2;
option domain-search "fake.tld";
default-lease-time 600;
max-lease-time 720;
authoritative;
log-facility local7;

subnet 10.99.98.0 netmask 255.255.255.0{
    range 10.99.98.80 10.99.98.100;
    option routers 10.99.98.1;
}

host lr-tv {
    hardware ethernet 80:c1:6e:2b:b6:cd;
    fixed-address 10.99.98.110;
    option routers 10.99.98.1;
    option domain-name-servers 192.168.1.2;
}
  • This worked for me, except that: 1. My DHCP VM uses Ubuntu Server (which is based on Debian) rather than Debian. I installed the same isc-dhcp-server package. 2. My internal network (intnet in my question) is 192.168.1.0/24, and I used option routers 192.168.1.1; and option domain-name-servers 192.168.1.1;. I was able to tell which IP to use by using nmap -sn 192.168.1.0/24. 3. I defined the options routers and domain-name-servers globally by adding them to /etc/dhcp/dhcpd.conf after the line # option definitions common to all supported networks.... – Mohamed Laradji Aug 21 '18 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.