» Public Networks
Network identifier: public_network
Vagrant public networks are less private than private networks, and the exact meaning actually varies from provider to provider, hence the ambiguous definition. The idea is that while private networks should never allow the general public access to your machine, public networks can.
Confused? We kind of are, too. It is likely that public
networks will be replaced by :bridged
in a future release, since
that is in general what should be done with public networks, and providers
that do not support bridging generally do not have any other features that map
to public networks either.
Warning! Vagrant boxes are insecure by default and by design, featuring public passwords, insecure keypairs for SSH access, and potentially allow root access over SSH. With these known credentials, your box is easily accessible by anyone on your network. Before configuring Vagrant to use a public network, consider all potential security implications and review the default box configuration to identify potential security risks.
» DHCP
The easiest way to use a public network is to allow the IP to be assigned via DHCP. In this case, defining a public network is trivially easy:
When DHCP is used, the IP can be determined by using vagrant ssh
to
SSH into the machine and using the appropriate command line tool to find
the IP, such as ifconfig
.
» Using the DHCP Assigned Default Route
Some cases require the DHCP assigned default route to be untouched. In these cases one
may specify the use_dhcp_assigned_default_route
option. As an example:
» Static IP
Depending on your setup, you may wish to manually set the IP of your
bridged interface. To do so, add a :ip
clause to the network definition.
» Default Network Interface
If more than one network interface is available on the host machine, Vagrant will
ask you to choose which interface the virtual machine should bridge to. A default
interface can be specified by adding a :bridge
clause to the network definition.
The string identifying the desired interface must exactly match the name of an available interface. If it cannot be found, Vagrant will ask you to pick from a list of available network interfaces.
With some providers, it is possible to specify a list of adapters to bridge against:
In this example, the first network adapter that exists and can successfully be bridge will be used.
» Disable Auto-Configuration
If you want to manually configure the network interface yourself, you
can disable auto-configuration by specifying auto_config
:
Then the shell provisioner can be used to configure the ip of the interface:
» Default Router
Depending on your setup, you may wish to manually override the default router configuration. This is required if you need to access the Vagrant box from other networks over the public network. To do so, you can use a shell provisioner script:
Or, an alternative, simpler version, assuming you get DHCP from your public network:
Note the above are fairly complex and will be guest OS specific, but we document the rough idea of how to do it because it is a common question.