我在vagrant中运行Ubuntu,这是Vagrantfile:

# 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 = "ubuntu/trusty64"
  config.vm.network :private_network, ip: "192.168.99.4", :netmask => "255.255.255.0", auto_config: false
end

因此,我希望将192.168.99.4作为IP,但我始终有:
eth0      Link encap:Ethernet  HWaddr 08:00:27:88:ba:8f
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe88:ba8f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1      Link encap:Ethernet  HWaddr 08:00:27:9c:a9:9f
          inet6 addr: fe80::a00:27ff:fe9c:a99f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

有什么线索我做错了吗?

在这个问题上取得了一些进展,几乎就像这样:
How to switch order of network adapters in Vagrant under VirtualBox?

它是关于不使用“10.0.2.15”的,据我了解,它将在virutalbox的“NAT”设置中进行更改,无法由Vagrant管理

最佳答案

vagrant book

所以您要报告的是此NAT。
另外,在Vagrantfile中设置auto_config: false时,未定义eth1,因此基本上是在告诉vagrant您自己进行所有设置。因此您应该将此参数设置为true(或删除)或自行设置etc/network/interfaces您可以查看vagrant public network并查看是否可以使用代码段示例从配置中删除eth0网关。

  config.vm.network "public_network", ip: "192.168.0.17"

  # default router
  config.vm.provision "shell",
    run: "always",
    inline: "route add default gw 192.168.0.1"

  # default router ipv6
  config.vm.provision "shell",
    run: "always",
    inline: "route -A inet6 add default gw fc00::1 eth1"

  # delete default gw on eth0
  config.vm.provision "shell",
    run: "always",
    inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"

关于vagrant - 如何使用Vagrant定义网络设置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35208188/

10-16 09:47