5

I'm using a vagrant Geodjango box and port forwarding is not working for me.

On the box, I have run:

python manage.py runserver 0.0.0.0:8000

But http://localhost:8000 and http://localhost:4567 both find nothing on the host machine.

On the Vagrant box, curl -v 'http://localhost:8000/' gives the usual:

<h2>Congratulations on your first Django-powered page.</h2>

which suggests that Django is running okay. But on the host machine, trying curl -v 'http://localhost:8000/' gives the following output:

curl: (7) Failed connect to localhost:8000; Connection refused

My Vagrantfile has the following port forwarding set up:

config.vm.forward_port 8000, 4567

Disabling the Mac's firewall does not help and stopping Apache makes no difference. I have tried running lsof -i :8000 on the host machine and there is no output, so I figure nothing is using the port.

Can anyone suggest anything?

zsquare
  • 9,916
  • 6
  • 53
  • 87
Richard
  • 62,943
  • 126
  • 334
  • 542
  • 1
    Ah, figured it out - there was a warning about port forwarding that I hadn't seen, right at the beginning of the `vagrant reload` process. Vagrant had reassigned the ports, so the site was actually running on port 2201 and `http://localhost:2201/` worked. – Richard Nov 26 '13 at 13:16

2 Answers2

8

I had the same issue on Yosemite and none of the ports were forwarding. Disabling the Firewall filter on the guest machine helped:

sudo service iptables stop
sth
  • 222,467
  • 53
  • 283
  • 367
user2333522
  • 81
  • 1
  • 2
  • 1
    I can also confirm that disabling the firewall on my guest fixed the same issue for me on Yosemite – DaddyMoe Sep 15 '15 at 10:35
  • My issue was also the firewall however I wasn't using "sudo service." The documentation here is very useful https://wiki.centos.org/HowTos/Network/IPTables - pay close attention to # iptables -P INPUT ACCEPT and # iptables -F. It's worth a read even if you can use "sudo service iptables stop" because you don't want to disable firewalls without understanding the consequences. – Adam Pearlman Oct 07 '15 at 15:59
4

Good to see you figured it out yourself.

Just want to add my 2 cents, in V2 Vagrantfile, the port forwarding code block is like below, try to use the new ones so as to avoid port conflicts (back in v1 I always got confused which is which).

config.vm.forward_port 8000, 4567 is forwarding guest port 8000 to host 4567, not the other way around.

In V2 format, it looks like below, which is clearer from my opinion

Vagrant.configure("2") do |config|
  config.vm.network "forwarded_port", guest: 80, host: 8080
end
Terry Wang
  • 13,840
  • 3
  • 50
  • 43