code-8
code-8

Reputation: 58632

update IP Address in Vagrant VMs

I have 5 VMs that I spin up using vagrant.

3 load Balancers, and 2 web servers.


VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "lb0" do |lb0|
    lb0.vm.box = "ubuntu/trusty64"
    lb0.vm.hostname = "lb0"
    lb0.vm.network :private_network, ip: "10.11.13.50"
  end
  config.vm.define "lb01" do |lb01|
    lb01.vm.box = "ubuntu/trusty64"
    lb01.vm.hostname = "lb01"
    lb01.vm.network :private_network, ip: "10.11.13.51"
  end
  config.vm.define "lb02" do |lb02|
    lb02.vm.box = "ubuntu/trusty64"
    lb02.vm.hostname = "lb02"
    lb02.vm.network :private_network, ip: "10.11.13.52"
  end

  config.vm.define "web01" do |web01|
    web01.vm.box = "ubuntu/trusty64"
    web01.vm.hostname = "web01"
    web01.vm.network :private_network, ip: "10.11.12.53"
  end

  config.vm.define "web02" do |web02|
    web02.vm.box = "ubuntu/trusty64"
    web02.vm.hostname = "web02"
    web02.vm.network :private_network, ip: "10.11.12.54"
  end
end

I just recently updated the IPs of my load balancers from 10.11.12.x --> 10.11.13.x due to the new requirement.


I run vagrant up again, I don't see new IPs updated on my lb0, lb1, and lb2. :( Did I miss anything ?


What do I do to update my existing VMs IP without having to destroy them and recreate them ?

Upvotes: 3

Views: 9192

Answers (3)

jazeb007
jazeb007

Reputation: 668

Update your Vagrantfile with the ip address available and vagrant reload to effect the changes.

Upvotes: 1

code-8
code-8

Reputation: 58632

After adjusting the new IP in Vagrantfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "lb0" do |lb0|
    lb0.vm.box = "ubuntu/trusty64"
    lb0.vm.hostname = "lb0"
    lb0.vm.network :private_network, ip: "10.11.13.50"
  end
  config.vm.define "lb01" do |lb01|
    lb01.vm.box = "ubuntu/trusty64"
    lb01.vm.hostname = "lb01"
    lb01.vm.network :private_network, ip: "10.11.13.51"
  end
  config.vm.define "lb02" do |lb02|
    lb02.vm.box = "ubuntu/trusty64"
    lb02.vm.hostname = "lb02"
    lb02.vm.network :private_network, ip: "10.11.13.52"
  end

  config.vm.define "web01" do |web01|
    web01.vm.box = "ubuntu/trusty64"
    web01.vm.hostname = "web01"
    web01.vm.network :private_network, ip: "10.11.12.53"
  end

  config.vm.define "web02" do |web02|
    web02.vm.box = "ubuntu/trusty64"
    web02.vm.hostname = "web02"
    web02.vm.network :private_network, ip: "10.11.12.54"
  end
end

I've learn that I have to run vagrant reload

Then, I noticed my IP are updated as expected.

Upvotes: 6

Frederic Henri
Frederic Henri

Reputation: 53703

This is weird, normally if you change the network configuration from the Vagrantfile, vagrant should update accordingly in your VM.

If you enable something like config.vm.network :private_network, ip: "10.11.13.52" you should see at the end of file /etc/network/interfaces something like

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
      address 10.11.13.52
      netmask 255.255.255.0
#VAGRANT-END

If you do not see your updated IP in the file, change it manually and run sudo /etc/init.d/networking restart to have the new IP available

Upvotes: 1

Related Questions