> Linux教程 >

linux下获取国内路由表

今天给公司的macbook都配置了vpn,但每次拨号大家的qq和skype都会掉下线,并且多人连接到了vpn,拖公司的网速,为了解决这样的问题,我做了连上vpn,访问国内网站不走vpn,访问国外才走vpn,为了让公司的macbook都实时能够更新到路由表,我做了下面的一个简单东西.
1.下载路由表
因为要获取到路由表才能给大家都更新,但路由表的获取网站:
chnroutes主页:https://code.google.com/p/chnroutes/,分流路由表下载:http://chnroutes-dl.appspot.com/,这个两个网站在国内都受到“特别的关照”,所以出现404、重置之类的别觉得奇怪。连接上VPN或使用网页代理访问.
 
所以我只能在国外的服务器上把路由表down下来:
wget http://chnroutes-dl.appspot.com/downloads/AMIfv95TJD_eME3FFtmpE7Ydli6PIRkyrChTrcZjRUm-vlg6Q-XyqvdKvzbdqD7pI1I3OQ3tP1BHenH1RpYcA-5qeF22tgpELl6wTR6_VXCPazn5EeIvjEG-EqAeMSucQMLatVZ8KBKbq-nskF1yg5vV6M7NQnGwBMlt2uP1lr241LUDOSoFqHI
 
2.下下来后,得到linuxzip.zip这个包,我们要解压
yum -y install unzip
unzip linuxzip.zip
解压出来有
data文件夹和install.sh文件
 
我们进入到data文件夹里,我们要获取ip-pre-up文件里的路由表,使用下面的命令:
awk '/route/,p' ip-pre-up >ip1
这样就把ip路由表提取出来了,但里面的内容如下:
route add 1.0.1.0/24 "${OLDGW}"
route add 1.0.2.0/23 "${OLDGW}"
route add 1.0.8.0/21 "${OLDGW}"
route add 1.0.32.0/19 "${OLDGW}"
route add 1.1.0.0/24 "${OLDGW}"
route add 1.1.2.0/23 "${OLDGW}"
route add 1.1.4.0/22 "${OLDGW}"
route add 1.1.8.0/21 "${OLDGW}"
route add 1.1.16.0/20 "${OLDGW}"
route add 1.1.32.0/19 "${OLDGW}"
route add 1.2.0.0/23 "${OLDGW}"
route add 1.2.2.0/24 "${OLDGW}"
route add 1.2.4.0/24 "${OLDGW}"
route add 1.2.5.0/24 "${OLDGW}"
route add 1.2.6.0/23 "${OLDGW}"
route add 1.2.8.0/24 "${OLDGW}"
route add 1.2.9.0/24 "${OLDGW}"
route add 1.2.10.0/23 "${OLDGW}"
route add 1.2.12.0/22 "${OLDGW}"
route add 1.2.16.0/20 "${OLDGW}"
route add 1.2.32.0/19 "${OLDGW}"
route add 1.2.64.0/18 "${OLDGW}"
route add 1.3.0.0/16 "${OLDGW}"
........(我省略了中间很多)
route add 103.252.64.0/22 "${OLDGW}"
route add 103.252.104.0/22 "${OLDGW}"
route add 103.252.172.0/22 "${OLDGW}"
route add 103.252.204.0/22 "${OLDGW}"
route add 103.252.208.0/22 "${OLDGW}"
route add 103.252.232.0/22 "${OLDGW}"
route add 103.252.248.0/22 "${OLDGW}"
route add 103.253.4.0/22 "${OLDGW}"
route add 103.253.60.0/22 "${OLDGW}"
 
所以我们还要来最后一步把路由表给提出来,其他的都不要:
sed '/./{s/^route\ add//;s/"${OLDGW}"//}' ip1 >t1.txt
sed '/./{s/^[ \t]*//;s/[ \t]*$//}' t1.txt >ip
 
这样才是真的把ip路由表提取出来了.
(责任编辑:IT)