Mapping of Vagrant Networks to VirtualBox Adapter Types

Mapping of Vagrant Networks to VirtualBox Adapter Types

Users of Vagrant may have noticed that the the configuration options for networks (config.vm.network) in Vagrant don’t match up cleanly to the network Adapter types in VirtualBox – as an example, when defining a “private_network” in a Vagrantfile Vagrant will actually provision your virtual appliance with a “Host-only Adapter.” The remainder of this blog post will describe the mapping of network configuration in a Vagrantfile to the adapters in VirtualBox in more detail.

forwarded_port Network Configuration

“forwarded_port” maps to a “NAT” type adapter
note that Vagrant always installs a NAT type adapter as the first network interface (typically en0 or eth0) when using VirtualBox. This is not well documented on the Internet, but can be found in Mitchell Hashimoto’s Vagrant: Up and Running.

private_network Network

“private_network” maps to a “Host-only Adapter”
if you provide an IP address (example: config.vm.network “private_network”, ip: “192.168.2.2”) which does not exist on a VirtualBox “Host-only Network” (such as vboxnet0) Vagrant will instruct VirtualBox to create a network for your virtual appliance.

public_network Network:

“public_network” maps to a “Bridged Adapter”
note that if you are using a public_network without specifying an adapter to bridge to you will be asked “what interface should the network bridge to” and be given a list of physical interfaces provided buy the Host OS.

Screenshot resulting from Testing

I attached a screenshot that resulted from the Vagrantfile that I used to create this mapping. Essentially the screenshot shows an instance that contains one of each type of adapter:

Vagrant-VirtualBox-Create_all_network_types

Vagrantfile used in Testing

To perform the mapping test I created a Vagrantfile that attaches each type of network interface. This Vagrantfile is available in my Snippets GitHub repository at https://github.com/colinbjohnson/snippets/blob/master/vagrant/create_all_network_types/Vagrantfile.

Questions or Comments?

If you have any questions please feel free to comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s