» Basic Usage of Networking

Vagrant offers multiple options for how you are able to connect yourguest machines to the network, but there is a standard usage pattern aswell as some points common to all network configurations thatare important to know.

» Configuration

All networks are configured within your Vagrantfileusing the config.vm.network method call. For example, the Vagrantfilebelow defines some port forwarding:

  1. Vagrant.configure("2") do |config|
  2. # ...
  3. config.vm.network "forwarded_port", guest: 80, host: 8080
  4. end

Every network type has an identifier such as "forwarded_port" in the aboveexample. Following this is a set of configuration arguments that can differfor each network type. In the case of forwarded ports, two numeric argumentsare expected: the port on the guest followed by the port on the host thatthe guest port can be accessed by.

» Multiple Networks

Multiple networks can be defined by having multiple config.vm.networkcalls within the Vagrantfile. The exact meaning of this can differ foreach provider, but in general the order specifiesthe order in which the networks are enabled.

» Enabling Networks

Networks are automatically configured and enabled after they've been definedin the Vagrantfile as part of the vagrant up or vagrant reload process.