麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 服務器 > Linux服務器 > 正文

Linux雙網卡綁定腳本的方法示例

2024-09-05 23:05:24
字體:
來源:轉載
供稿:網友

linux運維及配置工作中,常常會用到雙網卡綁定,少數幾臺服務器的配置還好,如果是需要配置幾十甚至上百臺,難免會枯燥乏味,易于出錯,我編寫了這個雙網卡綁定的輔助腳本,可傻瓜式地完成linux雙網卡綁定工作,當然,該腳本主要還是用于小批量的系統配置,如需配置大量的服務器,可提取腳本中的bonding函數,稍作修改即可,你值得一試!

1.適用范圍

該shell腳本可在以下linux系統創建多個綁定網卡,用于生產環境沒問題的:

  • Redhat 5.x
  • CentOS 5.x
  • Kylin 3.x
  • KUX 2.x

2.腳本特點

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   :eth0Second NIC  :eth1bond name   :bond1IP address  :192.168.56.11netmask    :255.255.255.0bonding_mode :mode=1primary NIC  :none----------------------------------------------Pls make sure its OK[y/n]:y

如上,腳本在使用過程中,會依次提示輸入需要綁定的子網卡名稱、綁定網卡名稱、IP地址和子網掩碼、綁定模式、是否指定主網卡,并主動對系統中可用網卡進行識別并列出,供用戶選擇,同時會判斷輸入的各項信息的正確性,保障雙網卡綁定順利進行。

3.使用說明

首先將腳本上傳至linux系統任意目錄下,使用root用戶執行:

[root@node1 tmp]# sh bonding_v2.0.sh ---------------------------------------------------- Network Configuration Assistant ---------------------------------------------------- 4 network cards available:eth0 eth1 eth2 eth3----------------------------------------------Please enter the First NIC:_

首先腳本會列出系統中有多少可用網卡,并提示輸入需要綁定的第一塊子網卡的名稱,這里輸入eth2。

無需擔心輸入錯誤,輸入重復等問題,腳本會自動判斷你的輸入信息是否正確。

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------4 network cards available:eth0 eth1 eth2 eth3The information you have entered:First NIC   : eth2----------------------------------------------Please select the second NIC:_

接著輸入需要綁定的第二塊網卡的名稱eth3,如果輸入錯誤會出現相應的提示,比如錯輸入為eth8,會提示需要重新輸入:

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------4 network cards available:eth0 eth1 eth2 eth3The information you have entered:First NIC   : eth2----------------------------------------------eth8 is not available,Please enter another one.Please select the second NIC:_

正確輸入需要綁定的第二塊網卡eth3后,如果linux系統中之前不存在綁定網卡,則默認第一個綁定網卡的名稱為bond0,如果系統中存在綁定網卡,腳本會提示輸入bondN(N為數字):

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   : eth2Second NIC  : eth3bond name   : bond0----------------------------------------------The default first bond name is -- bond0.Please enter an IP address:_

按照提示輸入需要綁定的IP地址,比如10.1.1.1

腳本會自動判斷輸入的IP地址格式和范圍是否正確,無需擔心輸入錯誤

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   : eth2Second NIC  : eth3bond name   : bond0IP address  : 10.1.1.1----------------------------------------------Pls enter the NETMASK[255.255.255.0]:_

輸入IP地址后,會提示輸入子網掩碼,默認為255.255.255.0,直接回車即可,也可以輸入自定義的子網掩碼。

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   : eth2Second NIC  : eth3bond name   : bond0IP address  : 10.1.1.1netmask    : 255.255.255.0----------------------------------------------Pls enter the bonding_mode[default:mode=1,active-backup]:_

這一步是輸入網卡綁定級別,默認使用主備模式:mode=1,直接回車即可,也可以輸入自定義的綁定級別(如輸入 mode=6),格式為:

mode={0,1,2,3,4,5,6}---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   :eth2Second NIC  :eth3bond name   :bond0IP address  :10.1.1.1netmask    :255.255.255.0bonding_mode :mode=1----------------------------------------------1-eth22-eth33-nonechoose whether to set up the primary NIC or not[default:3-none]:_

此時腳本提示是否設置primary網卡,primary網卡的作用是在子網卡均正常時,primary網卡優先處于活動狀態,這里默認為不設置primary網卡,也可以輸入數字1或2選擇一個網卡為primary網卡。

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   :eth2Second NIC  :eth3bond name   :bond0IP address  :10.1.1.1netmask    :255.255.255.0bonding_mode :mode=1primary NIC  :none----------------------------------------------Pls make sure its OK[y/n]:_

至此,所有信息輸入完畢,腳本會讓您判斷輸入的所有信息是否正確,正確則輸入y,進行下一步操作,否則輸入n,重新輸入以上信息。

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------Complete!File backup directory: /etc/sysconfig/network-scripts/inspur_bakyou can check the file and then restart the network service.1 ) service network restart2 ) exit----------------------------------------------Please make your choice:_

看到這里時,所有綁定網卡的配置文件已經修改完畢了,輸入1重啟網絡服務;輸入2直接退出腳本。

建議選擇重啟網絡服務,如果直接退出腳本而不重啟網絡服務,修改的配置文件是不會生效的,并且在使用該腳本創建下一個綁定網卡時顯示信息會出現異常(因為腳本通過ifconfig命令獲取當前網卡信息)。

you can check the file and then restart the network service.1 ) service network restart2 ) exit  ----------------------------------------------Please make your choice:1正在關閉接口 eth0:                    [確定]正在關閉接口 eth1:                    [確定]正在關閉接口 eth2:                    [確定]正在關閉接口 eth3:                    [確定]關閉環回接口:                       [確定]彈出環回接口:                       [確定]彈出界面 bond0: RTNETLINK answers: File exists在 bond0 添加地址 10.1.1.1 時出錯。                              [確定]彈出界面 eth0:                      [確定]彈出界面 eth1:                      [確定]

第一次重啟網絡服務時可能會出現以上類似報錯,無需擔心,其實配置已經完成,再次重啟網絡服務即恢復正常。

在綁定過程中修改的配置文件如下:

[root@node1 tmp]# cd /etc/sysconfig/network-scripts/[root@node1 network-scripts]# cat ifcfg-bond0 DEVICE=bond0BOOTPROTO=noneONBOOT=yesTYPE=EthernetUSERCTL=noIPV6INIT=noPEERDNS=yesIPADDR=10.1.1.1NETMASK=255.255.255.0BONDING_OPTS="miimon=100 mode=1"[root@node1 network-scripts]# cat ifcfg-eth2 DEVICE=eth2BOOTPROTO=none#HWADDR=08:00:27:41:b4:16ONBOOT=yesTYPE=EthernetUSERCTL=noIPV6INIT=noPEERDNS=yesSLAVE=yesMASTER=bond0[root@node1 network-scripts]# cat ifcfg-eth3DEVICE=eth3BOOTPROTO=none#HWADDR=08:00:27:6c:3d:0cONBOOT=yesTYPE=EthernetUSERCTL=noIPV6INIT=noPEERDNS=yesSLAVE=yesMASTER=bond0[root@node1 network-scripts]# cat /etc/modprobe.confalias scsi_hostadapter ata_piixalias scsi_hostadapter1 ahcialias net-pf-10 offalias ipv6 offoptions ipv6 disable=1alias snd-card-0 snd-intel8x0options snd-card-0 index=0options snd-intel8x0 index=0remove snd-intel8x0 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-intel8x0alias eth0 e1000alias eth1 e1000alias eth2 e1000alias eth3 e1000alias bond0 bonding

網絡配置信息如下:

[root@node1 tmp]# ifconfig bond0   Link encap:Ethernet HWaddr 08:00:27:41:B4:16      inet addr:10.1.1.1 Bcast:10.1.1.255 Mask:255.255.255.0     UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1     RX packets:1197 errors:0 dropped:0 overruns:0 frame:0     TX packets:125 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:0      RX bytes:106338 (103.8 KiB) TX bytes:16662 (16.2 KiB)eth0   Link encap:Ethernet HWaddr 08:00:27:35:B4:81      inet addr:192.168.56.11 Bcast:192.168.56.255 Mask:255.255.255.0     UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1     RX packets:1487 errors:0 dropped:0 overruns:0 frame:0     TX packets:1190 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:1000      RX bytes:146576 (143.1 KiB) TX bytes:151787 (148.2 KiB)eth1   Link encap:Ethernet HWaddr 08:00:27:72:08:46      inet addr:10.1.1.11 Bcast:10.1.1.255 Mask:255.255.255.0     UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1     RX packets:193 errors:0 dropped:0 overruns:0 frame:0     TX packets:455 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:1000      RX bytes:31434 (30.6 KiB) TX bytes:22657 (22.1 KiB)eth2   Link encap:Ethernet HWaddr 08:00:27:41:B4:16      UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1     RX packets:591 errors:0 dropped:0 overruns:0 frame:0     TX packets:93 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:1000      RX bytes:55217 (53.9 KiB) TX bytes:10511 (10.2 KiB)eth3   Link encap:Ethernet HWaddr 08:00:27:41:B4:16      UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1     RX packets:606 errors:0 dropped:0 overruns:0 frame:0     TX packets:32 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:1000      RX bytes:51121 (49.9 KiB) TX bytes:6151 (6.0 KiB)lo    Link encap:Local Loopback      inet addr:127.0.0.1 Mask:255.0.0.0     UP LOOPBACK RUNNING MTU:16436 Metric:1     RX packets:3297 errors:0 dropped:0 overruns:0 frame:0     TX packets:3297 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:0      RX bytes:4725726 (4.5 MiB) TX bytes:4725726 (4.5 MiB)

雙網卡綁定信息:

[root@node1 tmp]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.4.0-2 (October 7, 2008)Bonding Mode: fault-tolerance (active-backup)Primary Slave: NoneCurrently Active Slave: eth2MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth2MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 08:00:27:41:b4:16Slave Interface: eth3MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 08:00:27:6c:3d:0c

4.腳本代碼

#!/bin/bash# Date:2018-11-26 14:28:45# Author:ZhangJian# Mail:[email protected]# Func:Configure Network Bonding# Version:2.0#V1.6版本更新:不再將綁定的模式mode=x寫入modprobe.conf文件,將其寫入ifcfg-bond中,因為在modprobe.conf文件中時,修改了mode模式后,重啟網絡服務可能不生效。#V2.0版本更新:將primary網卡設置為可選擇項。trap "tput clear;tput cup 3;echo 'Any Questions: Send a message to QQ 1037509307.';tput cup 6;exit" 2 3if [[ -n $1 ]]; then cat <<EOFNetwork Configuration Assistant          --- Configure Network Bonding v1.5Usage:    sh $0    chmod +x $0 && ./$0EOFexit 0fiif [[ $UID -ne 0 ]]; then tput clear tput cup 6 20 echo -e "You must use the user: /033[31mROOT/033[0m" tput cup 10 exitfiERROR(){tput cup $1 $2;tput edecho 'Input error,Try again pls.'echo -e 'Press ENTER to continue..._/b/c'read inputA}Check_BakFile(){#文件備份函數#使用方法:#Check_BakFile 要備份的文件名 備份目錄 -x(按什么時間格式備份)case ${3} in  -d ) #按天備份    Bak_Date=`date '+%Y-%m-%d'`    ;;  -H ) #按小時備份    Bak_Date=`date '+%Y-%m-%d_%H'`    ;;  -M ) #按分鐘備份    Bak_Date=`date '+%Y-%m-%d_%H:%M'`    ;;  -m ) #按月備份    Bak_Date=`date '+%Y-%m'`    ;;  -Y ) #按年備份    Bak_Date=`date '+%Y'`    ;;  * ) #默認按分鐘備份    Bak_Date=`date '+%Y-%m-%d_%H:%M'`    ;;esac#Bak_Date=`date '+%Y-%m-%d-%H:%M'`[[ -d ${2}/${Bak_Date} ]] || mkdir -p ${2}/${Bak_Date}cp -ra ${1} ${2}/${Bak_Date}}bonding_pre(){#雙網卡綁定前導函數,判定網卡、IP等合法性并引導用戶正確輸入參數。#全部真實網卡NIC_NAME_all=`ifconfig -a | awk '//<Ethernet/>/ {print $1}' | grep -wEv '^bond[0-9]+'`#已經存在的綁定網卡NIC_NAME_bond=`ifconfig -a | awk '/^/<bond[0-9]+/>/ {print $1}'`#打印出已經是SLAVE的網卡NIC_NAME_slave=`ifconfig -a | sed -n '/SLAVE/{g;1!p;};h' | awk '{print $1}'`NIC_NAME_slave=${NIC_NAME_slave:=NULL}#打印出可用網卡NIC_NAME_free=`echo "$NIC_NAME_all" | grep -Fwv "$NIC_NAME_slave"`#可用網卡數量NIC_NAME_free_nu=`echo "$NIC_NAME_free" | wc -w`declare -a NIC_LISTNIC_LIST=($NIC_NAME_free)info_print(){tput clear;tput cup 2cat <<EOF---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------EOFtput cup 7if [[ -n ${1} ]]; then echo -e "Already existing Channel Bonding Interface of the system:/n/033[31m${1}/033[0m/n"fi}if [[ "$NIC_NAME_free_nu" -gt 1 ]]; then info_print echo -e "/033[031m$NIC_NAME_free_nu/033[0m network cards available:" echo -e "/033[31m${NIC_LIST[@]}/033[0m" echo -e "----------------------------------------------/n" #輸入第一塊網卡的名稱 while true; do  echo -e "/nPlease enter the First NIC:_/b/c"  read NIC1  echo ${NIC_LIST[@]} | grep -Fw "$NIC1" &> /dev/null  if [[ $? -eq 0 ]]; then   info_print   echo -e "/033[031m$NIC_NAME_free_nu/033[0m network cards available:/n/033[31m${NIC_LIST[@]}/033[0m"   echo -e "/nThe information you have entered:/nFirst NIC   : $NIC1"   echo -e "----------------------------------------------/n"   break  else   info_print   echo -e "/033[031m$NIC_NAME_free_nu/033[0m network cards available:/n/033[31m${NIC_LIST[@]}/033[0m"   echo -e "----------------------------------------------/n"   echo -e "/033[31m${NIC1}/033[0m is not available,Please enter another one."  fi done #輸入第二塊網卡的名稱 while true; do  echo -e "/nPlease select the second NIC:_/b/c"  read NIC2  if [[ ${NIC1} != ${NIC2} ]]; then   echo ${NIC_LIST[@]} | grep -Fw "${NIC2}" &> /dev/null   if [[ $? -eq 0 ]]; then    info_print "${NIC_NAME_bond}"    echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}"    echo -e "----------------------------------------------/n"    break   else    info_print    echo -e "/033[031m$NIC_NAME_free_nu/033[0m network cards available:/n/033[31m${NIC_LIST[@]}/033[0m/n/nThe information you have entered:/nFirst NIC   : ${NIC1}"    echo -e "----------------------------------------------/n"    echo -e "/033[31m${NIC2}/033[0m is not available,Please enter another one."   fi  else   info_print   echo -e "/033[031m${NIC_NAME_free_nu}/033[0m network cards available:/n/033[31m${NIC_LIST[@]}/033[0m/n/nThe information you have entered:/nFirst NIC   : ${NIC1}"   echo -e "----------------------------------------------/n"   echo -e "/033[31m${NIC2}/033[0m is the first NIC,Please enter another one."  fi done #輸入綁定網卡名稱并進行合理性檢查 if [[ -z ${NIC_NAME_bond} ]]; then  NAME_bond=bond0  info_print  echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}"  echo -e "----------------------------------------------/n"  echo "The default first bond name is -- bond0." else  while true; do   echo -e "/nPlease enter a bond name[bonN]:_/b/c"   read NAME_bond   #檢查輸入格式是否為bond+數字的格式。   echo "${NAME_bond}" | grep -wE '^bond[[:digit:]]+$' &> /dev/null   if [[ $? -eq 0 ]]; then    echo "${NIC_NAME_bond}" | grep -Fw "${NAME_bond}" &> /dev/null    if [[ $? -ne 0 ]]; then     info_print "${NIC_NAME_bond}"     echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}"     echo -e "----------------------------------------------/n"     break    else     info_print "${NIC_NAME_bond}"     echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}"     echo -e "----------------------------------------------/n"     echo "You can not use an existing name: ${NAME_bond}"     echo -e "/033[31m${NAME_bond}/033[0m is not available,Please enter another one like -- bondN."    fi   else    info_print "${NIC_NAME_bond}"    echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}"    echo -e "----------------------------------------------/n"    echo -e "/033[31m${NAME_bond}/033[0m is not available,Please enter another one like -- bondN."   fi  done fi #設置IP地址 while true; do  echo -e "/nPlease enter an IP address:_/b/c"  read IP_bond  echo "${IP_bond}" | grep -owE '^(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-5]{2})/.){3}([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-5]{2})$' &> /dev/null  if [[ $? -eq 0 ]]; then   info_print   echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}/nIP address  : ${IP_bond}"   echo -e "----------------------------------------------/n"   break  else   info_print   echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}"   echo -e "----------------------------------------------/n"   echo -e "IP address: /033[31m${IP_bond}/033[0m format errors, please re-enter."  fi done #設置netmask while true; do  echo -e "/nPls enter the NETMASK[255.255.255.0]:_/b/c"  read NETMASK_bond  NETMASK_bond=${NETMASK_bond:="255.255.255.0"}  #當變量為NETMASK_bond為空時,給其賦默認值255.255.255.0  echo "$NETMASK_bond" | grep -owE '^(128|192|224|240|248|252|254|255)/.((0|128|192|224|240|248|252|254|255)/.){2}(0|128|192|224|240|248|252|254|255)$' &> /dev/null  if [[ $? -eq 0 ]]; then   info_print   echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}/nIP address  : ${IP_bond}/nnetmask    : ${NETMASK_bond}"   echo -e "----------------------------------------------/n"   break  else   info_print   echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}/nIP address  : ${IP_bond}"   echo -e "----------------------------------------------/n"   echo -e "Input error./nPlease enter the correct NETMASK or press ENTER to use 255.255.255.0./n"  fi done#:<<!zhushi! #批量注釋,如果開啟批量注釋,默認mode=1 while true; do  echo -e "/nPls enter the bonding_mode[default:mode=1,active-backup]:_/b/c"  read mode_bond  mode_bond=${mode_bond:="mode=1"}  #當變量為mode_bond為空時,給其賦默認值1  if [[ ! ${mode_bond} =~ "mode=[0-6]" ]]; then   info_print   echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}/nIP address  : ${IP_bond}/netmask    : ${NETMASK_bond}"   echo -e "----------------------------------------------/n"   echo "Invalid answer: ${mode_bond}"   echo "Eg: mode={0,1,2,3,4,5,6}"  else   info_print   echo -e "The information you have entered:/n"   echo -e "First NIC   :${NIC1}/nSecond NIC  :${NIC2}/nbond name   :${NAME_bond}/nIP address  :${IP_bond}/nnetmask    :${NETMASK_bond}/nbonding_mode :${mode_bond}"   echo -e "----------------------------------------------/n"   break  fi done#!zhushi! #選擇是否設置primary網卡 while true; do  echo "1-${NIC1}"  echo "2-${NIC2}"  echo "3-none"  echo -e "choose whether to set up the primary NIC or not[default:3-none]:_/b/c"  read get_primary_NIC  get_primary_NIC=${get_primary_NIC:="none"}    case ${get_primary_NIC} in    1 )     get_primary_NIC=${NIC1}     #echo "--$get_primary_NIC"     break     ;;    2 )     get_primary_NIC=${NIC2}      #echo "--$get_primary_NIC"     break     ;;    3 )     get_primary_NIC=none      #echo "--$get_primary_NIC"     break     ;;    none )     break     ;;    * )      #echo "--$get_primary_NIC"     info_print     echo -e "The information you have entered:/nFirst NIC   : ${NIC1}/nSecond NIC  : ${NIC2}/nbond name   : ${NAME_bond}/nIP address  : ${IP_bond}/nnetmask    : ${NETMASK_bond}"     echo -e "----------------------------------------------/n"     echo "Invalid answer: ${get_primary_NIC}"     echo "Pls input a number in {1,2,3} or press ENTER to set up primary NIC none."     continue     ;;   esac   info_print   echo -e "The information you have entered:/n"   echo -e "First NIC   :${NIC1}/nSecond NIC  :${NIC2}/nbond name   :${NAME_bond}/nIP address  :${IP_bond}/nnetmask    :${NETMASK_bond}/nbonding_mode :${mode_bond}/nprimary NIC  :${get_primary_NIC}"   echo -e "----------------------------------------------/n"   break done #最終輸入信息確認 while true; do  info_print  echo -e "The information you have entered:/n"  echo -e "/033[31mFirst NIC   :${NIC1}/nSecond NIC  :${NIC2}/nbond name   :${NAME_bond}/nIP address  :${IP_bond}/nnetmask    :${NETMASK_bond}/nbonding_mode :${mode_bond}/nprimary NIC  :${get_primary_NIC}/033[0m"  echo -e "----------------------------------------------/n"  echo -e "Pls make sure its OK[y/n]:_/b/c"  read input  case ${input} in   [Yy]|[Yy][Ee][Ss] )    bonding "$NIC1" "$NIC2" "$NAME_bond" "$IP_bond" "$NETMASK_bond"    break    ;;   [Nn]|[Nn][Oo] )    bonding_pre   ;;   * )    tput cup 7;tput ed    ERROR 7 10   ;;  esac doneelse  info_print  echo -e "You have /033[031m${NIC_NAME_free_nu}/033[0m network cards available:/n"  #將重點顯示的“網卡名”標示為紅色  echo -e "/033[31m${NIC_LIST[@]}/033[0m/n"  echo -e "There are /033[31mnot enough/033[0m network cards to make bonding"  echo -e "Pls check it....../n"  echo -e 'Press ENTER to exit..._/b/c'  read answer  exit 1fi}bonding(){if [[ $# -lt 5 ]]then echo 'Bonding failed! Please provide enough information!' echo -e "/nUsage:/n    sh bonding.sh <NIC1_name> <NIC2_name> <bond_name> <IP> <NETMASK>/n/n" exit 1fi#get device name and ip informationSLAVE1_DEV="$1"    #SLAVE1_DEV=ethxSLAVE2_DEV="$2"    #SLAVE2_DEV=ethxBOND_DEV="$3"     #BOND_DEV=bondxSLAVE1=ifcfg-"$1"SLAVE2=ifcfg-"$2"BOND=ifcfg-"$3"BOND_IPADDR="$4"BOND_NETMASK="$5"BOND_DIR=/etc/sysconfig/network-scriptsif [ -e $BOND_DIR/$BOND ]then echo $BOND_DIR/$BOND is already existelse #file backup Check_BakFile "${BOND_DIR}/ifcfg-*" "${BOND_DIR}/inspur_bak" "-M"#get mac address SLAVE1_MAC=`grep 'HWADDR' ${BOND_DIR}/${SLAVE1}` SLAVE2_MAC=`grep 'HWADDR' ${BOND_DIR}/${SLAVE2}` # modify $BOND touch $BOND_DIR/$BOND echo "DEVICE=${BOND_DEV}" >> $BOND_DIR/$BOND echo "BOOTPROTO=none" >> $BOND_DIR/$BOND echo "ONBOOT=yes" >> $BOND_DIR/$BOND echo "TYPE=Ethernet" >> $BOND_DIR/$BOND echo "USERCTL=no" >> $BOND_DIR/$BOND echo "IPV6INIT=no" >> $BOND_DIR/$BOND echo "PEERDNS=yes" >> $BOND_DIR/$BOND echo "IPADDR=${BOND_IPADDR}" >> $BOND_DIR/$BOND echo "NETMASK=${BOND_NETMASK}" >> $BOND_DIR/$BOND if [[ ${get_primary_NIC} == none ]]; then   echo "BONDING_OPTS=/"miimon=100 ${mode_bond}/"" >> $BOND_DIR/$BOND else   echo "BONDING_OPTS=/"miimon=100 ${mode_bond} primary=$(echo ${SLAVE1} | cut -d'-' -f2)/"" >> $BOND_DIR/$BOND fi # modify $SLAVE1 > $BOND_DIR/$SLAVE1 echo "DEVICE=${SLAVE1_DEV}" >> $BOND_DIR/$SLAVE1 echo 'BOOTPROTO=none' >> $BOND_DIR/$SLAVE1 #cat $BOND_DIR/../ifcfg-bak/$SLAVE1 |grep HWADDR >> $BOND_DIR/$SLAVE1 echo "#$SLAVE1_MAC" >> $BOND_DIR/$SLAVE1 echo ONBOOT=yes >> $BOND_DIR/$SLAVE1 echo TYPE=Ethernet >> $BOND_DIR/$SLAVE1 echo USERCTL=no >> $BOND_DIR/$SLAVE1 echo IPV6INIT=no >> $BOND_DIR/$SLAVE1 echo PEERDNS=yes >> $BOND_DIR/$SLAVE1 echo SLAVE=yes >> $BOND_DIR/$SLAVE1 echo MASTER=$BOND_DEV >> $BOND_DIR/$SLAVE1 # modify SLAVE2 > $BOND_DIR/$SLAVE2 echo "DEVICE=$SLAVE2_DEV" >> $BOND_DIR/$SLAVE2 echo BOOTPROTO=none >> $BOND_DIR/$SLAVE2 #cat $BOND_DIR/../ifcfg-bak/$SLAVE2 |grep HWADDR >> $BOND_DIR/$SLAVE2 echo "#$SLAVE2_MAC" >> $BOND_DIR/$SLAVE2 echo ONBOOT=yes >> $BOND_DIR/$SLAVE2 echo TYPE=Ethernet >> $BOND_DIR/$SLAVE2 echo USERCTL=no >> $BOND_DIR/$SLAVE2 echo IPV6INIT=no >> $BOND_DIR/$SLAVE2 echo PEERDNS=yes >> $BOND_DIR/$SLAVE2 echo SLAVE=yes >> $BOND_DIR/$SLAVE2 echo MASTER=$BOND_DEV >> $BOND_DIR/$SLAVE2 [[ -e /etc/modprobe.conf.bak ]] && cp /etc/modprobe.conf /etc/modprobe.conf.bak.new || cp /etc/modprobe.conf /etc/modprobe.conf.bak echo "alias $BOND_DEV bonding" >> /etc/modprobe.confwhile true; do tput clear;tput cup 2cat <<EOF---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------Complete!File backup directory: ${BOND_DIR}/inspur_bakyou can check the file and then restart the network service.1 ) service network restart2 ) exit----------------------------------------------EOF  echo -e "Please make your choice:_/b/c"  read answer   case ${answer} in    1 )     service network restart     exit 0     ;;    2 )     exit 0     ;;   esac donefi}main(){ while true; do  bonding_pre done}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到服務器教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 圆产精品久久久久久久久久久 | 久久综合婷婷香五月 | 午夜伦情电午夜伦情电影 | 青草伊人网 | 国产精品久久久久久久久久妇女 | 欧美大胆xxxx肉体摄影 | 国产精品久久久久久久久久 | 九草网| 免费啪视频在线观看 | 精品一区二区三区在线观看视频 | 国产一级免费视频 | 欧美性激情视频 | 国产精品自在线拍 | 欧美成人黄色片 | 久久亚洲春色中文字幕久久 | 免费在线中文字幕 | 欧美精品免费一区二区三区 | 久久久入口 | 久国产| 久久精品视频黄色 | 日本高清在线免费 | 91成人免费视频 | 久久精精品 | 在线观看一二区 | 91 免费看片 | 色玖玖综合 | av在线播放免费观看 | 欧美大屁股精品毛片视频 | 欧美一级黄色免费 | xxxxxx视频 | 九九热九九热 | 国产精品成人久久久久a级 欧美特黄一级高清免费的香蕉 | 午夜视频亚洲 | 毛片在线免费观看视频 | 中文字幕一区二区三区久久 | 曰批全过程120分钟免费69 | 91网站免费观看 | 爽毛片 | 三人弄娇妻高潮3p视频 | 欧美日韩亚洲国产精品 | 久草在线综合 |