我有一个带有 2 个 NIC(eth0、eth1)的系统,我用电缆从外部连接它们
(使用交叉电缆或将它们连接到同一个交换机)。
我想要从 eth0 ping eth1 ip 地址,我想从 eth0 到 eth1 从外部(通过电缆)传输流量,但是 linux 内核在内部发送流量并且不允许它通过电缆传输,
如何我可以解决这个问题并向外部发送流量吗?
我将 ping 与“-I eth0”一起使用,但问题仍然存在。
最佳答案
问题不在于 VRF,而在于当内核检测到它可以使用它而不是通过线路发送时使用的环回。
让我们使用真实的 MAC 地址和虚拟 IP 地址和 NAT 来强制内核通过线路发送数据:
arp -s IP0 MAC0
arp -s IP1 MAC1
ip route add IP0 dev eth1
ip route add IP1 dev eth0
iptables -t nat -A POSTROUTING -d IP1 -j SNAT --to-source IP0
iptables -t nat -A POSTROUTING -d IP0 -j SNAT --to-source IP1
iptables -t nat -A PREROUTING -d IP0 -j DNAT --to-destination IP0
iptables -t nat -A PREROUTING -d IP1 -j DNAT --to-destination IP1
关于linux - 禁用linux内部路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804223/