0

I'm having trouble accessing my webserver when it's located on a virtual machine. If I put the webserver on the physical host machine, I can access it from the internet. However, when I try to access the webserver when it's on the VM (on the same host machine), it just hangs (from the browser, and curl externalip:forwardedport).

I'm a little annoyed why this isn't working because the parts to this setup all work in isolation, but don't work when put together.

When I put it on a virtual machine, I make sure to set up a bridged network connection and can access it from elsewhere in my network on separate machines. I also set up port forwarding on the router to the static ip assigned to the static IP assigned to the VM.

The following represent configurations. The first configuration is the one I'm trying to achieve. The second and third are "partial configurations" that seem like if they both work (and they do) then the first configuration should also work.

  1. webserver <-> virtual machine <-> host machine <-> router <-> modem <-> internet
  2. webserver <-> virtual machine <-> host machine <-> router <-> other computer
  3. ................................webserver <-> host machine <-> router <-> modem <-> internet

Basically #2 means I can access the webserver locally, and #3 means I can access the webserver from the internet, if the webserver is not on the virtual machine, but on the host of the vm.

I'm currently using:

webserver: python's SimpleHTTPServer at port 8888
virtual machine: centos deployed by vagrant on virtualbox. 
host machine: thinkpad, windows
router: apple airport, wrt-54g (tried both, same results)
modem: SB6121 cable modem
internet: comcast 

I set up port forwarding from port 8888 to the webserver's local static ip address 10.0.1.99 @ 8888.

Thought everything should be right. I asked a friend to try to access the webserver from his own router/internet and he has the same results: it just hangs.

It's the combination of port forwarding on the router and bridging the vm network adapter that seems to cause issues. I'm pretty certain I'm forwarding the right port, to the right static IP. Also, not sure why it's hanging, versus simply dropping my connection. Some people have suggested, the packets aren't finding their way back to the internet.

  • You have not supplied sufficient information to allow us to help - for a start, knowing what VM system you are using. At a guess it sounds like a combination of a NAT and Bridging proble. – davidgo Dec 27 '14 at 7:31
  • I thought I provided that information. On the VM I have two adapters. There is a NAT adapter for SSH connections I don't want to turn off, and another is the bridged connection assigned to a static IP. I can access the bridged connection from elsewhere in my network. – barrrista Dec 27 '14 at 7:39
  • 1
    Is it possible that the outbound routing is choosing the NAT path in preference to the direct path - I think this is a common mistake when setting up multiple Interfaces with different gateways, ie not having 2 routing tables. – davidgo Dec 27 '14 at 7:44
  • 1
    I haven't seen any mention on setting up IPtables on the vm. To me, that could be a problem. Try running this on the vm iptables -A INPUT -p tcp --dport 8888 -j ACCEPT – xR34P3Rx Dec 27 '14 at 16:26
  • 1
    I also have never configured this webserver before, but it is also possible that it is bound to your private ip (the ip it listens on). If possible, change to 0.0.0.0:8888. This will allow it to listen on ANY incoming address. – xR34P3Rx Dec 27 '14 at 16:30
1

I found what the problem was. Vagrant creates two adapters, one NAT, supposedly for the ssh connection, and the bridged adapter that I asked for in VagrantFile. If I disable the NAT adapter (ie. through VirtualBox) and leave the bridged adapter active, suddenly it works, and I can access the webserver from the internet. If I leave the NAT adapter in, I can only access the webserver from within my network (ie. other boxes).

Here is the configuration of when it did not work:

NAT Adapter: NAT adapter

Bridged adapter: Bridged adapter

ifconfig within my VM, hosting the webserver. Can't access from the internet. The ip address here is :99 because I set up a static ip through VagrantFile (vagrant's configuration file): ifconfig within my VM, hosting the webserver

Suddenly, it works if I remove the NAT adapter, only using the bridged adapter. The ip address changes to something assigned by DHCP, because I simply turn on: removed the NAT adapter, only using the bridged adapter

I'm positive I have set up port forwarding correctly each time the local ip changed on the bridged adapter, and have replicated the issue multiple times.

  • Well, the default route is the trick. Your vm is probabily defaulting to nat adapter for routing (ip route to check) and incoming packets on bridged adapter will be discarded. Try to set default route on the bridged adapter and delete that on nat adapter. – maudam Dec 28 '14 at 23:43
  • Apparently, I shouldn't delete the Nat adapter because I am using Vagrant. Commands like "vagrant up" won't work if the Nat adapter is removed. So mine might not be the best solution. – barrrista Feb 8 '15 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.