Web Server Access on a VirtualBox Guest

In: Computing 数码编程

7 Oct 2008

I been using VirtualBox to deploy virtual machines on my Windows machine since a significant memory upgrade. VirtualBox is suprisingly easy to used if compared to VMWare and it just fit to my basic needs.

Access the web server from the guest on host is pretty straightforward but not the other way.

In my scenario, my host OS is XP and the guest OS is Ubuntu. First, we go to the XP host and open a command prompt, and configure the port forwarding in the VirtualBox installation directory, as follows:

cd C:\Program Files\Sun\xVM VirtualBox
VBoxManage setextradata MyUbuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort" 8888
VBoxManage setextradata MyUbuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort" 80
VBoxManage setextradata MyUbuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol" TCP

This simply arbitrarily assign port 8888 of our host XP to forward connections to the guest Ubuntu’s port 80, which is the default port for HTTP connections.

Having done that, we now turn on our guest Ubuntu and use our web browser on host XP to browse http://localhost:8888/. Alright, now we got a local web server to play with.

We can also allowing SSH connections from the host OS to the guest OS as follows:

cd C:\Program Files\Sun\xVM VirtualBox
VBoxManage setextradata MyUbuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata MyUbuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata MyUbuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

7 Responses to Web Server Access on a VirtualBox Guest

Avatar

Edgar

December 30th, 2008 at 5:39 am

Man, I can’t do it! :( Is there any action that has to be done after the command promt on host machine?

When I write the command line you have here, I use instead of MyUbuntu, linux, as it is the name of my fedora instance on xVM.

Avatar

teonator

January 6th, 2009 at 10:32 am

What is the problem you encounter?

Avatar

elmer romero

January 16th, 2009 at 5:22 am

it worked! could not imagine a simpler way to do it Thanks

Avatar

cid

January 16th, 2009 at 5:17 pm

Hi From Spain;

I have a little problem with this maybe Can you helpme?
My problem is this I have VirtualBox Install in XP runnin wiht opensolaris virtual and this configuration

VirtualBox Command Line Management Interface Version 2.1.0
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/LastWindowPostion, Value: 4,30,640,522,max
Key: GUI/Fullscreen, Value: off
Key: GUI/Seamless, Value: off
Key: GUI/AutoresizeGuest, Value: on
Key: GUI/LastCloseAction, Value: powerOff
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol, Value: TCP
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort, Value: 8080
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort, Value: 5555
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort, Value: 2222
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort, Value: 22
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol, Value: TCP

But when I intented 127.0.0.1:5555 in XP host can´t open of the browser the correct web, and when i open the web 127.0.0.1:8080 in openSolaris host (machine virtual) I can open the web correctly of Apache.

I don´t know what is happens maybe permisions on XP

Thanks

Avatar

teonator

January 22nd, 2009 at 8:36 am

Might be XP or your firewall blocks the relative port? You may turn off your firewall temporary to identify the firewall blockage.

Avatar

cid

January 27th, 2009 at 6:21 pm

Hi
First Thanks for the answer, but i had my firewall disabled, I tried this before but nothing, i don´t know what is happens, because, I have the same configuration in Suse 10.1 and this is OK, but in XP not run, I think te OS XP is not nice for VirtualBox.

Thanks Again

Avatar

Robert

February 6th, 2009 at 5:27 am

Thanks for this, real helpful :)

I’m using virtual hosts on the guest machine, so if someone wants to access them from the host machine, needs to add the following to the hosts file on the host machine (C:\Windows\System32\driver\etc\hosts)

127.0.0.1 VirtualHostName

This way the virtual host will be accessible by VirtualHostName:8888

Thanks again for the tip ;)

Comment Form

About this blog

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, velit semper laoreet dictum, quam diam dictum urna, nec placerat elit nisl in quam. Etiam augue pede, molestie eget, rhoncus at, convallis ut, eros. Aliquam pharetra.

Advertisments

  • teonator: @Pablo: Hi sorry for late reply (very late one). Hope you are doing fine there. I am not using MySQL [...]
  • Pablo Cerda: Hi, we follow the steps described in your post to handle que drupal queries via Mysql proxy. If we t [...]
  • 三吉: wa...isnt a games?.... [...]
  • perrinator: everything is just a few HUNDREDS clicks away! LMAO!!!!! [...]
  • perrinator: LMAO!!!! ROTFL!!! LOL!!!! IS THIS F**KING REAL?!?!? [...]