Chinaunix首页 | 论坛 | 博客
  • 博客访问: 544936
  • 博文数量: 114
  • 博客积分: 5611
  • 博客等级: 大校
  • 技术积分: 1027
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-19 08:55
文章分类

全部博文(114)

文章存档

2011年(29)

2010年(20)

2009年(1)

2008年(11)

2007年(53)

分类: LINUX

2010-04-29 21:37:00

网络环境:
 
eth1   内网    192.168.6.* 接收从内部路由器过来的包
 
源地址包括了 192.168.3.0/24--192.168.10.0/24的地址
内部的路由器上的比较早,主要是用来隔离内部的网络广播的.他的每个段的网关是都是本段的1地址。
192.168.6.0/24段 是服务器段,有2个代理服务器,和若干web、ftp等应用服务器。
同时做了内网各个网段的路由(都是从192.168.6.1发送到192.168.6.0/24段)  
 
eth0   外网    电信地址 
 
增加2个路由表:
 
#vi /etc/iproute2/rt_tables
255     local
254     main
253     default
0       unspec
200     net10
100     net9
 
添加了2个路由表
 
#ip route list
61.132.*.*/29 dev eth0  proto kernel  scope link  src 61.132.*.*
192.168.6.0/24 dev eth1  proto kernel  scope link  src 192.168.6.*
169.254.0.0/16 dev eth1  scope link
default via 61.132.*.* dev eth0
 
对比下呀2个命令的含义一样的:
 
#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
61.132.*.*    *               255.255.255.248 U     0      0        0 eth0
192.168.6.0     *               255.255.255.0   U     0      0        0 eth1
169.254.0.0     *               255.255.0.0     U     0      0        0 eth1
default         61.132.*.*    0.0.0.0         UG    0      0        0 eth0
 
 
#ip route add to 192.168.0.0/16 via 192.168.6.1 dev eth1 table net9
#ip rule add to 192.168.3.0/24 pref 9000 table net9
#ip rule add to 192.168.4.0/24 pref 9001 table net9
#ip rule add to 192.168.5.0/24 pref 9002 table net9
#ip rule add to 192.168.7.0/24 pref 9003 table net9
#ip rule add to 192.168.8.0/24 pref 9004 table net9
#ip rule add to 192.168.9.0/24 pref 9005 table net9
#ip rule add to 192.168.10.0/24 pref 9006 table net9
 
其中net9的路由表,主要是目的地址的路由,为什么没有直接在缺省的路由表中直接做目的地址路由呢
因为后面的源地址路由中有针对本机网卡的ip地址段的策略,这个策略会优先缺省路由表,从而把这个目的地址路由的东西,扔给192.168.6.253中转了。实际的应用中如果直接配置到缺省路由,哪个策略优先,有点搞不清。
 
所以只能再加个net9路由表,同时把这几个段的策略扔给路由表net9处理的时候,设置优先级别高于符合net10的策略。这样的思路也清晰点!
 
如果只是本机出来的包,应该不会去匹配net10的策略,因为local的路由策略的优先级别最高!
 
做这个目的地址路由主要是为了把内部其他网段的ip到Internet网的包,能够正确的回包。

 
#ip route add to 0.0.0.0/0 via 192.168.6.253 dev eth1 table net10
#ip rule add from 192.168.6.0/24 pref 10000 table net10
#ip rule add from 192.168.3.0/24 pref 10001 table net10
 
做上面3条策略路由的目的是为了 把192.168.3.0/24 跟192.168.6.0/24段的上网流量,扔给另一台服务器192.168.6.253处理。
 
# ip route list table net9
192.168.0.0/16 via 192.168.6.1 dev eth1
 
# ip route list table net10
 
default via 192.168.6.253 dev eth1
 
# ip rule list
 
0:      from all lookup 255
9000:   from all to 192.168.3.0/24 lookup net9
9001:   from all to 192.168.4.0/24 lookup net9
9002:   from all to 192.168.5.0/24 lookup net9
9003:   from all to 192.168.7.0/24 lookup net9
9004:   from all to 192.168.8.0/24 lookup net9
9005:   from all to 192.168.9.0/24 lookup net9
9006:   from all to 192.168.10.0/24 lookup net9
10000:  from 192.168.6.0/24 lookup net10
10001:  from 192.168.3.0/24 lookup net10
32766:  from all lookup main
32767:  from all lookup default
 
 
测试了下,一切ok!!
 
 
 
阅读(7865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~