How do we change default ip address

29 views
Skip to first unread message

Jason Chu

unread,
May 20, 2019, 7:42:43 PM5/20/19
to Vagrant
Hi , I need to launch multiple ubuntu virtual machines with virtual box, so I created two different folders for two different vagrantfile  files, they did create separate virtual box vm in separate folders, however I noticed when I try to have those machines ping each other, all their ip address (from ifconfig output) shows up as 10.0.2.15, so looks like they are NAT network within Virtual box network,  how can I change the vagrant VMs using static ip and still able to use "Vagrant ssh" command, would it break it ?


thanks

Dennis Chang

unread,
May 20, 2019, 7:47:04 PM5/20/19
to Vagrant
Hi Jason,

You can configure a private_network and assign IP addresses to both machines (on the same subnet).
That will allow the two machines to talk to each other. You'll notice the NAT interface will still be there, but a new interface will be created.

Vagrant ssh will continue to work as you'll notice when the machine comes up that there is port forwarding involved.
So the first VM will have port 2222 (host port) forwarded to port 22 (inside the VM).
The second VM will see port 2222 already taken and will assign 2200 (host port) forwarded to port 22 (inside VM).


Alvaro Miranda Aguilera

unread,
May 22, 2019, 9:18:15 PM5/22/19
to vagra...@googlegroups.com
hello

you can do multi machine on same vagrant file and use private_network to allow intra vm networking

example
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# global
config.vm.box = "alvaro/xenial64"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
# server
config.vm.define "server" do |server|
server.vm.hostname = "server"
server.vm.network "private_network", ip: "192.168.56.20"
end
# client
(1..2).each do |i|
config.vm.define "client#{i}" do |vm|
vm.vm.hostname = "client#{i}"
vm.vm.network "private_network", ip: "192.168.56.#{30+i}"
end
end
end


On Mon, May 20, 2019 at 7:42 PM Jason Chu <jcck...@gmail.com> wrote:
Hi , I need to launch multiple ubuntu virtual machines with virtual box, so I created two different folders for two different vagrantfile  files, they did create separate virtual box vm in separate folders, however I noticed when I try to have those machines ping each other, all their ip address (from ifconfig output) shows up as 10.0.2.15, so looks like they are NAT network within Virtual box network,  how can I change the vagrant VMs using static ip and still able to use "Vagrant ssh" command, would it break it ?


thanks

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/aba58197-6b8a-4777-bc04-6e8983a0ce3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alvaro

Reply all
Reply to author
Forward
0 new messages