Networking

Vagrant(Virtualbox)僅主機多節點網路問題

  • December 21, 2015

我正在嘗試使用多 VM vagrant 環境作為部署 OpenStack 的測試平台,並且在嘗試從一個 VM 到 VM-inside-of-a-VM 進行通信時遇到了網路問題。

我有兩個 Vagrant 節點,一個雲控制器節點和一個計算節點。我正在使用僅主機網路。我的 Vagrantfile 看起來像這樣:

Vagrant::Config.run do |config|

 config.vm.box = "precise64"

 config.vm.define :controller do |controller_config|
   controller_config.vm.network :hostonly, "192.168.206.130" # eth1
   controller_config.vm.network :hostonly, "192.168.100.130" # eth2
   controller_config.vm.host_name = "controller"
 end

 config.vm.define :compute1 do |compute1_config|
   compute1_config.vm.network :hostonly, "192.168.206.131" # eth1
   compute1_config.vm.network :hostonly, "192.168.100.131" # eth2
   compute1_config.vm.host_name = "compute1"
   compute1_config.vm.customize ["modifyvm", :id, "--memory", 1024]
 end
end

當我嘗試啟動(基於 QEMU)的 VM 時,它在 compute1 上成功啟動,並且它的虛擬網卡(vnet0)通過網橋 br100 連接:

root@compute1:~# brctl show 100
bridge name bridge id       STP enabled interfaces
br100       8000.08002798c6ef   no      eth2

                       vnet0

當 QEMU VM 向控制器上執行的 DHCP 伺服器 (dnsmasq) 發出請求時,由於控制器上的 syslog 上的輸出,我可以看到請求到達控制器:

Aug  6 02:34:56 precise64 dnsmasq-dhcp[12042]: DHCPDISCOVER(br100) fa:16:3e:07:98:11 
Aug  6 02:34:56 precise64 dnsmasq-dhcp[12042]: DHCPOFFER(br100) 192.168.100.2 fa:16:3e:07:98:11 

但是,DHCPOFFER 永遠不會返回到在 compute1 上執行的 VM。如果我在執行 Vagrant (Mac OS X) 的主機上的 vboxnet3 介面上使用 tcpdump 觀看請求,我可以看到請求和回复

$ sudo tcpdump -i vboxnet3  -n port 67 or port 68
tcpdump: WARNING: vboxnet3: That device doesn't support promiscuous mode
(BIOCPROMISC: Operation not supported on socket)
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on vboxnet3, link-type EN10MB (Ethernet), capture size 65535 bytes
22:51:20.694040 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
22:51:20.694057 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
22:51:20.696047 IP 192.168.100.1.67 > 192.168.100.2.68: BOOTP/DHCP, Reply, length 311
22:51:23.700845 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
22:51:23.700876 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
22:51:23.701591 IP 192.168.100.1.67 > 192.168.100.2.68: BOOTP/DHCP, Reply, length 311
22:51:26.705978 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
22:51:26.705995 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
22:51:26.706527 IP 192.168.100.1.67 > 192.168.100.2.68: BOOTP/DHCP, Reply, length 311

但是,如果我在計算上的 eth2 上進行 tcpdump,我只會看到請求,而不是回复:

root@compute1:~# tcpdump -i eth2 -n port 67 or port 68
tcpdump: WARNING: eth2: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth2, link-type EN10MB (Ethernet), capture size 65535 bytes
02:51:20.240672 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
02:51:23.249758 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280
02:51:26.258281 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from fa:16:3e:07:98:11, length 280

在這一點上,我被困住了。我不確定為什麼 DHCP 回复沒有發送到計算節點。也許它與 VirtualBox 虛擬交換機/路由器的配置有關?

請注意,兩個節點上的 eth2 介面都已設置為混雜模式。

問題是必須通過 Vagrant 將介面設置為混雜模式,在客戶作業系統中這樣做是不夠的。

例如,如果您添加兩個 NIC,並且您定義的最後一個 NIC 是將橋接到 VM 的 NIC,那麼您的 Vagrantfile 應該包含以下內容:

compute1_config.vm.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]

引用自:https://serverfault.com/questions/414517