openSUSE多线路路由添加脚本

字体大小: 中小 标准 ->行高大小: 标准

openSUSE多线路路由添加脚本:

  1. #!/bin/bash  #author itnihao 
  2. #bolg  http://itnihao.blog.51cto.com   
  3.   green='\e[0;32m' 
  4. red='\e[0;31m'  blue='\e[0;36m' 
  5. blue1='\e[5;31m'  NC='\e[0m' 
  6. mkdir route  cd route 
  7. echo -e "${green}正在从互联网上下载最新路由表信息${blue1}..........."  wget http://www.tcp5.com/routingtable/telecom.rsc >/dev/null 2>&1 
  8. wget http://www.tcp5.com/routingtable/unicom.rsc >/dev/null 2>&1  wget http://www.tcp5.com/routingtable/mobile.rsc >/dev/null 2>&1 
  9. wget http://www.tcp5.com/routingtable/cernet.rsc >/dev/null 2>&1  wget http://www.tcp5.com/routingtable/other.rsc >/dev/null 2>&1 
  10. 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 
  11. 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 
  12. awk -F "=" '{print $5}' other.rsc|sed -e "s/ table//g" -e "/^$/d" >other.ip  echo -e "${blue}1):备份默认路由表:" 
  13. echo -e "${blue}2):恢复默认路由表:"  echo -e "${blue}3):设置电信路由表:" 
  14. echo -e "${blue}4):设置联通路由表:"  echo -e "${blue}5):设置移动网路由表:" 
  15. echo -e "${blue}6):设置教育网路由表:"  echo -e "${blue}7):设置其他网络路由表:" 
  16. echo -e "${blue}8):退出设置:"  echo -e "${NC}请选择:" 
  17. read NUM  if [ "${NUM}" -lt "1" -o "${NUM}" -gt "8"  ] 
  18. then     echo "你的选择不在1-8范围内:请重新运行" 
  19. elif     [ "${NUM}" == "1" ] 
  20. then     cp /etc/sysconfig/network/routes /etc/sysconfig/network/routes.default 
  21.    [ "$?" == "0" ] && echo -e "${green} 备份默认路由/etc/sysconfig/network/routes为/etc/sysconfig/network/routes.default${NC}"      [ "$?" != "0" ] && echo -e "${red}  备份默认路由出现错误,请检查/etc/sysconfig/network/routes文件是否存在${NC}" 
  22. elif     [ "${NUM}" == "2" ] 
  23. then        [ -f /etc/sysconfig/network/routes.default ]  
  24.    if  [ "$?" == "0" ];then     cp /etc/sysconfig/network/routes /etc/sysconfig/network/routes.default1 
  25.    mv /etc/sysconfig/network/routes.default /etc/sysconfig/network/routes     echo -e "默认路由恢复完毕,请检查/etc/sysconfig/network/routes文件后重启网卡服务" 
  26.    else     echo -e "文件/etc/sysconfig/network/routes.default不存在" 
  27.    exit     fi 
  28. elif     [ "${NUM}" == "3" ] 
  29. then     echo "input telecom gateway-输入电信线路网关:" 
  30.    read telecomgateway     echo "你的电信线路网关是${telecomgateway},任意键退出运行,确认按y继续" 
  31.    read true     [ ${true} != "y" ]  && exit 
  32.    echo "输入电信线路网卡接口,如\"eth2\":"     read interface 
  33.    echo "你的电信网卡接口是${interface},任意键退出运行,确认按y继续"     read true 
  34.    [ ${true} != "y" ]  && exit     echo "#电信路由开启"  >> /etc/sysconfig/network/routes 
  35.    cat telecom.ip|sed "s/$/ $telecomgateway $interface/g" >> /etc/sysconfig/network/routes     echo "#电信路由结束"  >> /etc/sysconfig/network/routes 
  36.    echo "电信线路路由添加完毕"  elif 
  37.    [ "${NUM}" == "4" ]  then 
  38.    echo "输入联通线路网关:"     read unicomgateway 
  39.    echo "你的联通线路网关是${unicomgateway},任意键退出运行,确认按y继续"     read true 
  40.    [ ${true} != "y" ]  && exit     echo "输入联通线路网卡接口,如\"eth2\":" 
  41.    read interface     echo "你的联通网卡接口是${interface},任意键退出运行,确认按y继续" 
  42.    read true     [ ${true} != "y" ]  && exit 
  43.    echo "#联通路由开启"  >> /etc/sysconfig/network/routes     cat uniccom.ip|sed "s/$/ $unicomgateway $interface/g" >> /etc/sysconfig/network/routes 
  44.    echo "#联通路由结束"  >> /etc/sysconfig/network/routes     echo "联通线路路由添加完毕" 
  45. mobile  elif 
  46.    [ "${NUM}" == "5" ]  then 
  47.    echo "输入移动线路网关:"     read mobilegateway 
  48.    echo "你的移动线路网关是${mobilegateway},任意键退出运行,确认按y继续"     read true 
  49.    [ ${true} != "y" ]  && exit     echo "输入移动线路网卡接口,如\"eth2\":" 
  50.    read interface     echo "你的移动网卡接口是${interface},任意键退出运行,确认按y继续" 
  51.    read true     [ ${true} != "y" ]  && exit 
  52.    echo "#移动路由开启"  >> /etc/sysconfig/network/routes     cat mobile.ip|sed "s/$/ $mobilegateway $interface/g" >> /etc/sysconfig/network/routes 
  53.    echo "#移动路由结束"  >> /etc/sysconfig/network/routes     echo "移动线路路由添加完毕" 
  54.   elif 
  55.    [ "${NUM}" == "6" ]  then 
  56.    echo "输入教育网线路网关:"     read cernetgateway 
  57.    echo "你的教育网线路网关是${cernetgateway},任意键退出运行,确认按y继续"     read true 
  58.    [ ${true} != "y" ]  && exit     echo "输入教育网线路网卡接口,如\"eth2\":" 
  59.    read interface     echo "你的教育网网卡接口是${interface},任意键退出运行,确认按y继续" 
  60.    read true     [ ${true} != "y" ]  && exit 
  61.    echo "#教育网路由开启"  >> /etc/sysconfig/network/routes     cat cernet.ip|sed "s/$/ $cernetgateway $interface/g" >> /etc/sysconfig/network/routes 
  62.    echo "#教育网路由结束"  >> /etc/sysconfig/network/routes     echo "教育网线路路由添加完毕" 
  63. elif     [ "${NUM}" == "7" ] 
  64. then     echo "输输入其它网络线路网关:" 
  65.    read othergateway     echo "你的其它网络线路网关是${othergateway},任意键退出运行,确认按y继续" 
  66.    read true     [ ${true} != "y" ]  && exit 
  67.    echo "输入其它网络线路网卡接口,如\"eth2\":"     read interface 
  68.    echo "你的其它网络网卡接口是${interface},任意键退出运行,确认按y继续"     read true 
  69.    [ ${true} != "y" ]  && exit     echo "#其它网络路由开启"  >> /etc/sysconfig/network/routes 
  70.    cat other.ip|sed "s/$/ $othergateway $interface/g" >> /etc/sysconfig/network/routes     echo "#其它网络路由结束"  >> /etc/sysconfig/network/routes 
  71.    echo "其它网络线路路由添加完毕"  elif 
  72.    [ "${NUM}" == "8" ]  then 
  73. exit  fi 
openSUSE多线路路由添加脚本

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/66564.html