首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 系统运维 >

更新-Scripts:实施双网卡绑定

2013-09-07 
更新-----Scripts:执行双网卡绑定#!/bin/bash#-------------------------------------------# Name:netbon

更新-----Scripts:执行双网卡绑定

#!/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 1fi if [ x$5 = x ]; thenecho "Input Error!"echo "Usage: sh ./netbond.sh ethN ethN bondN ipaddr netmask gateway"exit 1fiSCRIPTFILE=$0ETHN1=$1ETHN2=$2BONDN=$3IPADDR=$4NETMASK=$5GATEWAY=$6ETHN1FILE=/etc/sysconfig/network-scripts/ifcfg-$ETHN1ETHN2FILE=/etc/sysconfig/network-scripts/ifcfg-$ETHN2BONDFILE=/etc/sysconfig/network-scripts/ifcfg-$BONDNETHN1BAK=ifcfg-$ETHN1.bakETHN2BAK=ifcfg-$ETHN2.bakif [ `echo $ETHN1 |grep 'eth'|wc -l` -eq 0 ]; then        echo "Input Error: ethN1"fiif [ `echo $ETHN2 |grep 'eth'|wc -l` -eq 0 ]; then        echo "Input Error: ethN2"fiif [ `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"#fiif [ `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"fiif [ `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"fiif [ `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"fiif [ ! -f $ETHN1FILE ]; thenecho "Error!Not exist $ETHN1FILE"exit 1fiif [ ! -f $ETHN2FILE ]; thenecho "Error!Not exist $ETHN2FILE"exit 1fiif [ -f $BONDFILE ]; thenecho "Error!Exist $BONDFILE"exit 1fiecho "Set Info: $ETHN1 AND $ETHN2 will bond to $BONDN : $IPADDR,$NETMASK,$GATEWAY"echo "Go On?[Y/N]"read GOONGOON1=`echo $GOON |tr 'a-z' 'A-Z'|cut -c1`if [ $GOON1 = "Y" ]; thencp $ETHN1FILE ETHN1BAKcp $ETHN2FILE ETHN2BAKif [ -f ETHN1BAK ] && [ -f ETHN2BAK ] ; thenecho -e "DEVICE=$BONDN\nONBOOT=yes\nTYPE=Ethernet\nUSERCTL=yes\nBOOTPROTO=static\nIPADDR=$IPADDR\nNETMASK=$NETMASK\nGATEWAY=$GATEWAY">$BONDFILEchmod 644 $BONDFILEecho -e "DEVICE=$ETHN1\nONBOOT=yes\nBOOTPROTO=none\nTYPE=Ethernet\nUSERCTL=yes\nMASTER=$BONDN\nSLAVE=yes">$ETHN1FILEecho -e "DEVICE=$ETHN2\nONBOOT=yes\nBOOTPROTO=none\nTYPE=Ethernet\nUSERCTL=yes\nMASTER=$BONDN\nSLAVE=yes">$ETHN2FILEcat /etc/modprobe.conf |grep "$BONDN">nullRESULT=$?if [ $RESULT -eq 1 ] ; thenecho -e "alias $BONDN bonding\noptions $BONDN miimon=100 mode=1">>/etc/modprobe.confficat /etc/rc.d/rc.local|grep "$BONDN">nullRESULT=$?if [ $RESULT -eq 1 ] ; thenecho -e "ifenslave $BONDN $ETHN1 $ETHN2">>/etc/rc.d/rc.localfiecho "Done!Pls reboot system!"fielseecho "Cancel!"fi


热点排行