Question

Spec:

OS: Linux fedora 3.12.9-301.fc20.x86_64.
VirtualBox: 4.3.6
Vagrant: 1.4.3

I am trying to forward host's port 8080 to guest's port 80 using following vagrant configurations.

config.vm.network "private_network", ip: "192.168.56.101"
config.vm.network "forwarded_port", guest: 80, host: 8080

I've setup vhost on guest machine with servername local.example.com.

I've added following line to host machine's /etc/hosts file

192.168.56.101 local.example.com

After vagrant up without any error, if I try to access local.example.com, the webpage cannot be found. However, if I use local.example.com:8080, I can access it fine.

Why can't I access the vhost on guest machine using local.example.com with port 80?

UPDATE 1

Inside of guest machine, if I use curl http://192.168.56.101, I get right contents printed out in the terminal. If I use curl http://localhost, I get the same contents as 192.168.56.101. So I assume 192.168.56.101 is correctly pointing to localhost.

UPDATE2

In my host machine, if I run curl http://192.168.56.101, I get following error.

curl: (7) Failed connect to 192.168.56.101:80; Connection refused

If I run nc -v local.example.com, nc -v local.example.com:8080 or nc -v 192.168.56.101, I get following error.

UPDATE 3

I saw this command while searching for solution nmap -sS -P0 192.168.56.101/32, and I ran it and got following result.

Nmap scan report for local.example.com (192.168.56.101)
Host is up (0.0000040s latency).
Not shown: 999 closed ports
PORT     STATE SERVICE
8080/tcp open  http-proxy

Nmap done: 1 IP address (1 host up) scanned in 2.40 seconds

Does this look right?

UPDATE 4

Output of vagrant reload --debug is in this link

Was it helpful?

Solution

The log shows that you have a DHCP network in VirtualBox which starts right from the very same 192.168.56.101 address. My guess is that you have another VirtualBox instance (not necessarily even created by Vagrant) running and using the same IP. Check out from the VirtualBox GUI or with some VBoxManage list vms etc. commands.

Anyway, you should not use an address from the same range that the DHCP server is using.

OTHER TIPS

I had the exact same problem with Vagrant after upgrading to Fedora 20. After a few wasted hours messing about with iptables and selinux configs I fixed it by simply switching private network IP's:

private_network: 192.168.56.123

I assume this is related to tmatilai's answer about a conflict with the DHCP ranges but when I checked, another httpd resource was already using the port under the root username.

You shouldn't need port-forwarding when using a private network. If the guest is hosting a web server on port 80 you should be able to reach it on http://192.168.56.101 without the port-forwarding configuration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top