Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow two or more vagrant VMs to communicate on their own network

Tags:

I want to create multiple servers that can communicate directly with each other without using public IPs. They'll still need internet access but nothing from outside the network will need to connect to them. Creating one box usually works, but when I add additional servers the networking fails.

MacOS: 10.8.5
Virtualbox: 4.3.12
GuestOS: Ubuntu "precise64"
Using version 2 of the Vagrant config

Most of the time if I use private network I get:

saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...

Does anybody have a sample Vagrantfile that does this?

like image 932
Clutch Avatar asked Jul 21 '14 14:07

Clutch


People also ask

How do I run multiple vagrant boxes?

You can either use so called multi-machine environment to manage these boxes together in one project/Vagrantfile. They don't necessarily have to be somehow connected, ease of management may be the reason alone, e.g. if you need to start them up at the same time.

How do I set up a vagrant network?

Configure port forwarding This allows you to access a port on your own machine, but actually have all the network traffic forwarded to a specific port on the guest machine. To set up a forwarded port so you can access Apache on your guest, add the config. vm.network parameter to your Vagrantfile.

Which interface should the network bridge to vagrant?

Default Network Interface If more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.

What does vagrant configure 2 mean?

Vagrant.configure("2") do |config| # ... end. The "2" in the first line above represents the version of the configuration object config that will be used for configuration for that block (the section between the do and the end ). This object can be very different from version to version.


1 Answers

Here's an example which creates two VMs:

  • alpha 10.0.0.10
  • beta 10.0.0.11

From inside either VM you can reach the other by IP address, and can connect to the outside world.

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrant multi-machine sample setup

Vagrant.configure("2") do |config|
  config.vm.define :alpha do |alpha|
    alpha.vm.box = "hashicorp/precise64"
    alpha.vm.network :private_network, ip: "10.0.0.10"
    alpha.vm.hostname = "alpha"
  end

  config.vm.define :beta do |beta|
    beta.vm.box = "hashicorp/precise64"
    beta.vm.network :private_network, ip: "10.0.0.11"
    beta.vm.hostname = "beta"
  end
end
like image 149
BrianC Avatar answered Oct 24 '22 23:10

BrianC