I have a CentOS installed in VirtualBox. I have a web server running within it but for some reason I can't seem to be able to access it from outside.

The Ip address reported from CentOS is: The web server is on port 8080.

I can curl and I get correct response (from CentOS).

Iptables is not running.

I have network enabled in VirtualBox (NAT) and I have set a forwarding rule,80,,8080

For some reason this does not get me anything. When I try to curl, I get: "curl: (7) Failed to connect to port 80: Connection refused"

I also figured out that if I try to curl from Guest OS using it's public IP I still get the same error with connection refused.

Does anyone have any idea what I might be doing wrong?

migrated from serverfault.com Sep 3 '14 at 12:22

This question came from our site for system and network administrators.

  • This is because you're using the NAT networking mode. Try the Bridged one instead. – tombull89 Sep 3 '14 at 12:17
  • The thing is that I'd like to know why this NAT does not work as I believe I have configured it. – markovuksanovic Sep 3 '14 at 13:04
  • I tried swithcing to bridged mode and it still doesn't work. – markovuksanovic Sep 3 '14 at 13:26
  • You have to make sure you web server binds to all IP address interfaces, usually with a *. Otherwise it will only listen to connections from localhost. – Chloe Mar 17 '17 at 8:14

The virtual machine is behind NAT and won't be accessible from the outside.

You can either configure NAT port forwarding or change the interface type to bridge (so the VM has a physical presence in your local network). If you only need to access it from your machine, the Host-Only Adapter type will be enough.

  • Well, I believe I have set up port forwarding. I have set (in VirtualBox settings) Host IP to be, Host Port to be 9090, Guest IP to be and Guest Port to be 8080. When I use "curl" I don't get any response. It seems like curl is hanging... If I use "curl" from guest VM I get correct response - Hello World. – markovuksanovic Sep 3 '14 at 12:26
  • sometimes you need to restart your VM. Also check that the Guest IP is the one that is listed for eth0, rather than the virbr0 one. – robert Sep 3 '14 at 12:29
  • No that did not help. But I realised that if I use "curl" from guest OS I still get the same error which is a bit weird as this should be machines public IP... – markovuksanovic Sep 3 '14 at 12:44
  • Ok, sorted it out. For some stupid reason webserver which I use does not distinguish difference between – markovuksanovic Sep 3 '14 at 13:43

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.