linux下的策略路由(教育网流量和其他分开走)
前面提到实现的策略是从哪儿来的回哪儿去
也就是说从哪个网络设备上来的请求
response的时候还从哪个网络设备上回去
后来
策略改了
改成去教育网ip的流量都走教育网的线路,
也就是连接教育网线路的设备
按照前面的例子,就是eth0.100
其他公网的流量走另外一个网络设备,也就是eth0.101
于是在文件/etc/sysconfig/network-scripts/route-eth0.100中添加:
a.b.c.0/24 dev eth0.100 src a.b.c.d table edu
default via a.b.c.254 table edu
在文件/etc/sysconfig/network-scripts/rule-eth0.100中添加:
from a.b.c.d table edu
to 58.154.0.0/15 table edu
to 58.192.0.0/12 table edu
to 59.64.0.0/12 table edu
to 113.54.0.0/15 table edu
to 114.212.0.0/15 table edu
to 114.214.0.0/16 table edu
to 115.24.0.0/14 table edu
to 115.154.0.0/15 table edu
to 115.156.0.0/15 table edu
to 115.158.0.0/16 table edu
to 116.13.0.0/16 table edu
to 116.56.0.0/15 table edu
to 118.202.0.0/15 table edu
to 118.228.0.0/15 table edu
to 118.230.0.0/16 table edu
to 120.94.0.0/15 table edu
to 121.48.0.0/15 table edu
to 121.52.160.0/19 table edu
to 121.192.0.0/14 table edu
to 121.248.0.0/14 table edu
to 122.204.0.0/14 table edu
to 125.216.0.0/13 table edu
to 162.105.0.0/16 table edu
to 166.111.0.0/16 table edu
to 202.4.128.0/19 table edu
to 202.38.64.0/18 table edu
to 202.38.140.0/23 table edu
to 202.38.184.0/21 table edu
to 202.38.192.0/18 table edu
to 202.112.0.0/13 table edu
to 202.120.0.0/15 table edu
to 202.127.216.0/21 table edu
to 202.127.224.0/19 table edu
to 202.179.240.0/20 table edu
to 202.192.0.0/12 table edu
to 203.91.120.0/21 table edu
to 210.25.0.0/17 table edu
to 210.25.128.0/18 table edu
to 210.26.0.0/15 table edu
to 210.28.0.0/14 table edu
to 210.32.0.0/12 table edu
to 211.64.0.0/13 table edu
to 211.80.0.0/13 table edu
to 218.192.0.0/13 table edu
to 219.216.0.0/13 table edu
to 219.224.0.0/13 table edu
to 219.242.0.0/15 table edu
to 219.244.0.0/14 table edu
to 222.16.0.0/12 table edu
to 222.192.0.0/12 table edu
以上to的ip地址段都是教育网的ip地址
同样,在文件/etc/sysconfig/network-scripts/route-eth0.101添加:
e.f.g.0/24 dev eth1.470 src e.f.g.h table other
default via e.f.g.254 table other
在文件/etc/sysconfig/network-scripts/rule-eth0.101中添加:
from e.f.g.h table other
还有
在/etc/sysconfig/network里写的
GATEWAY=e.f.g.254
也就是写的是缺省的公网网关
原创文章,转载请注明: 转载自嘻嘻哈哈的部落格(blog)
本文链接地址: linux下的策略路由(教育网流量和其他分开走)


BTW
需要注意的是
在fc3(fedora core 3)下
把rule写到文件/etc/sysconfig/network-scripts/rule-$1里的方式并不管用
仔细看了看
是因为在脚本/etc/sysconfig/network-scripts/ifup-routes里最后少了如下这一段
# Routing rules
FILES=”/etc/sysconfig/network-scripts/rule-$1″
if [ -n "$2" -a "$2" != "$1" ]; then
FILES=”$FILES /etc/sysconfig/network-scripts/rule-$2″
fi
for file in $FILES; do
if [ -f "$file" ]; then
{ cat “$file” ; echo ; } | while read line; do
if [[ ! "$line" =~ '^[[:space:]]*(\#.*)?$’ ]]; then
/sbin/ip rule add $line
fi
done
fi
done