Vagrant Virtualbox 覆盖默认网络接口

Vagrant Virtualbox Override Default Network Interface

我想覆盖 "Adapter 1" 并将其从默认 NAT 更改为桥接。

这是使用 VirtualBox 的 MacOSX

下面是我的无脑尝试:

NODE_COUNT = 5
NODE_COUNT.times do |i|
    node_id = "mes00#{i += 1}"
    config.vm.define node_id do |node|

    # $network_interface could either be en0 or en1 depending in which is up
    node.vm.network :public_network,  :type => "dhcp",:bridge =>     $network_interface,:interface => 1
    node.vm.network :private_network, :ip => "192.168.0.1#{i}",:interface => 2
    node.vm.box = "ubuntu/trusty64"
    node.vm.hostname = "#{node_id}"
  end
end

输出显示:

==> mes004: Preparing network interfaces based on configuration...        
mes004: Adapter 1: nat
mes004: Adapter 2: bridged
mes004: Adapter 3: hostonly

至于 vagrant,第一个 nic 总是 nat。是设计使然。

如果您分享您遇到的问题,可能是所有这些问题的解决方法。