Alqio
Alqio

Reputation: 472

Vagrant cannot connect to two virtualbox internal networks

I have Vagrantfile with three boxes: lab1, lab2 and lab3. The idea is to have VirtualBox internal network between lab1 and lab2 (called intnet1) and lab1 and lab3 (called intnet2). This should allow to ssh from lab1 to lab2 and lab3, but not from lab2 to lab3 and vice versa. This is the relevant part of my Vagrantfile:

  config.vm.define "lab1" do |lab1|
    lab1.vm.network "private_network", ip: "192.168.50.3", virtualbox__intnet: "intnet2"
    lab1.vm.network "private_network", ip: "192.168.50.4", virtualbox__intnet: "intnet1"

    lab1.vm.network "forwarded_port", guest: 22, host: 10001, host_ip: "127.0.0.1"
  end

  config.vm.define "lab2" do |lab2|
    lab2.vm.network "private_network",  ip: "192.168.50.5", virtualbox__intnet: "intnet1"

    lab2.vm.network "forwarded_port", guest: 22, host: 10002, host_ip: "127.0.0.1"
  end

  config.vm.define "lab3" do |lab3|
    lab3.vm.network "private_network", ip: "192.168.50.6", virtualbox__intnet: "intnet2"

    lab3.vm.network "forwarded_port", guest: 22, host: 10003, host_ip: "127.0.0.1"
  end

The problem is that only the network that was configured first in lab1 works. So with this setup, I can only connect to lab3 from lab1, not to lab2. Trying to connect to 192.168.50.5 (lab2's ip) with SSH yields ssh: connect to host 192.168.50.5 port 22: No route to host.

In addition, if I manually check the box network preferences from VirtualBox, it shows that lab1 is connected to intnet2 with Adapter 2 and intnet1 with Adapter3.

What is the prolem here? How can I connect to both lab2 and lab3 from lab1?

Upvotes: 0

Views: 342

Answers (1)

Alqio
Alqio

Reputation: 472

The solution was to have intnet1 and intnet2 in two different subnetworks.

Upvotes: 1

Related Questions