How to Access services on a Guest Sun VirtualBox from the Host

I recently got sick of trying to get the lastest version of VMWare server to play nice. I need to run an Ubuntu Linux server on my Windows XP machine for testing various pieces of software.

After a bit of research i downloaded Suns VirtualBox, which seemed to have all the features i was looking for without all the fluff i didn’t need!

Download, installation and configuration was a breeze. I downloaded the latest Ubuntu iso, mounted and installed. Bingo.

However, i need to SSH to this machine from my desktop and i also need to access pages from the apache web server on the Ubuntu installation

By default the networking for the virtual machine is set to PCnet-FAST III(NAT) and the guest machine will reside on a different network.

Looking through the Virtual Box documentation i found what was needed to forward ports on my host (Windows XP) to the guest (Ubuntu) so that i could ssh and access http on the virtual box.

I hope this saves someone else a few minutes:

To enable port forwarding from the host to the guest OS, the guest must be switched off..

using the command prompt, navigate to where the VBoxManage executable is located, on my system this is:

cd “Program Files\Sun\xVM VirtualBox”

Then 3 commands need to be run for each mapping you wish to create.. with the following syntax (replace tokens in []):

  • VBoxManage setextradata “[name of your virtual machine]” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/[friendly name for rule]/Protocol” [protocol]
  • VBoxManage setextradata “[name of your virtual machine]” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/[friendly name for rule]/GuestPort” [guest port]
  • VBoxManage setextradata “[name of your virtual machine]” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/[friendly name for rule]/HostPort” [host port]

So to enable forwarding of port 2222 on my local machine to port 22 on the Ubuntu virtual machine i issued the following commands:

  • VBoxManage setextradata “Ubuntu Testing VPS” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol” TCP
  • VBoxManage setextradata “Ubuntu Testing VPS” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort” 22
  • VBoxManage setextradata “Ubuntu Testing VPS” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort” 2222
  • And to enable forwarding of port 8888 on my local machine to port 80 on the Ubuntu virtual machine i issued the following commands:

  • VBoxManage setextradata “Ubuntu Testing VPS” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysql/Protocol” TCP
  • VBoxManage setextradata “Ubuntu Testing VPS” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysql/GuestPort” 3306
  • VBoxManage setextradata “Ubuntu Testing VPS” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysql/HostPort” 3333
  • i can now access the ubuntu ssh server via ssh -p 2222 user@127.0.0.1

    and i can now access the apache server on the ubuntu virtual server via: http://localhost:8888/

Tags: , , ,

This entry was posted on Thursday, August 6th, 2009 at 10:25 am and is filed under Virtualisation. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply