Bridged networking is another type of networking that VirtualBox provides which causes the virtual machine to appear as another physical device on your network. Your virtual machine will ask for an IP from the network via DHCP and will be visible just like any other machine.
Vagrant exposes this feature in a straightforward and easy to use way.
Since setting up bridged networking requires configuring the OS to use the new interface, this is a guest-specific behavior. Currently, Vagrant supports a small set of operation systems.
If you'd like another OS supported, you can add it yourself using a custom guest or you can get in touch with a Vagrant developer and assist us in adding it to the core.
Enabling a bridged network on a virtual machine managed by Vagrant is simple enough, using a single configuration directive in the Vagrantfile:
Vagrant::Config.run do |config| config.vm.network :bridged end
The above will tell Vagrant to setup a bridged network interface. Vagrant will always setup this bridged interface as adapter #3 on the virtual machine. This can be overridden as well, see below for more information.
Sometimes you may want to specify the host’s network interface in your
Vagrantfile. This can help an individual speed up launch time for a VM, due to bypassing the prompt, however sharing the
Vagrantfile with this set can have unexpected results, since other systems may not have the same adapters, or may be named differently.
You may inspect the bridged adapters VirtualBox can use by running:
$ VBoxManage list bridgedifs | grep ^Name Name: en0: Wi-Fi (AirPort)
Then you may use the
Name value in your
Vagrant::Config.run do |config| config.vm.network :bridged, :bridge => "en0: Wi-Fi (AirPort)" end
Some networks will not work properly with bridged networking. Specifically, I've found that hotel networks, airport networks, and generally public-shared networks have configurations in place such that bridging does not work.
You can tell if the bridged networking worked successfully by seeing if the virtual machine was able to get an IP address on the bridged adapter.
Unlike host-only networks, Vagrant does not know the IP that the bridged network will receive a priori. Instead, it is up to your network to lease your virtual machine an IP via DHCP. Because of this, the IP address can only be determined by SSHing into the virtual machine and inspecting the adapters yourself.
For example, on an Ubuntu-powered virtual machine, by running
ifconfig it is easy to see what the IP address of the bridged adapter is:
$ ifconfig ... eth2 Link encap:Ethernet HWaddr 08:00:27:df:63:62 inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fedf:6362/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24 errors:0 dropped:0 overruns:0 frame:0 TX packets:20 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4380 (4.3 KB) TX bytes:2088 (2.0 KB)
In the above output, we can see that
eth2 has an IP address of
192.168.1.3. This is the IP address of the bridged adapter.