快速业务通道

linux 配置网桥脚本

作者 佚名技术 来源 Linux系统 浏览 发布时间 2012-03-30

  1. #!/bin/sh
  2. ##############################################################
  3. #
  4. # function: create linux bridge, centos 5 test pass.
  5. # user: chenjian
  6. # date : 2011-06-30 ^_^.
  7. #
  8. ##############################################################
  9. NETWORK_DIR=/etc/sysconfig/network-scripts
  10. if ! `rpm -qi bridge-utils > /dev/null`;
  11. then
  12. echo "bridge-utils package not install."
  13. fi
  14. rm -rf $NETWORK_DIR/ifcfg-br*
  15. read -p "Input your bridge name,ex br0: "
  16. if [ `echo $REPLY|wc -L` -eq 0 ];
  17. then
  18. REPLY=br0
  19. fi
  20. BRIDGE=$REPLY
  21. ETHERNET_ALL=$( ls -l $NETWORK_DIR|awk -F''-'' ''/ifcfg-eth/{print $8}'')
  22. while [ `echo $REPLY|wc -w` -lt 2 ];
  23. do
  24. read -p "Input you need to use the network adapter, separated by a space. current cards(`echo $ETHERNET_ALL`),chose two : "
  25. done
  26. ETHERNET=$REPLY
  27. for i in `seq 1 3`;
  28. do
  29. read -p "Input the bridge ip address and netmask. separated by a space: "
  30. if [ `echo $REPLY|wc -L` -eq 0 ];
  31. then
  32. echo "Input empty. this bridage will no ip address. "
  33. REPLY="0.0.0.0 0.0.0.0"
  34. sleep 3
  35. break
  36. elif `echo $REPLY|grep -v ''[0-9]\.'' > /dev/null`;
  37. then
  38. echo "Use only numbers and points."
  39. elif [ `echo $REPLY|awk ''{print $2}''|wc -L` -eq 0 ]
  40. then
  41. echo "Input errors, exit."
  42. exit 2
  43. else
  44. break
  45. fi
  46. done
  47. IP=`echo $REPLY|awk ''{print $1}''`
  48. NETMASK=`echo $REPLY|awk ''{print $2}''`
  49. brctl addbr $BRIDGE
  50. cat > $NETWORK_DIR/ifcfg-$BRIDGE <<-EOF
  51. DEVICE=$BRIDGE
  52. BOOTPROTO=static
  53. ONBOOT=yes
  54. NETMASK=$NETMASK
  55. IPADDR=$IP
  56. TYPE=Bridge
  57. EOF
  58. echo -------------------------------------
  59. echo "Bridge info "
  60. echo -------------------------------------
  61. cat $NETWORK_DIR/ifcfg-$BRIDGE
  62. echo ""
  63. for i in `echo $ETHERNET`;
  64. do
  65. MAC=$(ifconfig $i|awk ''/HWaddr/{print $NF }'')
  66. cat > $NETWORK_DIR/ifcfg-$i <<EOF
  67. DEVICE=$i
  68. HWADDR=$MAC
  69. BOOTPROTO=none
  70. ONBOOT=yes
  71. HOTPLUG=no
  72. TYPE=Ethernet
  73. BRIDGE=$BRIDGE
  74. EOF
  75. echo -------------------------------------
  76. echo "$i info"
  77. echo -------------------------------------
  78. cat $NETWORK_DIR/ifcfg-$i
  79. echo ""
  80. done
  81. echo ""
  82. echo -------------------------------------
  83. echo -e "install successful ,you need to restart your network"
  84. echo -------------------------------------
  85. exit 0;

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号