歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

openSUSE多線路路由添加腳本

openSUSE多線路路由添加腳本:

  1. #!/bin/bash 
  2. #author itnihao 
  3. #bolg  http://itnihao.blog.51cto.com 
  4.  
  5.  
  6. green='\e[0;32m' 
  7. red='\e[0;31m' 
  8. blue='\e[0;36m' 
  9. blue1='\e[5;31m' 
  10. NC='\e[0m' 
  11. mkdir route 
  12. cd route 
  13. echo -e "${green}正在從互聯網上下載最新路由表信息${blue1}..........." 
  14. wget http://www.tcp5.com/routingtable/telecom.rsc >/dev/null 2>&1 
  15. wget http://www.tcp5.com/routingtable/unicom.rsc >/dev/null 2>&1 
  16. wget http://www.tcp5.com/routingtable/mobile.rsc >/dev/null 2>&1 
  17. wget http://www.tcp5.com/routingtable/cernet.rsc >/dev/null 2>&1 
  18. wget http://www.tcp5.com/routingtable/other.rsc >/dev/null 2>&1 
  19. awk -F "=" '{print $5}' telecom.rsc |sed -e "s/ table//g" -e "/^$/d" >telecom.ip 
  20. awk -F "=" '{print $5}' unicom.rsc |sed -e "s/ table//g" -e "/^$/d" >unicom.ip 
  21. awk -F "=" '{print $5}' mobile.rsc |sed -e "s/ table//g" -e "/^$/d" >mobile.ip 
  22. awk -F "=" '{print $5}' cernet.rsc|sed -e "s/ table//g" -e "/^$/d" >cernet.ip 
  23. awk -F "=" '{print $5}' other.rsc|sed -e "s/ table//g" -e "/^$/d" >other.ip 
  24. echo -e "${blue}1):備份默認路由表:" 
  25. echo -e "${blue}2):恢復默認路由表:" 
  26. echo -e "${blue}3):設置電信路由表:" 
  27. echo -e "${blue}4):設置聯通路由表:" 
  28. echo -e "${blue}5):設置移動網路由表:" 
  29. echo -e "${blue}6):設置教育網路由表:" 
  30. echo -e "${blue}7):設置其他網絡路由表:" 
  31. echo -e "${blue}8):退出設置:" 
  32. echo -e "${NC}請選擇:" 
  33. read NUM 
  34. if [ "${NUM}" -lt "1" -o "${NUM}" -gt "8"  ] 
  35. then 
  36.    echo "你的選擇不在1-8范圍內:請重新運行" 
  37. elif 
  38.    [ "${NUM}" == "1" ] 
  39. then 
  40.    cp /etc/sysconfig/network/routes /etc/sysconfig/network/routes.default 
  41.    [ "$?" == "0" ] && echo -e "${green} 備份默認路由/etc/sysconfig/network/routes為/etc/sysconfig/network/routes.default${NC}"  
  42.    [ "$?" != "0" ] && echo -e "${red}  備份默認路由出現錯誤,請檢查/etc/sysconfig/network/routes文件是否存在${NC}" 
  43. elif 
  44.    [ "${NUM}" == "2" ] 
  45. then    
  46.    [ -f /etc/sysconfig/network/routes.default ]  
  47.    if  [ "$?" == "0" ];then 
  48.    cp /etc/sysconfig/network/routes /etc/sysconfig/network/routes.default1 
  49.    mv /etc/sysconfig/network/routes.default /etc/sysconfig/network/routes 
  50.    echo -e "默認路由恢復完畢,請檢查/etc/sysconfig/network/routes文件後重啟網卡服務" 
  51.    else 
  52.    echo -e "文件/etc/sysconfig/network/routes.default不存在" 
  53.    exit 
  54.    fi 
  55. elif 
  56.    [ "${NUM}" == "3" ] 
  57. then 
  58.    echo "input telecom gateway-輸入電信線路網關:" 
  59.    read telecomgateway 
  60.    echo "你的電信線路網關是${telecomgateway},任意鍵退出運行,確認按y繼續" 
  61.    read true 
  62.    [ ${true} != "y" ]  && exit 
  63.    echo "輸入電信線路網卡接口,如\"eth2\":" 
  64.    read interface 
  65.    echo "你的電信網卡接口是${interface},任意鍵退出運行,確認按y繼續" 
  66.    read true 
  67.    [ ${true} != "y" ]  && exit 
  68.    echo "#電信路由開啟"  >> /etc/sysconfig/network/routes 
  69.    cat telecom.ip|sed "s/$/ $telecomgateway $interface/g" >> /etc/sysconfig/network/routes 
  70.    echo "#電信路由結束"  >> /etc/sysconfig/network/routes 
  71.    echo "電信線路路由添加完畢" 
  72. elif 
  73.    [ "${NUM}" == "4" ] 
  74. then 
  75.    echo "輸入聯通線路網關:" 
  76.    read unicomgateway 
  77.    echo "你的聯通線路網關是${unicomgateway},任意鍵退出運行,確認按y繼續" 
  78.    read true 
  79.    [ ${true} != "y" ]  && exit 
  80.    echo "輸入聯通線路網卡接口,如\"eth2\":" 
  81.    read interface 
  82.    echo "你的聯通網卡接口是${interface},任意鍵退出運行,確認按y繼續" 
  83.    read true 
  84.    [ ${true} != "y" ]  && exit 
  85.    echo "#聯通路由開啟"  >> /etc/sysconfig/network/routes 
  86.    cat uniccom.ip|sed "s/$/ $unicomgateway $interface/g" >> /etc/sysconfig/network/routes 
  87.    echo "#聯通路由結束"  >> /etc/sysconfig/network/routes 
  88.    echo "聯通線路路由添加完畢" 
  89. mobile 
  90. elif 
  91.    [ "${NUM}" == "5" ] 
  92. then 
  93.    echo "輸入移動線路網關:" 
  94.    read mobilegateway 
  95.    echo "你的移動線路網關是${mobilegateway},任意鍵退出運行,確認按y繼續" 
  96.    read true 
  97.    [ ${true} != "y" ]  && exit 
  98.    echo "輸入移動線路網卡接口,如\"eth2\":" 
  99.    read interface 
  100.    echo "你的移動網卡接口是${interface},任意鍵退出運行,確認按y繼續" 
  101.    read true 
  102.    [ ${true} != "y" ]  && exit 
  103.    echo "#移動路由開啟"  >> /etc/sysconfig/network/routes 
  104.    cat mobile.ip|sed "s/$/ $mobilegateway $interface/g" >> /etc/sysconfig/network/routes 
  105.    echo "#移動路由結束"  >> /etc/sysconfig/network/routes 
  106.    echo "移動線路路由添加完畢" 
  107.  
  108. elif 
  109.    [ "${NUM}" == "6" ] 
  110. then 
  111.    echo "輸入教育網線路網關:" 
  112.    read cernetgateway 
  113.    echo "你的教育網線路網關是${cernetgateway},任意鍵退出運行,確認按y繼續" 
  114.    read true 
  115.    [ ${true} != "y" ]  && exit 
  116.    echo "輸入教育網線路網卡接口,如\"eth2\":" 
  117.    read interface 
  118.    echo "你的教育網網卡接口是${interface},任意鍵退出運行,確認按y繼續" 
  119.    read true 
  120.    [ ${true} != "y" ]  && exit 
  121.    echo "#教育網路由開啟"  >> /etc/sysconfig/network/routes 
  122.    cat cernet.ip|sed "s/$/ $cernetgateway $interface/g" >> /etc/sysconfig/network/routes 
  123.    echo "#教育網路由結束"  >> /etc/sysconfig/network/routes 
  124.    echo "教育網線路路由添加完畢" 
  125. elif 
  126.    [ "${NUM}" == "7" ] 
  127. then 
  128.    echo "輸輸入其它網絡線路網關:" 
  129.    read othergateway 
  130.    echo "你的其它網絡線路網關是${othergateway},任意鍵退出運行,確認按y繼續" 
  131.    read true 
  132.    [ ${true} != "y" ]  && exit 
  133.    echo "輸入其它網絡線路網卡接口,如\"eth2\":" 
  134.    read interface 
  135.    echo "你的其它網絡網卡接口是${interface},任意鍵退出運行,確認按y繼續" 
  136.    read true 
  137.    [ ${true} != "y" ]  && exit 
  138.    echo "#其它網絡路由開啟"  >> /etc/sysconfig/network/routes 
  139.    cat other.ip|sed "s/$/ $othergateway $interface/g" >> /etc/sysconfig/network/routes 
  140.    echo "#其它網絡路由結束"  >> /etc/sysconfig/network/routes 
  141.    echo "其它網絡線路路由添加完畢" 
  142. elif 
  143.    [ "${NUM}" == "8" ] 
  144. then 
  145. exit 
  146. fi 
Copyright © Linux教程網 All Rights Reserved