Search code examples
network-programmingvagrantvirtual-machine

Vagrant Setup with two boxes connected via a third box simulating a switch/bridge


I would like to have a setup as depicted here: Suggested setup

I would like for the two VMs to only be able to talk to each other via a third container simulating a switch, or just a bridge for starters. I care about the host network or outside connectivity only to the extend that I want to ssh into each box.

I tried to build on the tutorial for multiple machines as follows:

Vagrant.configure("2") do |config|

  config.vm.define "switch" do |switch|
    switch.vm.box = "hashicorp/bionic64"
    switch.vm.network "public_network", ip: "192.168.50.6"
  end

  config.vm.define "interlocking" do |interlocking|
    interlocking.vm.box = "hashicorp/bionic64"
    interlocking.vm.network "public_network", ip: "192.168.50.5", bridge: "192.168.50.6"
  end

  config.vm.define "point" do |point|
    point.vm.box = "hashicorp/bionic64"
    point.vm.network "public_network", ip: "192.168.50.4", bridge: "192.168.50.6"
  end

end

But I don't know how to stop the two VMs from just finding each other in the network right away without using the bridge. Can somebody point me in the right direction?

A good way to do this outside of vagrant would also be fine.


Solution

  • I ended up using OpenVSwitch with this configuration in ansible:

    - hosts: all
      become: true
      tasks:
      - name: install wireshark
        apt:
          name: wireshark
      - name: install tshark
        apt:
          name: tshark
      - name: install Open vSwitch
        apt:
          name: openvswitch-switch
      - name: create bridge Interface br0
        openvswitch_bridge:
          bridge: br0
      - name: bridging ethNode1
        openvswitch_port:
          bridge: br0
          port: eth1
      - name: bridgeing ethNode2
        openvswitch_port:
          bridge: br0
          port: eth2
      - name: bridgeing ethNode3
        openvswitch_port:
          bridge: br0
          port: eth3