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

Clutch picture Clutch · Jul 21, 2014 · Viewed 14.9k times · Source

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?

Answer

BrianC picture BrianC · Jul 21, 2014

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