基于策略的路由

我在http://www.diegolima.org/wordpress/?p=36find了很好的关于负载平衡的文章。虽然我的要求与纯粹的负载平衡略有不同,但我无法实现。

我们有两个ISP连接。 我已经把这两台路由器分别连接到了eth0(public ip 121.XXX.XX.XXX)和eth1(192.168.129.XXX)上的Linux服务器,而我们的内部networking是eth2(192.168.1.XXX)。

我已经决定,我们的FTP应该使用eth1接口,Squid应该使用eth0,Sendmail应该使用eth0,一些用户应该使用eth0,另一些用户应该使用eth1。

任何人都可以告诉是否有可能,我怎样才能实现这个使用iptables和iproute2? 一步一步的帮助是高度赞赏。 提前致谢。

configurationIPROUTE2

echo "4 sendmail" >> /etc/iproute2/rt_tables ip route add 121.XXX.XX.XXX/MASK dev eth0 src 121.XXX.XX.XXX table sendmail ip route add 192.168.1.XXX/24 dev eth2 table sendmail ip route add default via GATEWAY1 table sendmail ip ru add from 121.XXX.XX.XXX lookup sendmail ip ru add fwmark 2 table sendmail ip route flush cache 

configurationIPTABLES

 iptables -t mangle -I OUTPUT -p tcp --dport 25 -j MARK --set-mark 0x2 iptables -t mangle -I PREROUTING -i eth2 -p tcp --dport 25 -j MARK --set-mark 0x2 iptables -t nat -I POSTROUTING -s 192.168.1.XXX/24 -o eth0 -j SNAT --to-source 121.XXX.XX.XXX 

我使用shorewall做了类似的事情。
一切都基于标记和过滤数据包,并在其上应用一些规则。 一切都应该在larc howt中解释: http ://lartc.org/howto/index.html进程应该是这样的(我必须重读一些东西,我几个月前做过):

  • 这个数据包来自内部networking

  • netfilter适用于一些MARK的stream量

  • 基于标记的规则通过正确的设备路由分组