Setting up VirtualBox Guest VM Server Networking via NAT

I recently took Atlassian up on their Starter Pak deal to help manage some personal projects I’m hoping to kick off. I’m a big fan of their work, and their entire suite has performed extremely well for us at work for the last 3 years.

While I could run the software directly off of my iMac, my preference (and the environment I’m ultimately most comfortable in) is to run them under Linux. To accomplish this, I downloaded the latest version of Xubuntu and installed it within VirtualBox for OS X. Being the lazy man that I am, I did a plain-vanilla VirtualBox install.

After a quick apt-get to install OpenSSHd (and trying to connect via the host OS back to the guest), I realized that the default network settings would not allow me to see back into the guest OS (Xubuntu) from the host (OS X) (The other way around works fine, btw).

The VirtualBox documentation presents a few different ways to resolve this (NAT, Bridged and Host-Only). Once again, I decided to take the path of least resistance…which is to do simple port-forwarding from the host OS to the guest OS. The result is that when a resource is requested on host OS port, it just forwards the request to the mapped guest OS port.

I have 3 primary services that I’m looking to forward: SSHd (22), Apache (80) and Tomcat (8080)….so my mappings look like this:

Host OS Port 2222 –> Guest OS Port 22 (SSHd)
Host OS Port 10080 –> Guest OS Port 80 (Apache)
Host OS Port 18080 00> Guest OS Port 8080 (Tomcat)

When VirtualBox is installed, it places a few command line utilities on the host OS. The command that is needed to setup port-forwarding is VBoxManage. There are 3 values that must be set for port-forwarding to work: Protocol, HostPort and GuestPort. Below are the commands I executed to setup SSH port-forwarding:

VBoxManage setextradata "Xubuntu"
  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP

VBoxManage setextradata "Xubuntu"
  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22

VBoxManage setextradata "Xubuntu"
  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222

The value “guestssh” is somewhat arbitrary…it just needs to be the same for all 3 values. The other difference you might have is if you have chosen a different virtual network adapter (pcnet) when you setup your VM. When in doubt, check the VirtualBox documentation.

That’s basically it…just rinse and repeat for any other services that you want to run on the guest OS and have visible from the host.


Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: