Iptables 通过多个虚拟网络接口进行循环调度

Iptables 通过多个虚拟网络接口进行循环调度

我有一台服务器,它有两个主网络接口和 5 个这样的虚拟接口。

eth0 - 192.168.1.1
eth1 - 192.168.3.1

eth1:2 192.168.3.3
eth1:3 192.168.3.4
eth1:4 192.168.3.5
eth1:5 192.168.3.6
eth1:6 192.168.3.7

etho 是我的内部接口,eth1 是我的外部接口。我需要使用循环方式使用全部 5 个网络接口路由所有流量。如果三个请求到达 eth0,则这三个请求分别通过 eth1:1、eth1:2 和 eth 1:3。顺序无关紧要。我需要使用全部五个活动接口并使用循环方式路由流量。我该怎么做?只使用 iptables 就可以做到吗?

答案1

我认为你可以使用PREROUTING带有统计模块的链来实现这一点。你可以看看这篇文章:带有 iptables 和 NAT 的简单状态负载均衡器

在你的情况下,它可能是这样的:

iptables -t nat -A PREROUTING -i eth0 -m state --state NEW -m statistic --mode random
 --probability .25 -j DNAT --to 192.168.3.3

iptables -t nat -A PREROUTING -i eth0 -m state --state NEW -m statistic --mode random
 --probability .25 -j DNAT --to 192.168.3.4

iptables -t nat -A PREROUTING -i eth0 -m state --state NEW -m statistic --mode random
 --probability .25 -j DNAT --to 192.168.3.5

iptables -t nat -A PREROUTING -i eth0 -m state --state NEW -m statistic --mode random
 --probability .25 -j DNAT --to 192.168.3.6

从理论上讲,它应该可行,但我不能保证此设置将适用于有状态协议

另一个选择是寻找如下解决方案哈普罗西

相关内容