I can't access my forwarded ports outside my vagrant box shell.
I created a vagrant box with the following forwarded ports.
config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true
config.vm.network "forwarded_port", guest: 27017, host: 27017 #mongodb
config.vm.network "forwarded_port", guest: 5000, host: 5000 #python flask port
config.vm.network "forwarded_port", guest: 5050, host: 5050 # NODE Port
config.vm.network "private_network", ip: "192.168.33.10"
I have installed both a python server and a nodejs server. If I ssh in to my vagrant box and try: curl http://localhost:5050
it correctly returns my nodejs hello world. If I curl http://localhost:5000
it correctly my python3 hello world.
However, I can't access my localhost outside the vagrant environment (with the servers in vagrant still active)
What am I doing wrong?
I am setting up a new machine - so it is possible I've not installed something essential on my localmachine but I have installed the dependencies for vagrant etc.
Pinging localhost or 127.0.0.1 works but only without a port. I am getting the following errors in terminal from my host machine outside vagrant:
$ ping localhost:80
ping: cannot resolve localhost:80: Unknown host
$ ping localhost:8080
ping: cannot resolve localhost:8080: Unknown host
$ curl 'http://localhost:80'
curl: (7) Failed to connect to localhost port 80: Connection refused
$ curl 'http://localhost:8080'
curl: (56) Recv failure: Connection reset by peer
$ curl 'http://localhost:5000'
curl: (56) Recv failure: Connection reset by peer
$ curl 'http://localhost:5050'
curl: (56) Recv failure: Connection reset by peer
$ curl 'http://127.0.0.1:80'
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
$ curl 'http://127.0.0.1:8080'
curl: (56) Recv failure: Connection reset by peer
$ curl 'http://127.0.0.1:5000'
curl: (56) Recv failure: Connection reset by peer
$ curl 'http://127.0.0.1:5050'
curl: (56) Recv failure: Connection reset by peer
& the below from the static ip, after a short delay for each...
$ curl 'http://192.168.33.10:80'
curl: (7) Failed to connect to 192.168.33.10 port 80: Connection refused
$ curl 'http://192.168.33.10:8080'
curl: (7) Failed to connect to 192.168.33.10 port 8080: Connection refused
$ curl 'http://192.168.33.10:5000'
curl: (7) Failed to connect to 192.168.33.10 port 5000: Connection refused
$ curl 'http://192.168.33.10:5050'
curl: (7) Failed to connect to 192.168.33.10 port 5050: Connection refused
I am using Mac OS Catalina. My firewall is disabled & allowing all connections.
Output of sudo netstat -ntlp
within the vm..
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 469/rpcbind
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 510/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 865/sshd
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 790/postgres
tcp 0 0 192.168.33.10:5050 0.0.0.0:* LISTEN 2730/node
tcp 0 0 192.168.33.10:5000 0.0.0.0:* LISTEN 4070/python
tcp6 0 0 :::111 :::* LISTEN 469/rpcbind
tcp6 0 0 :::22 :::* LISTEN 865/sshd
tcp6 0 0 ::1:5432 :::* LISTEN 790/postgres
It seems to be similar to the problem here but my vagrantfile has the right lines in it: Vagrant, nodejs and iptable port forwarding
I've also double checked everything pointed out in about 10 questions like this: vagrant port forwarding doesn't work: Connection reset by peer