#!/bin/bash
#author itnihao
#bolg http://itnihao.blog.51cto.com
green='\e[0;32m'
red='\e[0;31m'
blue='\e[0;36m'
blue1='\e[5;31m'
NC='\e[0m'
mkdir route
cd route
echo -e "${green}正在从互联网上下载最新路由表信息${blue1}..........."
wget http://www.tcp5.com/routingtable/telecom.rsc >/dev/null 2>&1
wget http://www.tcp5.com/routingtable/unicom.rsc >/dev/null 2>&1
wget http://www.tcp5.com/routingtable/mobile.rsc >/dev/null 2>&1
wget http://www.tcp5.com/routingtable/cernet.rsc >/dev/null 2>&1
wget http://www.tcp5.com/routingtable/other.rsc >/dev/null 2>&1
awk -F "=" '{print $5}' telecom.rsc |sed -e "s/ table//g" -e "/^$/d" >telecom.ip
awk -F "=" '{print $5}' unicom.rsc |sed -e "s/ table//g" -e "/^$/d" >unicom.ip
awk -F "=" '{print $5}' mobile.rsc |sed -e "s/ table//g" -e "/^$/d" >mobile.ip
awk -F "=" '{print $5}' cernet.rsc|sed -e "s/ table//g" -e "/^$/d" >cernet.ip
awk -F "=" '{print $5}' other.rsc|sed -e "s/ table//g" -e "/^$/d" >other.ip
echo -e "${blue}1):备份默认路由表:"
echo -e "${blue}2):恢复默认路由表:"
echo -e "${blue}3):设置电信路由表:"
echo -e "${blue}4):设置联通路由表:"
echo -e "${blue}5):设置移动网路由表:"
echo -e "${blue}6):设置教育网路由表:"
echo -e "${blue}7):设置其他网络路由表:"
echo -e "${blue}8):退出设置:"
echo -e "${NC}请选择:"
read NUM
if [ "${NUM}" -lt "1" -o "${NUM}" -gt "8" ]
then
echo "你的选择不在1-8范围内:请重新运行"
elif
[ "${NUM}" == "1" ]
then
cp /etc/sysconfig/network/routes /etc/sysconfig/network/routes.default
[ "$?" == "0" ] && echo -e "${green} 备份默认路由/etc/sysconfig/network/routes为/etc/sysconfig/network/routes.default${NC}"
[ "$?" != "0" ] && echo -e "${red} 备份默认路由出现错误,请检查/etc/sysconfig/network/routes文件是否存在${NC}"
elif
[ "${NUM}" == "2" ]
then
[ -f /etc/sysconfig/network/routes.default ]
if [ "$?" == "0" ];then
cp /etc/sysconfig/network/routes /etc/sysconfig/network/routes.default1
mv /etc/sysconfig/network/routes.default /etc/sysconfig/network/routes
echo -e "默认路由恢复完毕,请检查/etc/sysconfig/network/routes文件后重启网卡服务"
else
echo -e "文件/etc/sysconfig/network/routes.default不存在"
exit
fi
elif
[ "${NUM}" == "3" ]
then
echo "input telecom gateway-输入电信线路网关:"
read telecomgateway
echo "你的电信线路网关是${telecomgateway},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "输入电信线路网卡接口,如\"eth2\":"
read interface
echo "你的电信网卡接口是${interface},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "#电信路由开启" >>/etc/sysconfig/network/routes
cat telecom.ip|sed "s/$/ $telecomgateway $interface/g" >>/etc/sysconfig/network/routes
echo "#电信路由结束" >>/etc/sysconfig/network/routes
echo "电信线路路由添加完毕"
elif
[ "${NUM}" == "4" ]
then
echo "输入联通线路网关:"
read unicomgateway
echo "你的联通线路网关是${unicomgateway},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "输入联通线路网卡接口,如\"eth2\":"
read interface
echo "你的联通网卡接口是${interface},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "#联通路由开启" >>/etc/sysconfig/network/routes
cat uniccom.ip|sed "s/$/ $unicomgateway $interface/g" >>/etc/sysconfig/network/routes
echo "#联通路由结束" >>/etc/sysconfig/network/routes
echo "联通线路路由添加完毕"
mobile
elif
[ "${NUM}" == "5" ]
then
echo "输入移动线路网关:"
read mobilegateway
echo "你的移动线路网关是${mobilegateway},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "输入移动线路网卡接口,如\"eth2\":"
read interface
echo "你的移动网卡接口是${interface},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "#移动路由开启" >>/etc/sysconfig/network/routes
cat mobile.ip|sed "s/$/ $mobilegateway $interface/g" >>/etc/sysconfig/network/routes
echo "#移动路由结束" >>/etc/sysconfig/network/routes
echo "移动线路路由添加完毕"
elif
[ "${NUM}" == "6" ]
then
echo "输入教育网线路网关:"
read cernetgateway
echo "你的教育网线路网关是${cernetgateway},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "输入教育网线路网卡接口,如\"eth2\":"
read interface
echo "你的教育网网卡接口是${interface},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "#教育网路由开启" >>/etc/sysconfig/network/routes
cat cernet.ip|sed "s/$/ $cernetgateway $interface/g" >>/etc/sysconfig/network/routes
echo "#教育网路由结束" >>/etc/sysconfig/network/routes
echo "教育网线路路由添加完毕"
elif
[ "${NUM}" == "7" ]
then
echo "输输入其它网络线路网关:"
read othergateway
echo "你的其它网络线路网关是${othergateway},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "输入其它网络线路网卡接口,如\"eth2\":"
read interface
echo "你的其它网络网卡接口是${interface},任意键退出运行,确认按y继续"
read true
[ ${true} != "y" ] && exit
echo "#其它网络路由开启" >>/etc/sysconfig/network/routes
cat other.ip|sed "s/$/ $othergateway $interface/g" >>/etc/sysconfig/network/routes
echo "#其它网络路由结束" >>/etc/sysconfig/network/routes
echo "其它网络线路路由添加完毕"
elif
[ "${NUM}" == "8" ]
then
exit
fi