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 



本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/900476,如需转载请自行联系原作者

相关文章
|
3月前
|
监控 数据安全/隐私保护 网络虚拟化
ensp命令练习及交换机 和个路由器的基本命令
ensp命令练习及交换机 和个路由器的基本命令
124 0
|
Ubuntu
Ubuntu 20.04 多网卡路由规则配置
Ubuntu 20.04 多网卡路由规则配置
2748 0
|
网络协议 Unix Linux
CentOS7下利用FRR路由套件实现OSPF动态路由组网
CentOS7下利用FRR路由套件实现OSPF动态路由组网
937 0
CentOS7下利用FRR路由套件实现OSPF动态路由组网
|
4月前
|
编译器 Linux 开发工具
openwrt软路由基础探索
openwrt软路由基础探索
66 0
|
11月前
|
监控 数据安全/隐私保护 网络虚拟化
ensp命令练习及交换机 和个路由器的基本命令(上)
ensp命令练习及交换机 和个路由器的基本命令
|
11月前
|
监控 网络虚拟化 数据安全/隐私保护
ensp命令练习及交换机 和个路由器的基本命令(下)
ensp命令练习及交换机 和个路由器的基本命令
|
网络协议 安全 算法
网络设备基本配置命令
一、配置交换机路由器名字(config)#hostname 名字二、配置交换机管理地址(config)#int vlan 1(config-if)#ip address IP地址 子网掩码(config-if)#no shutdown(config-if)#exit三、配置交换机缺省网关(config)#ip default-gateway IP地址四、配置交换机路由器特权密码(从用户模式进入特权模式时使用)(config)#enable secret [level 数字(0-15)] 0或5 密码五、配置交换机路由器远程登录密码(利用Telnet方式远程登录进入用户模项目三 构建小型局域网