"No route to host": understanding networking between Vagrant VMs

13,495

Turns out this was just the iptables on the base box tripping me up. Switching this off (service iptables stop to temporarily disable the firewall) allowed me to route between the two machines.

Share:
13,495

Related videos on Youtube

Nathaniel Waisbrot
Author by

Nathaniel Waisbrot

I work as a software engineer where I mostly write server-side or dev-ops-y code.

Updated on September 18, 2022

Comments

  • Nathaniel Waisbrot
    Nathaniel Waisbrot over 1 year

    I'd like to have a pair of VMs with a network between them. I made the following Vagrantfile

    VAGRANTFILE_API_VERSION = "2"
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      config.vm.define :alpha do |alpha|
        alpha.vm.box = "centos-6.4"
        alpha.vm.network :private_network, ip: "192.168.50.2"
    
        alpha.vm.provision "shell", inline: "yum install -y nc"
      end
    
      config.vm.define :beta do |beta|
        beta.vm.box = "centos-6.4"
        beta.vm.network :private_network, ip: "192.168.50.10"
        beta.vm.provision "shell", inline: "yum install -y nc"
      end
    end
    

    At first, I thought that things were working, because I can do

    vagrant ssh alpha

    and then

    ping 192.168.50.10

    or

    ssh 192.168.50.10

    And those both work. But it looks like it's actually only those two operations that work. If I have beta listen on port 3000 and try to connect to it, I can't:

    $ ssh -p3000 192.168.50.10
    ssh: connect to host 192.168.50.10 port 3000: No route to host
    

    How can I get it so that all traffic can pass between the two VMs?

    I've got VirtualBox 4.2.18 as the provider and Vagrant 1.3.3

    Edit: After more experimentation, I can reproduce this with CentOS on VirtualBox alone, and if I change the base-box to an Ubuntu one, I do not have this problem (with no other changes to the Vagrantfile). Is this a problem with networking with CentOS on VirtualBox?

  • TheFiddlerWins
    TheFiddlerWins about 6 years
    For newer versions try systemctl stop firewalld.service
  • Cory Ringdahl
    Cory Ringdahl over 3 years
    I run into this every time in this exact situation, and every time it surprises and frustrates me.