Late last year, I wrote about a hack I came up with for configuring a VirtualBox guest OS with DHCP and ensuring it always got the same IP address. After a new project and some new insight, I’ve figured out a new way that deprecates all of the information in that post. Under that configuration, I assumed that the only way to get a static IP address for a Windows guest OS was to join it to the corporate domain – I was wrong. In the steps that follow, I’ll explain how to set up VirtualBox networking and the network settings for Windows and Ubuntu guests to support static IPs on your VMs. This will make it possible for you to connect from VM-to-VM (provided they’re both running) and for your host OS (in this case Mac OSX) to connect to each VM via static IP.
Step 1: VirtualBox Network Settings
To enable static IP addresses on your VirtualBox VMs, you’ll first need to setup a Host-Only network. The host-only network is a virtual network provided by VirtualBox that is visible only to the Host OS and its virtual machines. VirtualBox should setup a default host-only network during installation, but if it doesn’t you can add one pretty easily. Go to VirtualBox’s application menu and select Preferences – Network. Here you’ll be able to add a host-only network if it doesn’t exist… If desired, you can also configure multiple host-only networks allowing you to create various scenarios where VMs are networked together or fenced-off from each other.
VirtualBox Host-Only Networks
Below are my VirtualBox network settings. As you’ll notice, I’ve enabled the DHCP server on the host-only network albeit unnecessary. I just wanted to show that you can have it enabled and still assign your VMs static IP addresses.
VirtualBox Host-Only Network Adapter and DHCP Server Settings
Step 2: VirtualBox VM Network Adapter Settings
In this scenario, your VMs will need two network adapters – a NAT adapter for Internet connectivity; and a Host-Only adapter for the network we configured in Step 1. When you create your new VM settings, VirtualBox should add a NAT adapter by default so you shouldn’t have to do anything here.
Virtual Machine Settings: NAT Network Adapter
Enable the host-only adapter by clicking the Enable Network Adapter checkbox on the Adapter 2 tab. Select Host-Only Adapter from the Attached To combo box and select the host-only network you created in Step 1 in the Name combo box. If you only have one host-only network, this will already be selected… Please note this is a single VM configuration. You’ll have to add the host-only adapter to all of your participating VMs.
Virtual Machine Settings: Host-Only Network Adapter
Step 3 (Windows): Static IP Configuration (Host-Only Network)
Setting up a static IP on a Windows machine is fairly straightforward as the IPV4 settings dialog should be familiar to almost everyone… Below I’ve configured the Default Gateway and Preferred DNS Server boxes to contain the host-only network adapter address configured in Step 1 (192.168.56.1). I’ve assigned a static IP similar to the default gateway incrementing the address’s last number by one. There is no configuration necessary for the NAT network adapter. Below you’ll also notice a screen shot of my Windows network properties. For reference purposes only, I renamed the machine’s networks to reflect the names of the VirtualBox network adapters.
Windows IPV4 Configuration Settings
Step 3 (Ubuntu): Static IP Configuration (Host-Only Network)
Configuring a static IP in Ubuntu (I’m using the latest version available, 12.04) is just as straightforward as the Windows configuration. Again, you’ll only need to configure the host-only network adapter – the settings are exactly the same as they were for the Windows machine except for the IP address. Both the Default Gateway and Preferred DNS Server should be set to the host-only network adapter address configured in Step 1 (192.168.56.1). Just choose your static IP and you’re finished. As before, for reference purposes I’ve renamed each of my Ubuntu networks to match the VirtualBox network adapter name.
Ubuntu IPV4 Configuration Settings
All in all, the static IP configuration is really easy. Nothing more to say on this topic…