1

I'm trying to configure static IPs on 2 vagrant boxes so they can communicate with each other. With the following config, the "db" node comes up with an eth1 and eth2 with 192.168.50.4 and 192.168.50.5 respectively. The second "web" node, correctly brings up only an eth1 with 192.168.50.5. Why does the first node have both addresses?

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Hello"

  config.vm.define "web" do |web|
    web.vm.box = "ubuntu/trusty64"
    config.vm.network "private_network", ip: "192.168.50.5"
  end

  config.vm.define "db" do |db|
    db.vm.box = "ubuntu/trusty64"
    config.vm.network "private_network", ip: "192.168.50.4"
  end
end
  • Did you get figure this one out? I have the same problem. – rangfu May 8 at 12:58
0

I've just tested it and it works for me. Here's the code:

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

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|


  config.vm.define "web" do |web|
    web.vm.box = "ubuntu14"
    web.vm.network "private_network", ip: "192.168.50.5"
    config.vm.hostname = "web"
    config.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id, "--memory", "256"]
        vb.customize ["modifyvm", :id, "--cpus", "1"]
#   vb.gui = true
    end
  end

  config.vm.define "db" do |db|
    db.vm.box = "ubuntu14"
    db.vm.network "public_network", ip: "192.168.50.4"
    db.vm.hostname = "db"
    config.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id, "--memory", "512"]
        vb.customize ["modifyvm", :id, "--cpus", "2"]
#   vb.gui = true
    end
  end

end

Edit:

Resulting IP configuration:

vagrant@web:~$ sudo ip ad show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:c3:8f:e9 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fec3:8fe9/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:96:2d:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.50.5/24 brd 192.168.50.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe96:2d54/64 scope link 
       valid_lft forever preferred_lft forever



vagrant@db:~$ sudo ip ad show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:c3:8f:e9 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fec3:8fe9/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:d6:b3:d1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.50.4/24 brd 192.168.50.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed6:b3d1/64 scope link 
       valid_lft forever preferred_lft forever
  • Even after a destroy and "up", I'm still seeing it. Can you confirm what interfaces are up on each node via a "sudo ifconfig"? – Peter Dec 2 '14 at 14:17
  • I've edited my reply with the "ip address show" output – Matías Dec 2 '14 at 15:26
0

Going to take a different track on this one. I use the vagrant plugin vagrant-hostmanager. You can install it with vagrant plugin install vagrant-hostmanager and my vagrant file looks like the below. I can now ping/ssh/other by hostname (e.g. ssh nfs1).

#-----------------------------------------------------#
#- Project: vagrant-based
#- Author.: jlawson
#- Date...: 2015-03-16
#- Notes..:
#-----------------------------------------------------#


VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |c|

    #-- BEGIN Plugin Config -------------------------------------------------------#

    #- Configure vagrant-hostmanager plugin
    if Vagrant.has_plugin?("vagrant-hostmanager")
        c.hostmanager.enabled = true
        c.hostmanager.manage_host = true
        c.hostmanager.ignore_private_ip = false
        c.hostmanager.include_offline = true
    else
        puts "FATAL: Vagrant-hostmanager plugin not detected. Please install the plugin with\n 'vagrant plugin install vagrant-hostmanager' from any other directory\n before continuing."
        exit
    end

    #-- END Plugin ----------------------------------------------------------------#

    c.vm.define "app1", primary: true do |app1|
      #- Instance Base & DNS
      app1.vm.box = "app1"
      app1.vm.box_url = "file:///DevOps/vm-boxes/aws/opscode_ubuntu-14.04_chef-provisionerless.box"
      app1.vm.hostname = "dev-application1.local.vm"
      app1.hostmanager.aliases = %w(dev-app1.localdomain dev-app1)

      #- Ports and IPs
      app1.vm.network(:forwarded_port, {:guest=>80, :host=>8001})
      app1.vm.network(:forwarded_port, {:guest=>443, :host=>8443})
      app1.vm.network(:private_network, {:ip=>"199.10.0.2"})

      #- Misc
      app1.ssh.forward_agent = true

      #- Instance Customizations
      app1.vm.provider :virtualbox do |p|
        p.name = app1.vm.box
        p.customize ["modifyvm", :id, "--memory", "1024"]
        p.customize ["modifyvm", :id, "--cpus", "1"]
      end

    end

    c.vm.define "nfs1", autostart: false do |nfs1|
        #- Instance Base & DNS
        nfs1.vm.box = "nfs1"
        nfs1.vm.box_url = "file:///DevOps/vm-boxes/aws/opscode_ubuntu-14.04_chef-provisionerless.box"
        nfs1.vm.hostname = "dev-nfs1.local.vm"
        nfs1.hostmanager.aliases = %w(dev-nfs1.localdomain dev-nfs1)

        #- Ports & IPs
        nfs1.vm.network(:private_network, {:ip=>"199.10.0.4"})

        #- Instance Customizations
        nfs1.vm.provider :virtualbox do |p|
          p.customize ["modifyvm", :id, "--memory", "512"]
          p.customize ["modifyvm", :id, "--cpus", "1"]
        end

    end
end

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.