问题
I Need to setup 2 vagrant machine with public network,so follow this link to https://www.vagrantup.com/docs/networking/public_network.html edit the Vagrantfile.
But only one machine only have public static ip. another one not get public static ip.
this is my vagrant machine configuration:
Machine 1 Vagrant File:
Vagrant.configure("2") do |config|
config.vm.box = "man2"
config.ssh.username = "vagrant"
config.vm.hostname = "www.myhost.net"
config.ssh.forward_agent = "true"
config.vm.network "public_network", ip: "192.168.1.10"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
end
Machine 2 Vagrant File:
Vagrant.configure("2") do |config|
config.vm.box = "man1"
config.ssh.username = "vagrant"
config.vm.hostname = "www.myhost.net"
config.ssh.forward_agent = "true"
config.vm.network "public_network", ip: "192.168.1.20"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=777"]
end
While Vagrant up
System Ask Which interface should the network bridge to?
I Choose Both machie as 1 "eno1"
1) eno1
2) docker0
3) veth54294ac
4) virbr0
5) vethc81d7f7
6) br-08179b343476
7) br-1d45dec94893
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
default: Which interface should the network bridge to? 1
then, Vagrant ssh Both machine
only one machine have public static ip , another machine doesn't show public ip.
if I choose Different Bridge network in any one system some think like: (machine 2) to
1) eno1
2) docker0
3) veth54294ac
4) virbr0
5) vethc81d7f7
6) br-08179b343476
7) br-1d45dec94893
option: 4 (virbro) ot others now, also same issue.
Update 1:
Before I tried Same Setup its working fine, only different Version of Vagrant and VirtualBox
Before Tried:
Fedrora 23
Vagrant 1.8.1
virtualbox 5.0
Now tried:
Fedrora 23
Vagrant 1.8.6
Virtualbox 5.1.6
Any Restrictions in this versions.
Why?
System cannot share same Bridge network ?
Suggest me how to resolve this problem.
回答1:
Your Vagrantfile
seems good to me. It may be your Machine2
IP 192.168.1.20
is assigned to other system. if assigned to other system then DHCP will not assign this IP to your machine.
if you are sure these IPs not assigned to other system then make it static
otherwise you can give like :
config.vm.network "public_network"
in This case DHCP will release IP that is available.
No need to write separate Vagrantfile
for each VM. you can create a single Vagrantfile
for multiple VM like:
Vagrant.configure("2") do |config|
config.vm.define :server1 do |server1|
server1.vm.box = "man1"
server1.vm.host_name = "vm1.example.com"
server1.vm.network "public_network", ip: "192.168.1.10"
server1.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
server1.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
end
config.vm.define :server2 do |server2|
server2.vm.box = "man1"
server2.vm.host_name = "vm2.example.com"
server2.vm.network "public_network", ip: "192.168.1.20"
server2.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
server2.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
end
end
if you want to up server1
then do
vagrant up server1
To up all VM then do
vagrant up
For ssh use like:
vagrant ssh server1
System cannot share same Bridge network ?
yes , it can share bridge network. you can create multiple VM with single bridge.
For more info you can refer Documentation
来源:https://stackoverflow.com/questions/39790510/public-network-in-vagrant