我有以下Vagrantfile
定义了许多(multi-machine)VM:
Vagrant.configure(2) do |config|
for i in 1..3 do
config.vm.define "vm#{i}" do |c|
c.vm.box = "ubuntu/xenial64"
c.vm.network "public_network", ip: "192.168.0.#{i + 100}"
c.vm.network :forwarded_port, guest: 22, host: rand(2000...4000), id: 'ssh'
end
end
end
执行vagrant up
后,每个VM都具有相同的eth1
接口:
eth1 Link encap:Ethernet HWaddr 08:00:27:43:e7:4f
inet addr:192.168.0.103 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: 2607:b400:26:0:a00:27ff:fe43:e74f/64 Scope:Global
inet6 addr: fe80::a00:27ff:fe43:e74f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:59 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10065 (10.0 KB) TX bytes:3832 (3.8 KB)
我希望每个VM都有一个单独的IP,但每个都奇怪地采用IP 192.168.0.103
。如果我将ip
规范省略为public_network
,则每个VM的eth1
IP都不同。
如何在多机Vagrantfile
中配置多个网桥IP?
答案 0 :(得分:0)
我猜它是红宝石警告之一(你可以在网上阅读Closures and for loops in Ruby和其他可能的资源)
基本上取代你的循环
for i in 1..3 do
等效
(1..3).each do |i|