Ubuntu – How to ssh between a cluster of Vagrant guest VMs

ubuntu 12.04vagrantvirtualbox

I have 3 Ubuntu 12.04 VMs configured with bridged networking and setup with Vagrant. I can access all of them from the host using "vagrant ssh", but I can't figure out how I connect from one guest VM to another.

Best Answer

In the Vagrantfile give each of the machines a static private address.

Vagrant.configure(2) do |config|
    config.vm.define "master" do |master|    
        master.vm.box = "ubuntu/trusty64"
        # You may wish to use a more obscure private ip, like 10.2.2.4
        master.vm.network "private_network", ip: "10.0.0.200"
    end
    config.vm.define "slave" do |slave|    
        slave.vm.box = "ubuntu/trusty64"
        # You may wish to use a more obscure private ip, like 10.2.2.5
        slave.vm.network "private_network", ip: "10.0.0.201"
    end
End

With these machines both booted you can first ssh into one by name

vagrant ssh master

And from within this session you can ssh to another machine via its private network ip:

ssh 10.0.0.201

When prompted for a user/password you can authenticate as vagrant/vagrant, or further configure an ssh for yourself.


This information was adapted from the following post[1]:

  1. Vagrant Virtual Machine Cluster Jesse - jessesnet 2014-04-22. Retrieved 2015-02-26