通过Vagrant在同一接口上设置多个静态地址



因此,在尝试将手动安装说明转换为Vagrant设置VM时,我对如何使/etc/network/interfaces文件具有以下内容感到困惑:

auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
auto eth1:1
iface eth1:1 inet static
address 192.168.56.102
netmask 255.255.255.0
auto eth1:2
iface eth1:2 inet static
address 192.168.56.103
netmask 255.255.255.0

这些接口都在VirtualBox中的VM上使用仅主机适配器。

我知道我可以创建三个单独的适配器,并使用相同的主机专用适配器,这样做:

config.vm.network "private_network", ip: "192.168.56.101"
config.vm.network "private_network", ip: "192.168.56.102"
config.vm.network "private_network", ip: "192.168.56.103"

但这显然与上面的文件不匹配。我宁愿没有一些黑客的解决方案重写/etc/network/接口在启动/关闭,但我似乎不能让Vagrant工作,找不到任何其他除了非常简单的教程。

我不确定您是否可以使用默认网络配置。

我尝试了一些选项,使用一些参数

config.vm.network "private_network", ip: "192.168.50.101", :device => "eth1", :adapter => 1, :netmask => "255.255.255.0"
config.vm.network "private_network", ip: "192.168.50.102", :device => "eth1:1", :adapter => 1, :netmask => "255.255.255.0"
config.vm.network "private_network", ip: "192.168.50.103", :device => "eth1:2", :adapter => 1, :netmask => "255.255.255.0"

但是这将使VM不能启动或者每个接口都有自己的接口。

然后查看https://docs.vagrantup.com/v2/networking/public_network.html/DISABLE AUTO-CONFIGURATION,您可以执行以下操作

# manual ip
config.vm.network "public_network", auto_config: false
config.vm.provision "shell",
  run: "always",
  inline: "ifconfig eth1 192.168.50.101 netmask 255.255.255.0 up"
config.vm.provision "shell",
  run: "always",
  inline: "ifconfig eth1:1 192.168.50.102 netmask 255.255.255.0 up"
config.vm.provision "shell",
  run: "always",
  inline: "ifconfig eth1:2 192.168.50.103 netmask 255.255.255.0 up"

在VM上运行ifconfig -a时,得到

eth0      Link encap:Ethernet  HWaddr 00:0c:29:e5:fe:e1
          inet addr:172.16.42.238  Bcast:172.16.42.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee5:fee1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:766 errors:0 dropped:0 overruns:0 frame:0
          TX packets:489 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:83256 (83.2 KB)  TX bytes:69904 (69.9 KB)
eth1      Link encap:Ethernet  HWaddr 00:0c:29:e5:fe:eb
          inet addr:192.168.50.101  Bcast:192.168.50.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee5:feeb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:125 errors:0 dropped:20 overruns:0 frame:0
          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:10180 (10.1 KB)  TX bytes:1478 (1.4 KB)
eth1:1    Link encap:Ethernet  HWaddr 00:0c:29:e5:fe:eb
          inet addr:192.168.50.102  Bcast:192.168.50.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
eth1:2    Link encap:Ethernet  HWaddr 00:0c:29:e5:fe:eb
          inet addr:192.168.50.103  Bcast:192.168.50.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

最新更新