This month I’ve got a couple of trips to the US, one work, one leisure. I’d like to be able to use some of the dead time during the flight to do some development work. Instead of running PHP, Apache and MySQL from my Mac, I run it from a Ubuntu virtual machine via VirtualBox.
My previous configuration was to use a bridged network so the host could see the guest and access services running on it. Perfect … except when you don’t have a network connection, like when you’re on a flight. Initially I struggled with OS X setting the wired interface inactive when a cable is not connected. I asked around and found I needed to change the adapter type from bridged to host only.
Host only networking creates a new virtual adapter on the host machine using the loopback interface, VirtualBox names this
vboxnet0. This adapter enables the host to see services on the guest but with no requirement for a physical NIC to be present, so it’ll work offline too.
Setting up Host Only networking
Host only adapters cannot provide internet access, therefore we’ll need two devices on the guest for when we’re online. The first device should be configured as NAT (the default), the second is the host only adapter.
Once you’ve added those adapters, go to
/etc/fstab on the guest.
Now we can boot our VM. Once the VM starts, if you run
ifconfig in , you should see a virtual adapter has been added to OS X:
$ ifconfig vboxnet0 vboxnet0: flags=8843
mtu 1500 ether 0a:00:27:00:00:00 inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
When Ubuntu has booted, configure the network interfaces:
$ sudo vim /etc/network/interfaces
If you chose to enable VirtualBox’s built in DHCP server, you can leave the NAT interface
eth0 as dynamically assigned:
auto eth0 iface eth0 inet dhcp
Assign the second host only adapter with a static IP address, this address must be on the same subnet as the
vboxnet0 adapter on the host. For example, if our IP was 192.168.56.1, the guest must use an IP within the range 192.168.56.2 – 255.
auto eth1 iface eth1 inet static address 192.168.56.5 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.56.255
When you’re done, restart networking on the guest:
$ sudo /etc/init.d/networking restart
You should be able to SSH to Ubuntu from OS X now:
$ ssh 192.168.56.5 Linux 2.6.32-21-generic-pae #32-Ubuntu SMP Fri Apr 16 09:39:35 UTC 2010 i686 GNU/Linux Ubuntu 10.04 LTS Welcome to Ubuntu! .... $Tweet