Vagrant:如何在一个Vagrantfile中配置多个NIC?
收藏

官方文档仅提供了1个IP的示例:

http://docs.vagrantup.com/v2/networking/private_network.html

Vagrant.configure("2") do |config|
  config.vm.network "private_network", ip: "192.168.50.4"
end

谷歌搜索我只能找到多个IP的一个示例:

https://groups.google.com/forum/#!topic/vagrant-up/hqtdOEjjlsw

Vagrant::Config.run do |config|
  config.vm.define :web001 do |config|
    config.vm.box = "base"
    config.vm.forward_port("http", 5000, 8881)
    config.vm.forward_port("ssh", 22, 2222)
    config.vm.host_name = "web001.example.com"
    config.vm.network("33.33.33.10")
    config.vm.network("33.33.33.20", {:adapter=>2})
  end
end 

但这对我不起作用...

任何帮助将不胜感激....

最佳答案

使用Vagrant 1.6.1和Virtualbox的专用网络,您只需重复config.vm.network定义即可创建多个专用ip:

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "precise64"

  config.vm.network "private_network", ip: "192.168.50.4"
  config.vm.network "private_network", ip: "192.168.50.5"
  config.vm.network "private_network", ip: "192.168.50.6"
  config.vm.network "private_network", ip: "192.168.50.7"

end

    公众号
    关注公众号订阅更多技术干货!