Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a vagrant config file with three VMs configured in it. All are identical except on has a static IP and the other two are on DHCP. The two which are assigned IPs by DHCP can talk to each other without any issues, but the one with a static IP cannot be contacted by the others.

In other words ping client0 -> client1 works

ping client1 -> client0 works

ping client1 -> server does not

This is my Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.provision "chef_solo" do |chef|
    chef.cookbooks_path = "provision/cookbooks"
    chef.add_recipe "apt"
    chef.add_recipe "python"
  end

  config.vm.provision :shell, :path => "provision/python-modules.py"

  config.vm.define :server do |server|
    server.vm.hostname = "server"
    server.vm.network :private_network, ip: "172.28.128.2"
  end

  config.vm.define :client0 do |client0|
    client0.vm.hostname = "client0"
    client0.vm.network :private_network, type: :dhcp
  end

  config.vm.define :client1 do |client1|
    client1.vm.hostname = "client1"
    client1.vm.network :private_network, type: :dhcp
  end
end

Any ideas how I can get the server machine to be contactable by the others on a static IP? I'm using the virtualbox providor.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

After extensive research and experimentation is appear the Vagrant was assigning each VM to a different submask, hence them not being able to connect to each other. In effect, they were all on different networks.

It turns out you can, however, override this. To do so simply configure the netmask for one as shown below.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.provision "chef_solo" do |chef|
    chef.cookbooks_path = "provision/cookbooks"
    chef.add_recipe "apt"
    chef.add_recipe "python"
  end

  config.vm.provision :shell, :path => "provision/python-modules.py"

  config.vm.define :server do |server|
    server.vm.hostname = "server"
    server.vm.network :private_network, ip: "172.28.128.2", :netmask => "255.255.0.0"
  end

  config.vm.define :client0 do |client0|
    client0.vm.hostname = "client0"
    client0.vm.network :private_network, type: :dhcp, :netmask => "255.255.0.0"
  end

  config.vm.define :client1 do |client1|
    client1.vm.hostname = "client1"
    client1.vm.network :private_network, type: :dhcp, :netmask => "255.255.0.0"
  end
end

At this time I am unsure as to weather you can override the netmask for all on the global config, while maintaining some VMs with DHCP and other with a static IP. I'll experiement with that once I'm am back on a more powerful machine so destroying and creating the VM each time is faster.

share|improve this answer
add comment

You could also done something like below, if you provisioning multiple VM's with DHCP. In optional VM section you can mention/name multiple VM's you required.

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = '2'

DOMAIN = '.example.com'
PUPPETMASTER_HOSTNAME = 'puppet' + DOMAIN

#Requires box with puppetlabs repo setup, but puppet not installed
DEFAULT_BOX = 'precise64'
DEFAULT_BOX_URL = 'http://files.vagrantup.com/precise64.box'

REQUIRED_HOSTS = [
  'puppetdb',
  'puppetdb-postgres'
]

OPTIONAL_HOSTS = [
  'ldap01',
  'ldap02'

]

HOSTS = REQUIRED_HOSTS + OPTIONAL_HOSTS

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  #VBox config to avoid mac address collisions
  config.vm.provider :virtualbox do |vb|
    vb.customize ['modifyvm', :id, '--natnet1', '10.200/16']
    #vb.gui = true
  end

  config.vm.box = DEFAULT_BOX
  config.vm.box_url = DEFAULT_BOX_URL

  #Add network interface
  config.vm.network :private_network, :type => :dhcp, :netmask => '255.255.0.0'

  #Defines puppet master
  config.vm.define :puppet_master do |puppetmaster|
    puppetmaster.vm.hostname = PUPPETMASTER_HOSTNAME
    puppetmaster.vm.synced_folder '../puppet/', '/vagrant_sync/puppet', :create => true
    puppetmaster.vm.provision :shell, :path => 'scripts/bootstrap_puppetmaster.sh'
  end

  HOSTS.each do |host_name, opts|
    config.vm.define host_name do |box|
      fqdn = host_name + DOMAIN

      box.vm.hostname = fqdn
      box.vm.provision :shell, :inline => 'yum install -y puppet'
      box.vm.provision :puppet_server do |puppet|
        puppet.puppet_server = PUPPETMASTER_HOSTNAME
      end
    end
  end
end
share|improve this answer
    
Excellent solution, thanks for sharing this. I'll have to update my local configuration file now, this is a much cleaner solution when multiple identical client are required for testing. Thanks! –  Daniel Groves Jan 30 at 21:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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