更新-----Scripts:執行雙網卡綁定

來源:互聯網
上載者:User

更新-----Scripts:執行雙網卡綁定 [python] #!/bin/bash  #-------------------------------------------------------------------------------  # Name:      netbond  # Filename : netbond.sh  # Local:         # What:      用於雙網卡綁定  # HowTo :    sh ./netbond.sh ethN ethN bondN ipaddr netmask gateway    # Version   : 1.1 2013.9.6 對輸入進行判斷,因為已經發生過一次輸入錯誤導致配置失敗  #             1.0 2013.9.3  # Release   : 2013-9-3  # Author    : Gtlions  # Copyright : Copyright (c) Gtlions 2013 <gtlions.l@gmail.com>     # Licence   : <Gtlions's licence>  #-------------------------------------------------------------------------------  echo "You are logged in as `whoami`";   if [ `whoami` != root ]; then       echo "Must be logged as root run script."       exit 1  fi     if [ x$5 = x ]; then      echo "Input Error!"      echo "Usage: sh ./netbond.sh ethN ethN bondN ipaddr netmask gateway"      exit 1  fi  SCRIPTFILE=$0  ETHN1=$1  ETHN2=$2  BONDN=$3  IPADDR=$4  NETMASK=$5  GATEWAY=$6  ETHN1FILE=/etc/sysconfig/network-scripts/ifcfg-$ETHN1  ETHN2FILE=/etc/sysconfig/network-scripts/ifcfg-$ETHN2  BONDFILE=/etc/sysconfig/network-scripts/ifcfg-$BONDN  ETHN1BAK=ifcfg-$ETHN1.bak  ETHN2BAK=ifcfg-$ETHN2.bak    if [ `echo $ETHN1 |grep 'eth'|wc -l` -eq 0 ]; then          echo "Input Error: ethN1"  fi    if [ `echo $ETHN2 |grep 'eth'|wc -l` -eq 0 ]; then          echo "Input Error: ethN2"  fi    if [ `echo $BONDN |grep 'bond'|wc -l` -eq 0 ]; then          echo "Input Error: bondN"  fi      #if [ `echo $IPADDR |awk -F'.' '{print NF-1}'` -eq 3 ]; then  #       :  #else  #       echo "Input Error: ipaddr"  #fi    if [ `echo $IPADDR|grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$'|wc -l` -eq 0 ] ; then          echo "Input Error: ipaddr"  fi  if [ `echo $NETMASK|grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$'|wc -l` -eq 0 ] ; then          echo "Input Error: netmask"  fi  if [ `echo $GATEWAY|grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$'|wc -l` -eq 0 ] ; then          echo "Input Error: gateway"  fi    if [ ! -f $ETHN1FILE ]; then      echo "Error!Not exist $ETHN1FILE"      exit 1  fi  if [ ! -f $ETHN2FILE ]; then      echo "Error!Not exist $ETHN2FILE"      exit 1  fi  if [ -f $BONDFILE ]; then      echo "Error!Exist $BONDFILE"      exit 1  fi    echo "Set Info: $ETHN1 AND $ETHN2 will bond to $BONDN : $IPADDR,$NETMASK,$GATEWAY"  echo "Go On?[Y/N]"  read GOON  GOON1=`echo $GOON |tr 'a-z' 'A-Z'|cut -c1`  if [ $GOON1 = "Y" ]; then            cp $ETHN1FILE ETHN1BAK      cp $ETHN2FILE ETHN2BAK      if [ -f ETHN1BAK ] && [ -f ETHN2BAK ] ; then          echo -e "DEVICE=$BONDN\nONBOOT=yes\nTYPE=Ethernet\nUSERCTL=yes\nBOOTPROTO=static\nIPADDR=$IPADDR\nNETMASK=$NETMASK\nGATEWAY=$GATEWAY">$BONDFILE          chmod 644 $BONDFILE          echo -e "DEVICE=$ETHN1\nONBOOT=yes\nBOOTPROTO=none\nTYPE=Ethernet\nUSERCTL=yes\nMASTER=$BONDN\nSLAVE=yes">$ETHN1FILE          echo -e "DEVICE=$ETHN2\nONBOOT=yes\nBOOTPROTO=none\nTYPE=Ethernet\nUSERCTL=yes\nMASTER=$BONDN\nSLAVE=yes">$ETHN2FILE                    cat /etc/modprobe.conf |grep "$BONDN">null          RESULT=$?            if [ $RESULT -eq 1 ] ; then              echo -e "alias $BONDN bonding\noptions $BONDN miimon=100 mode=1">>/etc/modprobe.conf          fi                    cat /etc/rc.d/rc.local|grep "$BONDN">null          RESULT=$?                if [ $RESULT -eq 1 ] ; then              echo -e "ifenslave $BONDN $ETHN1 $ETHN2">>/etc/rc.d/rc.local          fi            echo "Done!Pls reboot system!"      fi  else      echo "Cancel!"  fi   

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.