Vagrant - 2 个虚拟机具有相同的 IP

Vagrant - 2 VMs have same IP

我正在尝试玩木偶。所以我使用 vagrant 启动了两个 debian 实例。我的 Vagrantfile 看起来像这样

Vagrant.configure("2") do |config|

  config.vm.define "puppetagent" do |puppetagent|
    puppetagent.vm.box = "puphpet/debian75-x64"
    puppetagent.vm.hostname = "puppetagent.example.com"
    puppetagent.vm.network "private_network",ip: "192.168.10.21"
  end

  config.vm.define "puppetmaster" do |puppetmaster|
    puppetmaster.vm.box = "puphpet/debian75-x64"
    puppetmaster.vm.hostname = "puppetmaster.example.com"
    puppetmaster.vm.network "private_network",ip: "192.168.10.22"
  end

然而,当我通过 ssh 进入两个实例并查看 /etc/hosts 文件(在两个实例上)如下所示:

# master - instance1

127.0.0.1   localhost
127.0.1.1 puppetmaster.example.com puppetmaster

# agent - instance2

127.0.0.1   localhost
127.0.1.1 puppetagent.example.com puppetagent

我对此感到困惑。我确实为两者指定了不同的 IP,但为什么它在 hosts 文件中显示相同的 IP?

我可以猜测您是 运行 基于 debian 的 VM 吗?

127.0.1.1 行,虽然不是 debian 特性 本身 是由 debian 安装程序添加的,如 debian manual 中所述。并非所有 Unice 都这样做。

这是环回地址,与您 VM 的实际 IP 地址无关,无论您是否使用 debian。

如果你想让 vagrant 更新 /etc/hosts,你需要使用像 Vagrant hostmanager.

这样的插件