0
2
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.
- webserver <-> virtual machine <-> host machine <-> router <-> modem <-> internet
- webserver <-> virtual machine <-> host machine <-> router <-> other computer
- ................................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 – 2014-12-27T07:31:20.303
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 – 2014-12-27T07:39:13.340
Are you using Xen, KVM, VMWare, Virtualbox or some other Hypervisor ? (also, what OS are you using ?) – davidgo – 2014-12-27T07:43:03.117
1Is 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 – 2014-12-27T07:44:37.743
The information you requested is in the post, as code formatting. – barrrista – 2014-12-27T07:56:20.283
That's possible. If that is the problem, I'm not sure why I can access the webserver on the VM from within the network, on other boxes. I have a macbook pro connected to the same router, and I simply type the static ip of the bridged VM, plus its port, in the browser, and can see the website. – barrrista – 2014-12-27T07:59:57.913
With the webserver running on the vm, try to open the webpage from a browser on the host os using the address and port . Works ? – maudam – 2014-12-27T11:45:59.333
1I 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 – 2014-12-27T16:26:23.9971I 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 – 2014-12-27T16:30:12.590@janos, yes, but I also move the webserver from host to vm when i test the vm_ip, and vice versa. – barrrista – 2014-12-27T19:05:52.690
@maudam, yes. Accessing from the host's browser works. – barrrista – 2014-12-27T19:07:35.887
@xR34P3Rx, I have tried both, but to no avail. – barrrista – 2014-12-27T19:16:19.487
Not sure if this is a issue, but when I try to look at my "wireless clients" list on Airport, I cannot see my bridged VM (static IP). When I was using the wrt-54g, the most similar list I could find was the dhcp client list, which did not show the VM as well. Not sure if it would show up in the latter case as the VM has a static IP. – barrrista – 2014-12-27T19:18:14.010
Did you follow a specific tutorial? If so, could you post it so we can review it? – xR34P3Rx – 2014-12-27T19:32:12.040
@xR34P3Rx, I'll write up a more detailed summary of what I did tonight. – barrrista – 2014-12-27T20:48:37.513
@barrrista sounds good :) – xR34P3Rx – 2014-12-27T20:49:29.233
@barrista try to disable firewalls and antivirus temporarily on host and guest. – maudam – 2014-12-28T11:44:55.980
I found what the problem was. Virtualbox creates two adapters, one NAT, supposedly for the ssh connection, and the bridged adapter that I asked for. If I disable the NAT adapter (ie. through VirtualBox), 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). I'll do a writeup with screenshots in the answer. – barrrista – 2014-12-28T21:32:10.333