Mike Lindegarde... Online

Things I'm likely to forget.

Putting Ubuntu 14.04 to Work via VirtualBox

I'm pretty sure I've done this before

Skip the story

Hosting Ubuntu in a VM makes it incredibly easy to setup a Linux box that you can use to host a Git server, WordPress blog, your Rails apps, Node.js, Apache, mail server, MySQL RDBMS, TeamCity, etc...  Really, there's no reason not to setup an Ubuntu VM.

This isn't the first time I've attempted blogging, nor is this the first time I've put together a post about using VirtualBox to host an Ubuntu VM.  Each time I write this post I discover that the process has gotten easier and eaiser... mostly.

You no longer need to use "VBoxManage setextradata" to setup port forwarding, Ubuntu has gotten easier and easier to use, and most major software package have some sort of setup / installation package you can download and easily install.

However, I continue to write this post every few years because I continue to have a problems trying to install the VirtualBox Guest Additions...


Getting a basic installation of Ubuntu setup is incredibly straight forward.  You pretty much need just two things:

  1. VirtualBox
  2. The latest stable distribution of Ubuntu for desktops (if you're reading this you should probably avoid Ubuntu Server)

Helpful hint:  if you have an old install of VirtualBox laying around from the last time you messed around with virtual machines, delete it and install the newest release.  This will ensure you have the newest version of the Guest Additions.

Install the Guest Additions

I'm going to assume you can figure out how to install VirtualBox and get a basic instance of Ubuntu up and running.  For the most part the options are pretty straight forward.  Give up as much memory as you can and allocate a virtual disk drive that matches your intended use for the VM.

Make sure that you go into the VM's settings (in VirtualBox) and enable 3D acceleration.  With that taken care of, open a terminal and execute the following:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential module-assistant
$ sudo m-a prepare
$ sudo apt-get install xserver-xorg xserver-xorg-core

With that taken care of, use the VirtualBox menu to mount the Guest Additions CD in the VM.  Ubuntu should automatically prompt you to begin installation.  If it does not, you can either eject / unmount the CD or run the following command:

sudo sh /media/cdrom/VBoxLinuxAdditions.run

Once the install completes you should reboot the virtual machine.  Hopefully when Ubuntu finishes rebooting you'll be all set.

Hello World

As nifty as it is to have Ubuntu running in a VM on your Windows box, it doesn't do you a lot of good unless you can get to it from the outside world.  Regardless of the port you want to open up, you basically have two ways to accomplish your goal:

  1. Configure your VM to use a Bridged Adapter
  2. Setup port forwarding

Bridged Adapter

With bridged networking your VM essentially appears to be on your network.  There is no need to setup port forwarding.  You can simply configure network router to forward traffic to the IP address of the VM.  Unless you have a compelling reason not to, I'd recommend using this configuration if you want to open something running on your VM to the outside world.

Port Forwarding

With port forwarding your host OS has the opportunity to buffer / forward packets as it sees fit.  I'll let you explore why you would use port forwarding over a bridged adapter on your own.   Here's how you do it:

  1. Open the settings for your VM in Virtual Box
  2. Go to the Network tab
  3. Ensure Attached to is set to NAT
  4. Click on Port Forwarding
  5. In the dialog that appears enter whatever Host and Guest port are appropriate for your use case.  You should leave the two IP columns blank.

Wrap up

With that you should be set to access your VM from anywhere in the world.  Please keep in mind that this probably isn't the most secure thing to do.  I wouldn't really recommend leaving any port open to the world unless you really know what you're doing. 

Random useful links: