5

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?

1 Answer 1

6

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.

2
  • 2
    For newer versions try systemctl stop firewalld.service Apr 20, 2018 at 15:23
  • I run into this every time in this exact situation, and every time it surprises and frustrates me. Jan 6, 2021 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .