5

I currently have a development environment setup on a Windows 7 PC running Ubuntu 11.04 inside of a VirtualBox on the same box. I am using the "Bridged Network" option within VirtualBox, and inside of Windows I have bridged the network connection created by VirtualBox and my standard wifi connection from Windows 7. This has allowed me to access the webserver running in the VirtualBox across my local network under one i.p., however when I go into my router to port forward port 80 to the outside world, it is still inaccessible. Is there something I'm missing in order to get this to work as described? I would like to expose port 80 on the VirtualBox to the outside world.

4
  • Have you tried using both the guest local ip and the hosts one? It could be that it needs the guests direct ip address. May 11, 2011 at 13:57
  • I have not, I'll try that when I get home this evening. The guest machine has 2 adapters and 4 ips. the 1st adapter is setup for NAT and has a address off the normal network range. The second adapter has 3 ips, ranging from the bridged ip, to two static ips that are currently not in use. So should I use the 1st adapter's NAT address for the port forwarding?
    – chrisw
    May 11, 2011 at 14:01
  • Why are you doing double NAT? If your router is already doing NAT, you've got plenty of private IP addresses to choose from. Why do you have NAT enabled on your VirtualBox guest OS?
    – Spiff
    May 11, 2011 at 14:10
  • Due primarily to ignorance. I was following a guide to setting up a development server via VirtualBox and that was the recommended setup. I just want to be able to forward my ssh and apache ports to the outside world and be able to access them internally as well.
    – chrisw
    May 11, 2011 at 14:20

2 Answers 2

3

It has been my experience that virtualized networks and WiFi adapters typically will have problems - and this isn't specific to just VirtualBox.

I would recommend that you switch the virtual network adapter in VirtualBox to be in NAT mode instead of bridged. You can then port forward through VirtualBox (similar to what you did on your router) to access the web server. There isn't a GUI for port forwards, so you will need to do this from the command line:

VBoxManage setextradata "VM Name Here" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/http/Protocol" TCP
VBoxManage setextradata "VM Name Here"  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/http/GuestPort" 80
VBoxManage setextradata "VM Name Here” "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 8080

That will forward port 8080 on your host to port 80 on your guest, so your router configuration would need to forward public port 80 to 8080 on your laptop. Feel free to adjust the port numbers to whatever makes sense on your network.

Another option would be to connect an ethernet cable as the bridged networking option would work just fine in that case.

2
  • This may sound like a silly question, but can you forward the same port to the host machine? I've seen examples like this around but they always seem to do something similar to what you have here. I would ideally like to forward the guest port 80 to the host port 80. Also, will I need to add this to a automated script or do I just need to enter it once?
    – chrisw
    May 11, 2011 at 14:12
  • @chrisw Yes, You can certainly forward the same port number - so long as you don't have a server already using that port on the host machine.
    – Goyuix
    May 11, 2011 at 17:49
0

Actually this is quite simple with netsh on windows host.

netsh interface portproxy add v4tov4 listenport=8080 listenaddress=HOSTIPADDRESS connectport=80 connectaddress=GUESTIPADDRESS

Then as Goyuix pointed out you just need to forward router public port 80 to 8080 to your host.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .