22

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?

mjk
  • 2,443
  • 4
  • 33
  • 33
Clutch
  • 7,404
  • 11
  • 45
  • 56

1 Answers1

36

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
BrianC
  • 10,591
  • 2
  • 30
  • 50
  • 2
    I can't believe how easy it is. Huzzah! – Matt Scheurich Oct 24 '16 at 08:28
  • @BrianC I know I should have started a new thread instead..., Can you suggest me something similar for windows host with two Kali linux guestOS? – StackUseR Jan 05 '17 at 12:32
  • @AshishSrivastava give it a try using my template above as an example, but using the Kali Linux vagrant box names instead. If you can't get it to work, create a new question with the details of what you've tried and I can take a look. – BrianC Jan 05 '17 at 18:41
  • 3
    Some more detail here: https://www.vagrantup.com/docs/multi-machine/. It says "The moment more than one machine is defined within a Vagrantfile, the usage of the various vagrant commands changes slightly. The change should be mostly intuitive. "Commands that only make sense to target a single machine, such as vagrant ssh, now require the name of the machine to control. Using the example above, you would say vagrant ssh alpha or vagrant ssh beta." – Anthony Jul 22 '18 at 11:47