VirtualBox Bridged Network Port Forwarding Issue

7,279

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.

Share:
7,279

Related videos on Youtube

chrisw
Author by

chrisw

Updated on September 18, 2022

Comments

  • chrisw
    chrisw over 1 year

    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.

    • Admin
      Admin almost 13 years
      Have you tried using both the guest local ip and the hosts one? It could be that it needs the guests direct ip address.
    • Admin
      Admin almost 13 years
      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?
    • Admin
      Admin almost 13 years
      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?
    • Admin
      Admin almost 13 years
      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
    chrisw almost 13 years
    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?
  • Goyuix
    Goyuix almost 13 years
    @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.