在ssh-DNAT之后的机器1的日志中的火星源到位于机器2上的虚拟机(机器1和机器2的xover连接)

我的场景

在这里输入图像说明

  • 2个物理机器,每个物理机器有2个networking接口(eth0,eth1)。
  • 他们充当虚拟机主机
  • 只有一台机器,networking工作没有问题
  • 首先我有两个分离的networking,每台机器都有一个自己的虚拟DHCP服务器运行
  • 然后我试图将分离的networking合并为一个
  • 防火墙:shorewall(lan的连接策略=允许在两台机器上)
  • dhcp服务器:dnsmasq
  • 两台机器都可以连接到互联网

我想通过交叉连接两台机器,并希望他们共享一个networking,所以我只有一个DHCP服务器与一个networking,每个服务器在这个局域网可以连接到对方。 这是有道理的,或者是两个独立的DHCP服务器和networking更好的方式?

问题

下面我添加了一些configuration,我做了一些连接testing。

总之

  • machine1 + machine2可以在machine1上达到ips
  • 机器1 +机器2无法到达机器2上的ips
  • machine1 + machine2可以在machine2上达到ips
  • 外部dnat(例如ssh)对machine1(端口5678 – > 10.62.63.20:22)
  • 外部dnat(例如ssh)不能用于machine2(端口5678 – > 10.62.63.30:22)

如果我SSH连接到machine1端口5678到10.62.62.20的连接工作,我只能从machine1上的连接看到shorewall日志条目。 但如果我连接到machine2端口5678连接不起作用,我可以看到machine1上的火星日志

Nov 29 15:26:57 machine1 kernel: [ 7495.749894] martian source **ssh.client.ip.addr** from **yyy.yyy.yyy.yyy**, on dev br1 

机器概述

machine1虚拟机:

  • dhcp 10.62.63.2
  • web1 10.62.63.20

machine2虚拟机:

  • web2 10.62.63.30

configuration文件

machine1 / etc / shorewall /规则

 ***snip*** DNAT:debug net lan:10.62.63.20:22 tcp 5678 - xxx.xxx.xxx.xxx ***snip*** 

machine2 / etc / shorewall /规则

 ***snip*** DNAT:debug net lan:10.62.63.30:22 tcp 5678 - yyy.yyy.yyy.yyy ***snip*** 

machine1 / etc / networking / interfaces

 # Loopback device: auto lo iface lo inet loopback # device: eth0 #allow-hotplug eth0 auto eth0 iface eth0 inet manual # device: eth1 #allow-hotplug eth1 auto eth1 iface eth1 inet manual auto br0 iface br0 inet static address xxx.xxx.xxx.xxx broadcast xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gateway xxx.xxx.xxx.xxx bridge_ports eth0 bridge_fd 0 bridge_hello 2 bridge_maxage 12 bridge_maxwait 0 bridge_stp off auto br1 iface br1 inet static address 10.62.63.1 broadcast 10.62.63.255 netmask 255.255.255.0 bridge_ports eth1 bridge_fd 0 bridge_hello 2 bridge_maxage 12 bridge_maxwait 0 bridge_stp off 

machine2 / etc / networking / interfaces

 # Loopback device: auto lo iface lo inet loopback # device: eth0 #allow-hotplug eth0 auto eth0 iface eth0 inet manual # device: eth1 #allow-hotplug eth1 auto eth1 iface eth1 inet manual auto br0 iface br0 inet static address yyy.yyy.yyy.yyy broadcast yyy.yyy.yyy.yyy netmask yyy.yyy.yyy.yyy gateway yyy.yyy.yyy.yyy bridge_ports eth0 bridge_fd 0 bridge_hello 2 bridge_maxage 12 bridge_maxwait 0 bridge_stp off auto br1 iface br1 inet static address 10.62.63.3 broadcast 10.62.63.255 netmask 255.255.255.0 bridge_ports eth1 bridge_fd 0 bridge_hello 2 bridge_maxage 12 bridge_maxwait 0 bridge_stp off 

testing

machine1(10.62.63.1)

路线:

 ip route show yyy.yyy.yyy.yyy/yy dev br0 proto kernel scope link src yyy.yyy.yyy.yyy 10.62.63.0/24 dev br1 proto kernel scope link src 10.62.63.1 default via yyy.yyy.yyy.yyy dev br0 
  • ping 10.62.63.3到br1 ip(remote):ok
  • ping 10.62.63.1到br1 ip(local):ok
  • ping 10.62.63.2到dns(本地):ok
  • ping 10.62.63.20到web01(本地):好的
  • ping 10.62.63.30到web02(远程):好的
  • ssh 10.62.63.20到web01(本地):好的
  • ssh 10.62.63.30到web02(远程):好的

machine2(10.62.63.3)

路线:

 ip route show yyy.yyy.yyy.yyy/yy dev br0 proto kernel scope link src yyy.yyy.yyy.yyy 10.62.63.0/24 dev br1 proto kernel scope link src 10.62.63.3 default via yyy.yyy.yyy.yyy dev br0 
  • ping 10.62.63.3到br1 ip(local):ok
  • ping 10.62.63.1到br1 ip(remote):ok
  • ping 10.62.63.2到dns(远程):好的
  • ping 10.62.63.20到web01(远程):ok
  • ping 10.62.63.30到web02(本地):好的
  • ssh 10.62.63.20到web01(远程):ok
  • ssh 10.62.63.30到web02(本地):好的

问题是出站数据包,而不是入站。

dhcp服务器为两台机器提供了相同的网关(10.62.63.1),所以dnat机器上的入站数据包到达他们的位置(machine2上的web)没有问题,但是返回的数据包被发送到machine1的网关(10.62。 63.1)而不是来自何处(10.62.63.3)。

所以它作为martion包在machine1上。

解决方法是在dns(dnsmasq)上添加标签,以便不同主机上的虚拟机获得不同的网关:

/etc/dnsmasq.conf

 *** snip *** dhcp-host=set:machine1,ff:ff:ff:ff:ff:ff,web01,10.62.63.20 dhcp-host=set:machine2,ee:ee:ee:ee:ee:ee,web02,10.62.63.30 dhcp-option=tag:machine1,option:router,10.62.63.1 dhcp-option=tag:machine2,option:router,10.62.63.3 *** snip ***