Multi-host Vagrant and Private Networks

- - posted in vagrant | Comments

Problems accessing HTTP applications using the IP of your Vagrant boxes?

I have three Vagrant boxes all provisioned from a single Vagrantfile. The HTTP apps where starting up fine and if I ssh in to the machine I could curl localhost:3000 and get the expected response.

However while the guest machines where up and pingable from the host I got no response from the HTTP port.

The problem it turns out is Ubuntu has the ufw firewall installed which blocks all incoming connections by default.

When provisioning the machine either disable the firewall or punch a hole in it for your ports:

1
sudo ufw disable
1
sudo ufw allow 3000/tcp

Here is a snippet from my Vagrantfile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.define "jukebox" do |jb|
    jb.vm.network "private_network", ip: "192.168.1.1"
    jb.vm.hostname = "jukebox.dev"

    $script = <<-SCRIPT

    sudo ufw allow 3000/tcp

    # ...

    SCRIPT

    jb.vm.provision "shell", inline: $script
  end
end

Comments