2017-09-03 97 views
1

額外的橋樑,我想2通過一個Vagrantfile創建兩個虛擬機:流浪漢創建第二VM

# -*- mode: ruby -*- 
# vi: set ft=ruby : 
Vagrant.configure("2") do |config| 
    config.vm.box = "centos/7" 
    config.vm.box_version = "1707.01" 

    config.vm.define "inf-vm-01" do |node| 
    config.vm.hostname = "inf-vm-01" 
    config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.1.121" 
    end 

    config.vm.define "inf-vm-02" do |node| 
    config.vm.hostname = "inf-vm-02" 
    config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.1.122" 
    end 
end 

正如你可以看到,我想給每個客戶機和我的主機之間建立橋樑。問題是第二個虛擬機有一個額外的橋。這是IP地址的輸出:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
     inet 127.0.0.1/8 scope host lo 
      valid_lft forever preferred_lft forever 
     inet6 ::1/128 scope host 
      valid_lft forever preferred_lft forever 
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
     link/ether 52:54:00:ad:a0:96 brd ff:ff:ff:ff:ff:ff 
     inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0 
      valid_lft 86303sec preferred_lft 86303sec 
     inet6 fe80::5054:ff:fead:a096/64 scope link 
      valid_lft forever preferred_lft forever 
    3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
     link/ether 08:00:27:1b:8e:eb brd ff:ff:ff:ff:ff:ff 
     inet 192.168.1.121/24 brd 192.168.1.255 scope global eth1 
      valid_lft forever preferred_lft forever 
     inet6 fe80::a00:27ff:fe1b:8eeb/64 scope link 
      valid_lft forever preferred_lft forever 
    4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
     link/ether 08:00:27:e1:d5:bc brd ff:ff:ff:ff:ff:ff 
     inet 192.168.1.122/24 brd 192.168.1.255 scope global eth2 
      valid_lft forever preferred_lft forever 
     inet6 fe80::a00:27ff:fee1:d5bc/64 scope link 
      valid_lft forever preferred_lft forever 

什麼是錯我的流浪漢文件?

回答

0

您有錯誤的Vagrantfile,您在一個塊內使用config.vm.network,因此它對該文件有效。你應該寫這樣的(請注意,我如何使用塊內的節點1和節點變量)

# -*- mode: ruby -*- 
# vi: set ft=ruby : 
Vagrant.configure("2") do |config| 
    config.vm.box = "centos/7" 
    config.vm.box_version = "1707.01" 

    config.vm.define "inf-vm-01" do |node1| 
    node1.vm.hostname = "inf-vm-01" 
    node1.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.1.121" 
    end 

    config.vm.define "inf-vm-02" do |node2| 
    node2.vm.hostname = "inf-vm-02" 
    node2.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.1.122" 
    end 
end 

您也可以閱讀vagrant doc,特別是Defining Multiple Machines