Vagrant(Virtualbox)仅主机多节点网络问题

Vagrant(Virtualbox)仅主机多节点网络问题

我正在尝试使用多 VM 流浪环境作为部署 OpenStack 的测试平台,并且在尝试从一个 VM 到 VM 内部的 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 接口都已设置为混杂模式。

答案1

问题在于必须通过 Vagrant 将接口设置为混杂模式,在客户操作系统内部执行此操作是不够的。

例如,如果您添加了两个 NIC,并且您定义的最后一个 NIC 是将桥接到虚拟机的 NIC,那么您的 Vagrantfile 应该包含以下内容:

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

相关内容