mike.williamson

Connecting to a web server on a VirtualBox guest.

Posted by: mikewilliamson on: November 14, 2009

One of the things I did frequently when using VMware is connect from my host (usually Windows) to my guest (usually Linux). The fact that I don’t really remember how I set that up seems to indicate that it was pretty trivial or just worked “out of the box” (which is a funny thing to say about a VM). After happily using Virtualbox for a while now, the need to connect from host to guest has inevitably reared its head and I was a little surprised that there does not seem to be a straight forward way to do that. Turning as one usually does in such a situation, to Google, and since it was a bit of a fiddle I thought I would scrawl it down here.

Keep in mind my host machine is Windows Vista (I know, I know…)  and the guest is Ubuntu Karmic Koala.

Open the Windows command line and navigate to

C:\Program Files\Sun\VirtualBox>

There are three commands that need to be issued. The command is a little daunting at first glance so here are the important parts:

“karmic” is the name I gave my VM when I created it.

“pcnet” refers to the PCNet virtual network card that I am using in my VM which you can select in your network settings. e1000 is also valid if thats what you’re using.

“railsdev” is the name that will be given to the port forwarding configuration that these commands set up.

The rest should be fairly self explanatory:

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/Protocol” TCP

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/GuestPort” 3000

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/HostPort” 3000

Thats about it. Not to bad when you get down to it.

Now http://localhost:3000 on your host machine connects to port 3000 on your VM. As long as you have Mongrel or Webbrick ready and waiting, things are good.

Yay!

Leave a Reply