Continuing on the update process of updating old "Fat Bloke" articles wrote in the past, here you can find the updated one dedicated to Host-Only Networking for VirtualBox.
Since the initial blog about VirtualBox and Networking (Oracle VM VirtualBox: Networking options and how-to manage them), there have been lots of people asking how to run multiple server vm's on their laptops, allowing the host to also connect to these servers too. As it happens, I recently needed just such a configuration myself so thought I'd share how I did it...
On my Oracle Linux laptop, I wanted to set up a private network within my host on which I would run:
Note that this had to be isolated to within my host machine because I was setting up a new Active Directory Domain (example.com) and we didn't want the Windows Server dishing out DHCP addresses to everyone in the office. But we did want the Linux Server to be able to talk with the Windows Server for directory services and name services.
So logically this looked like:
I used the VirtualBox Manager to create a vm of OS type "Windows 2016 (64-bit)" but before running it for the first time, I modified the Network configuration of the guest to use the VirtualBox Host-only Ethernet Adaptor:
I planned to use this Windows server to deliver DHCP addresses for the private host-only network, so I disabled the built-in DHCP server via the Preferences...Network dialog in the VirtualBox Manager (all this can be done form the command line too BTW). Like this:
And in the interests of full disclosure, here are my private adapter settings too:
I then installed Windows Server 2016 giving it a static IP address of 192.168.245.110 and name ad.example.com.
After initial install I added extra roles to make the server be an Active Directory Domain Controller, DNS Server and DHCP Server:
The Linux server is an Oracle Linux (7.3) server. Again, I set the newly created vm to use a Host-only network (as above), and installed Oracle Linux, giving it a static IP address: 192.168.245.111 - vdi1.example.com, and set DNS to point to the AD server ad.example.com.
This all worked swimmingly, and both machines could see each other and use each other's services:
N.B. the servers running in these vm's are full blown instances so watch out for security settings and the like which block connections between them and the host.
The great thing about host-only networks is that the host itself sits on this network and so can partake in the fun.
The host sees this network just as another NIC:
$ ifconfig vboxnet0
Note that the IP address the host uses is configured when you set up the host-only network above.
I wanted to update the Windows and Linux guests using Software Update, but to do that I needed access to the Internet, which my host only adaptor did not provide for me. One way of doing this is to temporarily switch from Host-only to NAT networking, do the update, then switch back again. And VirtualBox lets you do this while the VM is running which is very cool.
But for my Linux VM I wanted something a bit more permanent. So I created a second Bridged virtual network adaptor so that my Linux VM had an address on my host's network as well as the example.com host-only network. To do this you do have to shutdown the guest OS, and then reconfigure the VM like this:
The guest simply then sees this as another interface:
Server Operating Systems typically come as "secure by default" so watch out for firewalls blocking connections. As your host-only network is private anyway you could simply turn the firewall off, e.g. on Linux:
Possible Nameserver Issue
One issue that had me scratching my head for some time was that after I added a second interface to my Linux server, my name resolution stopped working. Eventually I figured it out: Linux has a feature called NetworkManager which detects new networks and reconfigures the system to use them. One of the results of this "reconfiguration" is an overwrite of the /etc/resolv.conf file which points to the nameservers. In my case this meant that the Linux server was no longer using the AD server for DNS. Linux experts could probably tell me how to elegantly fix this, but I found 2 solutions myself:
chkconfig NetworkManager off
hosts: files dns
I now have a very cool setup on my laptop which enables to play around with Oracle Linux, MySQL, Apache, Active Directory, and all the other services that Linux and Windows Servers offer, all without disturbing anyone else on the network.