连接来自两台物理主机的虚拟子网

我有proxmox 4基于debian 8在两个主机A和B.都有两个网卡。 每个主机的一个NIC通过交叉电缆连接。

Host A: eth0: public IP eth1: 10.0.0.2/24 vmbr1: 10.0.0.1/24 Host B: eth0: public IP eth1: 10.0.1.2/24 vmbr1: 10.0.1.1/24 

在vmbr1上,每个主机上都附有一个容器,其中包含10.0.x.10。 我会这样表示:

 Host A: veth100i1@if12: 10.0.0.10/24 (IP only visible inside container on eth0) Host B: veth100if1@if30: 10.0.1.10/24 (IP only visible inside container on eth0) 

路由表主机A:

 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 XXXX 0.0.0.0 UG 0 0 0 eth0 XXX0 XXXX 255.255.255.224 UG 0 0 0 eth0 XXX0 0.0.0.0 255.255.255.224 U 0 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 vmbr1 10.0.1.0 10.0.0.2 255.255.255.0 UG 0 0 0 eth1 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 

路由表主机B:

 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 YYYY 0.0.0.0 UG 0 0 0 eth0 YYY0 YYYY 255.255.255.224 UG 0 0 0 eth0 YYY0 0.0.0.0 255.255.255.224 U 0 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.0.0.0 10.0.1.2 255.255.255.0 UG 0 0 0 eth1 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 vmbr1 

从主机AI可以ping通

  • 它的容器在10.0.0.10
  • 主机的B eth1 10.0.1.2
  • 在10.0.1.1上的主机B vmbr1
  • 但不包括10.0.1.10上的Host B容器

从主机BI可以ping通

  • 它的容器在10.0.1.10
  • 主机在10.0.0.2上的eth1
  • 主机的10.0.1.1上的vmbr1
  • 但不在10.0.0.10上的Host's A容器上

当我尝试从主机BI的容器上的主机A ping 10.0.1.10时,可以在主机B的eth1上看到以下内容:

 tcpdump -nni eth1 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes 12:42:48.567438 ARP, Request who-has 10.0.1.10 tell 10.0.0.2, length 46 

在主机B的vmbr1上,tcpdump什么也没有显示。

如何将数据包路由到其他主机的容器?

尝试将eth1接口设置为第三个子网(如10.0.3.0/24)中的地址。 您可能还需要添加转发,如下所示。

或者尝试代理可用服务器的ARP请求。 您可以使用类似命令手动启用此function。

 systctl -w net.ipv4.conf.eth1.proxy_arp=1 

一旦你有它的工作,你可以坚持重新启动,通过在/etc/sysctl.d中添加一个文件,包含一行如下:

 net.ipv4.conf.eth1.proxy_arp = 1 

您可能还需要使用以下任一设置启用启用转发:

 net.ipv4.conf.all.forwarding = 1 net.ipv4.conf.eth1.forwarding = 1 

另一种方法是在vmbr1定义中包含eth1。 从长远来看,这可能是一个更好的方法。