4

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

kidonchu
  • 785
  • 1
  • 9
  • 20
  • @tmatilai I just updated original post with answer to your question. – kidonchu Feb 05 '14 at 18:03
  • Do you have firewalls on host or guest which could block the connection? And host doesn't have any other network interface connected to a network which collides with 192.168.56.0/24? – tmatilai Feb 05 '14 at 18:59
  • @tmatilai Updated 3. That was my initial thought. So I disabled firewall using `systemctl stop firewalld.service` and `chkconfig firewalld off`, and I used `systemctl status firewalld.service` to make sure firewall is disabled. How can I check if host network collides with 192.168.56.0/24? – kidonchu Feb 05 '14 at 19:12
  • @tmatilai Just updated the post with output of vagrant reload --debug. I tried without port forwarding, but didn't work as expected. – kidonchu Feb 05 '14 at 20:25
  • @tmatilai I think I found a problem. If I change private ip address to 192.168.56.102, it works. So I think there is a ip address conflict. How can I check and make sure that this is the problem? – kidonchu Feb 05 '14 at 21:14

3 Answers3

2

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.

tmatilai
  • 4,071
  • 20
  • 24
  • You are right on the problem. There was another instance of vm that was occupying 192.168.56.101. I couldn't find this out because when I opened GUI version of virtualbox, it didn't show up. I deleted all vms in Virtual Box/ folder, rebooted the computer, and re-vagrant up the machine, and now it works as expected. Thanks a lot for hanging onto this problem. P.S. Not using 192.168.56.101 as private ip address might not be an option for me...We all use same box in our team, and I am the only one with Fedora. Others use Ubuntu. I don't know why Ubuntu doesn't have this problem though. – kidonchu Feb 05 '14 at 21:45
  • I am having weird issue. When I `vagrant reload`, it works fine. However, after a while, 5 mins or so, the same things happen: only able to access guest machine via port 8080. Would this happen because I changed the lower bound of DHCP range to 192.168.56.102? and keep the private ip to 192.168.56.101? This behavior is very random so that I cannot tell which part is wrong. Sometimes it doesn't work even after `vagrant reload`. I changed the lower bound of DHCP range because this issue in my OP happened again after the reboot. – kidonchu Feb 10 '14 at 17:45
2

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.

t j
  • 7,026
  • 12
  • 46
  • 66
0

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.

Jahaja
  • 3,222
  • 1
  • 20
  • 11
  • 1
    The subject is misleading. The port forwarding *does* work, but direct access doesn't as explained in all updates. Of course your statement is still correct. =) – tmatilai Feb 05 '14 at 21:37
  • Ah, true. A bit strange though. =) – Jahaja Feb 05 '14 at 23:18