Linux环境下基于策略的路由
时间:2007-06-19 来源:go1860
<IFRAME align=center marginWidth=0 marginHeight=0 src="http://www.baobaozx.cn/g6.htm" frameBorder=0 width=336 scrolling=no height=280></IFRAME>
因此为了满足条件2,给eth0添加地址: ip addr add 172.17.1.2/32 dev eth0 假设系统被设置为对所有的输出数据报都进行IP伪装。首先清空旧的策略规则,然后创建新的规则如下: ip route add 10.10.0.0/16 via 10.254.254.2 src 10.254.254.2 table goodnet1 proto static ip route add default via 172.17.1.254 src 172.17.1.128 table goodnet1 proto static ip route add 172.18.0.0/16 via 172.17.1.1 src 172.17.1.2 table goodnet2 proto static ip route add default via 172.17.1.254 src 172.17.1.128 table goodnet2 proto static ip rule add from 192.168.1.0/24 pref 15000 table goodnet2 ip rule add from 192.168.2.0/24 pref 15001 table goodnet1 例7:综合实例 假设例6中的路由、规则和地址仍然在起作用,我希望实现下面的需求: Internal A Hosts 33-62 to Network A Masq as 172.17.1.3 Internal A Hosts 65-78 to tcp port 80 on Network A Masq as 172.17.1.4 Internal B Hosts 33-62 to tcp port 80 on Network A Deny Access Internal B Hosts 65-78 to tcp port 80 on Network C Masq as 10.254.254.2 应该记得我们仍然允许例6中的连接性,下面就是解决方案: ip addr add 172.17.1.3/32 dev eth0 ip addr add 172.17.1.4/32 dev eth0 ip route del default table goodnet1 ip route del default table goodnet2 ip route add throw 0/0 table goodnet1 proto static ip route add throw 0/0 table goodnet2 proto static ip route add default via 172.17.1.254 src 172.17.1.128 table internet proto static ip route add 172.18.0.0/16 via 172.17.1.1 src 172.17.1.3 table badnet1 proto static ip route add 172.18.0.0/16 via 172.17.1.1 src 172.17.1.4 table badnet2 proto static ip rule add from 192.168.1.32/27 to 172.18.0.0/16 pref 14999 table badnet1 ip rule add fwmark 1 pref 14998 table badnet2 ip rule add fwmark 2 pref 14997 table goodnet1 ip rule add fwmark 3 pref 14996 blackhole ip rule add pref 15003 table internet ipchains -I input -p tcp -s 192.168.1.64/28 -d 172.18.0.0/16 80 -m 1 ipchains -I input -p tcp -s 192.168.2.64/28 -d 10.10.0.0/16 80 -m 2 ipchains -I input -p tcp -s 192.168.2.32/27 -d 172.18.0.0/16 80 -m 3 其实有很多的有效方法,但是虽然这里使用名为badnet1和badnet2的表,但是名字是没有实际意义的,只是用来引用表3和表4的符号。 总结 希望你通过该文章能享受Linux2.2的强大路由功能,它提供的路由功能是很多路由器产品都是难以匹敌的, 如果考虑到它的免费性,它的性能价格比更是没有任何产品可以相比。例如例7中的例子可以很好的运行在只有16M内存的486/33的机器上。 学习专业知识,网络技术,选择网盾~!官方网址:www.netsos.com.cn 联系电话:027—87879366 87865200 咨询Q Q: 495492526 807638839 咨询Email:[email protected] 学院地址:武汉市洪山区武珞路720号(省军区对面)
相关阅读 更多 +