Search code examples
centosvagrantportforwardingvagrant-windows

Forwarding multiple ports in vagrant


I have a vagrant box. I am already forwarding one port which looked like this

config.vm.network "forwarded_port", guest: 80, host: 8181

This works well but I want to forward another port and I added the following line below:

config.vm.network "forwarded_port", guest: 8080, host: 5555

I have an apache server listening at port 80 in the guest and I set up a python server to listen at 8080 in the guest too. In my host I visit 127.0.0.1:8181 and it works but if I visit 127.0.0.1:5555, I get this page is not working.

If it helps This is my network configuration in vagrant.

config.vm.network "forwarded_port", guest: 80, host: 8181
config.vm.network "forwarded_port", guest: 8080, host: 5555
config.vm.network "private_network", ip: 192.168.33.111

I have tried to add host_ip: "127.0.0.1" but it didn't change anything. I used vagrant reload after modifying my vagrantfile. What am I getting wrong here?

I followed information provided here: https://www.vagrantup.com/docs/networking/forwarded_ports.html


Solution

  • Ok I was able to resolve this problem. You have to do ifconfig and grab your ip addres from inet section.

    Use this address instead of localhost or 127.0.0.1 with any port you want to listen to if available. For me my ip was 10.0.2.15 and I listened at port 8080 and visited 127.0.0.1:5555 and it worked.