Need help understanding differences between public and private networking and how that affects port forwarding

40 views
Skip to first unread message

micky...@gmail.com

unread,
May 22, 2018, 4:53:40 PM5/22/18
to Vagrant
Hello,

Networking noob here. Nice to meet everyone!

I have created a Vagrantfile where I use a variable that allows me to switch between public or private networking types:


I am not sure if I fully understand which network type is most optimal to use and when ...

  • When would I want to use private over public?
  • Which one would work best (or at all) with forwarded ports?
  • What is the advantage to one over the other?

Here's my current understanding (could some one confirm/deny/correct my assumptions):

  1. NAT port forwarding = "private_network"
    • Connect, from host, using "localhost"
    • Port forwarding works (why? because localhost is used by host machine and ports could collide?)
    • Setting "auto_correct" will fix any port collisions between guest and host
  2. Public Network (VirtualBox Bridged networking) = "public_network"
    • You have to connect using IP address of box (DHCP or defined via config.vm.network.ip)
    • Port forwarding does not work (why? is this because the machine handles this via Apache/Tomcat, etc, and using IP means no sharing by host machine so no ports would collide?)
    • Setting "auto_correct" is not needed because port forwarding isn't needed (or is ignored by Vagrant when network type is "public"?)

So it sounds like, to clarify my thoughts/understanding further:

  • Use "private_network" (Vagrant default) if you want to use "localhost" and use port forwarding to avoid port collisions between guest VM and host machine.
  • Use "public_network" if you want to connect to VM using IP address; port forwarding is not required because VM uses it's own IP address so ports will not collide between guest VM and host machine.

Does that sound right?

One last question:

  • If you use "private_network", and provide an IP, do you still have to worry about forwarded ports and collisions (assuming yes)?
Thanks so much for taking the time to read/help. Sorry if noob questions. Just trying to learn and become more aware of how things work. :)

Mário Costa

unread,
May 22, 2018, 5:17:58 PM5/22/18
to vagra...@googlegroups.com
Vagrant uses virtual machine backends, such as Virtualbox, so its configurations map to the capabilities of the backend.
From a Google search the first result:

Cheers

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/bad66b3d-699a-4637-8e12-040f6335ef4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Micky Hulse

unread,
May 22, 2018, 5:34:16 PM5/22/18
to vagra...@googlegroups.com
Hi Mário, thanks so much for the quick reply and help, I really appreciate it!

On Tue, May 22, 2018 at 2:17 PM, Mário Costa
<mario.si...@gmail.com> wrote:
> Vagrant uses virtual machine backends, such as Virtualbox, so its
> configurations map to the capabilities of the backend.
> From a Google search the first result:
> https://www.thomas-krenn.com/en/wiki/Network_Configuration_in_VirtualBox

Reading now, thanks for the pointer!

micky...@gmail.com

unread,
May 29, 2018, 12:44:53 PM5/29/18
to Vagrant
For anyone else interested in this topic, I found a good blog article here:


I think I like the sound of "Port-Forwarding with NAT Networking"; I think this translates to Vagrant as "private_network" for "config.vm.network" and then specify your "forwarded_port"(s) via the config.vm.network setting.

I guess I'm just looking for a "one size fits all" solution. 
Reply all
Reply to author
Forward
0 new messages