11

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.

6

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
4

I've just fixed this up in a complex multi CentOS (BoxCutter 6.9) VM Vagrant setup. There are two levels to this problem, my problem was 2:

  1. Get your Vagrant config right so that you have a "private_network" and the IP addresses of all your VM's are in the same subnet (static or DHCP): https://www.vagrantup.com/docs/networking/private_network.html

  2. When ssh'ing between VM's if you get this error: [root@vm01 ~]# ssh root@vm02 Permission denied (publickey,gssapi-keyex,gssapi-with-mic). The error message means that none of the authentication methods managed to authenticate your session, and there is no mention of a password option so password authentication has probably been disabled. To fix edit /etc/ssh/sshd_config and check that you have PasswordAuthentication yes and it's not commented out (#), then restart sshd if required: service sshd restart (it won't disconnect any sesssions coz it's clever).

1

If you have set them up with a bridged interface, it means they all belong to your standard LAN. Thus you can easily access a VM from another VM by issuing

 ssh myname@ip_of_vm_2

You can find the IPs of your machines either directly from inside each machine, or by using a standard tool like nmap, or by asking your router the list of DHCP clients. Lastly, if you know their IP addresses but not their BIOS names, you can use nmbd to associate a name to an IP address:

 nmblookup -A IP_address

Incidentally, this ease of access (which sets your VMs on the same foot as your LAN pcs) is one of the reason why I always use the bridged interface.

2
  • Thanks. I think the complication comes from the fact that I am trying to bridge using my wireless interface, and wifi adapters (generally? always?) can't be put into promiscuous mode to pick up packets for other addresses. Is that a possible reason this isn't working? – IanSR Nov 8 '13 at 15:01
  • No, not true. Bridged configuration on wlan0 works perfectly, I just tried it with VirtualBox, I have three VMs all perfectly connected. – MariusMatutiae Nov 8 '13 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.