» Private Networks

Network identifier: private_network

Vagrant private networks allow you to access your guest machine by some addressthat is not publicly accessible from the global internet. In general, thismeans your machine gets an address in the private address space.

Multiple machines within the same private network (also usually with therestriction that they're backed by the same provider)can communicate with each other on private networks.

Guest operating system support. Private networksgenerally require configuring the network adapters on the guestmachine. This process varies from OS to OS. Vagrant ships withknowledge of how to configure networks on a variety of guestoperating systems, but it is possible if you are using a particularlyold or new operating system that private networks will not properlyconfigure.

» DHCP

The easiest way to use a private network is to allow the IP to be assignedvia DHCP.

  1. Vagrant.configure("2") do |config|
  2. config.vm.network "private_network", type: "dhcp"
  3. end

This will automatically assign an IP address from the reserved address space.The IP address can be determined by using vagrant ssh to SSH into themachine and using the appropriate command line tool to find the IP,such as ifconfig.

» Static IP

You can also specify a static IP address for the machine. This lets youaccess the Vagrant managed machine using a static, known IP. TheVagrantfile for a static IP looks like this:

  1. Vagrant.configure("2") do |config|
  2. config.vm.network "private_network", ip: "192.168.50.4"
  3. end

It is up to the users to make sure that the static IP does not collidewith any other machines on the same network.

While you can choose any IP you would like, you should use an IP fromthe reserved private address space. These IPs are guaranteed to never be publicly routable,and most routers actually block traffic from going to them from theoutside world.

For some operating systems, additional configuration options for the staticIP address are available such as setting the default gateway or MTU.

Warning! Do not choose an IP that overlaps with anyother IP space on your system. This can cause the network to not bereachable.

» IPv6

You can specify a static IP via IPv6. DHCP for IPv6 is not supported.To use IPv6, just specify an IPv6 address as the IP:

  1. Vagrant.configure("2") do |config|
  2. config.vm.network "private_network", ip: "fde4:8dba:82e1::c4"
  3. end

This will assign that IP to the machine. The entire /64 subnet willbe reserved. Please make sure to use the reserved local addresses approvedfor IPv6.

You can also modify the prefix length by changing the netmask option(defaults to 64):

  1. Vagrant.configure("2") do |config|
  2. config.vm.network "private_network",
  3. ip: "fde4:8dba:82e1::c4",
  4. netmask: "96"
  5. end

IPv6 supports for private networks was added in Vagrant 1.7.5 and maynot work with every provider.

» Disable Auto-Configuration

If you want to manually configure the network interface yourself, youcan disable Vagrant's auto-configure feature by specifying auto_config:

  1. Vagrant.configure("2") do |config|
  2. config.vm.network "private_network", ip: "192.168.50.4",
  3. auto_config: false
  4. end

If you already started the Vagrant environment before setting auto_config,the files it initially placed there will stay there. You will have to removethose files manually or destroy and recreate the machine.

The files created by Vagrant depend on the OS. For example, for manyLinux distros, this is /etc/network/interfaces. In general you shouldlook in the normal location that network interfaces are configured for yourdistro.