0

I have configured a multi-machine Vagrant file with two VMs acting as a mini failover active-passive cluster.

As the running services are the same and running on the same port, Vagrant doesn't allow me to port-forward the same port twice on my host, so I can't access them nor the Vagrant won't run the second VM successfully.

I tried to bypass the port-forwarding by putting VMs on my real network with public_network option ( which is kind like --net=host in docker ? ), but that doesn't solve the problem.

030
  • 5,901
  • 13
  • 68
  • 110
  • Please add the vagrant file and explain what you are trying to achieve. If you boot multiple VMs using vagrant then different IPs need to be assigned so how is this possible: `As the running services are the same and running on the same port`? – 030 Jul 08 '15 at 21:16
  • Thank you for your comment, but I have found the solution in the meantime and I have provided it below. Thanks anyway :) –  Jul 08 '15 at 21:48

1 Answers1

0

The right thing to do is:

  • set your VMs on your physical network and give them static IPs and set netmask as well:

    config.vm.define "vm1" do |vm1|
        vm1.vm.hostname = "vm1"
        vm1.vm.network "public_network", ip: "192.168.x.y", bridge: "wlan0", netmask: "255.255.255.0"
    end
    
    config.vm.define "vm2" do |vm2|
        vm2.vm.hostname = "vm2"
        vm2.vm.network "public_network", ip: "192.168.x.y", bridge: "wlan0", netmask: "255.255.255.0"
    end
    

Like this the VMs appear as physical servers on my network and no port-forwarding is necessary ( like in docker with --net=host parameter ).

At first my services were only accessible from the host on which Vagrant was running until I have figured out that I need to supply the netmask option as well, and boom, after the next vagrant reload every other device in my local network can now access those services as well.

I have stump upon the solution via this thread.

I think that the official Vagrant docs should be updated to include that option as I couldn't find it initially there, and it's an important one.