歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> openSUSE多線路路由添加腳本

openSUSE多線路路由添加腳本

日期:2017/2/28 15:47:57   编辑:Linux教程

openSUSE多線路路由添加腳本:

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