I'm trying do set up the most basic network bridge demo in Vagrant. I have two machines in the same subnet, but on different LANs, and a bridge machine with two interfaces and a network bridge that gets set up in a provisioning script.
Here's my Vagrantfile
:
$bridge_script = <<SCRIPT
sudo apt-get update
sudo apt-get install -y bridge-utils
sudo brctl addbr br0
sudo brctl addif br0 eth1 eth2
sudo ifconfig br0 up
SCRIPT
Vagrant.configure(2) do |config|
config.vm.define "machine1" do |machine1|
machine1.vm.box = "hashicorp/precise64"
machine1.vm.network "private_network", ip: "192.168.1.2",
virtualbox__intnet: "lan1"
end
config.vm.define "bridge" do |bridge|
bridge.vm.box = "hashicorp/precise64"
bridge.vm.network "private_network", ip: "0.0.0.0",
virtualbox__intnet: "lan1"
bridge.vm.network "private_network", ip: "0.0.0.0",
virtualbox__intnet: "lan2"
bridge.vm.provision :shell, inline: $bridge_script
end
config.vm.define "machine2" do |machine2|
machine2.vm.box = "hashicorp/precise64"
machine2.vm.network "private_network", ip: "192.168.1.3",
virtualbox__intnet: "lan2"
end
end
I can't get either machine to ping the other successfully. Using tcpdump
I found that an ARP request get passed from machine1
all the way to machine2
, but when machine2
responds, the response does not even get to eth2
on bridge
. (I only see the ARP response when listening on eth1
in machine2
.
How can I get this to work?
Turns out that by default VirtualBox doesn't let you have promiscuous NICs, you have to explicitly enable it.
I added the following lines to the
bridge
definition and things started to work: