Do you have to use forwarded ports?

35 views
Skip to first unread message

Jake Wilson

unread,
Jun 25, 2015, 12:31:51 PM6/25/15
to vagra...@googlegroups.com
I'm new to using Vagrant and got a question about forwarded ports. In my vagrant instance, I have a number of different websites that I am developing. Not just a single site. I would prefer to access these sites in the browser using host definitions instead of http://localhost:8080.

So for example, in my Vagrantfile I set my guest machine to have a particular ip, i just randomly chose 192.168.0.150. Next on my host machine, I edited my hosts file (I'm using Windows 7) to point my development domain names to my guest machine:

192.168.0.150   website1.local website2.local website3.local

So now, do I HAVE to use the port forwarding? I would prefer to access my local dev websites in the browser using just "http://website1.local" instead of "http://website1.local:8080". 

How do I achieve this? Do I forward a port from 80 to 80? Or do I disable port forwarding all together? Is this a common approach to developing on multiple sites in a single vagrant environment?


dragon788

unread,
Jun 26, 2015, 2:08:41 PM6/26/15
to vagra...@googlegroups.com
Rather than hacking on a hosts file (which can break networking) I would setup aliases in your development environment that let you "launch site1" and it will open whichever site is aliased as 'alias site1='firefox vagrantip:port1' or something like that. The other alternative would be to use bridging instead of port forwarding, and then you can directly access any and all ports on your Vagrant machine via a dedicated IP on your system's subnet.

Jake Wilson

unread,
Jun 27, 2015, 1:38:11 AM6/27/15
to vagra...@googlegroups.com
Why would adding hosts to your hosts file break networking? That is what the file is for. Am I missing something?

Alvaro Miranda Aguilera

unread,
Jun 29, 2015, 1:07:39 AM6/29/15
to vagra...@googlegroups.com
Hello,

Vagrant doesn't do the host (windows?) update, but you an do the port thing

You can use fwd port OR you can add a host only ip OR you can add a bridge ip

That or is an inclusive OR, that mean you can do all/some/one of them

For forward port in the vagrant host you add:
https://docs.vagrantup.com/v2/networking/forwarded_ports.html

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


For host only IP, that is a IP in a network that will be known to your
host and the VMs in that network you can use:
https://docs.vagrantup.com/v2/networking/private_network.html

config.vm.network "private_network", ip: "192.168.50.4"

For a bridge IP that is an IP in the same network local to your host
so other machines from the local network or your host, or any other
guest/vm in the local network can connect:

https://docs.vagrantup.com/v2/networking/public_network.html

config.vm.network "public_network", ip: "192.168.0.17"


In the last 2, you need to ensure:

A. The Guest firewall allow access to your port
B. The application you want to test is binding to all the IP/Interface over IPV4

Let me know if you need more information, or the urls are good
starting point to get you started.

After you modify the Vagrantfile, I would suggest do vagrant reload,
and then ping the ip you did share to the host only/bridge ip

Alvaro
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/57e0253e-2812-469f-9016-d5e8ba9eef28%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages