centos下多網(wǎng)卡做bond腳本
多網(wǎng)卡或者單網(wǎng)卡形式下的網(wǎng)卡bonding
#! /bin/sh
#獲取當(dāng)前網(wǎng)卡數(shù)
ethnum=`lspci | grep Ethernet | wc -l`
echo $ethnum
#如果網(wǎng)卡數(shù)小于等于1則什么都不做
if [ $ethnum -le 1 ]
then
echo "do nothing!"
fi
#如果網(wǎng)卡數(shù)大于等于2則
if [ $ethnum -ge 2 ]
then
#-------? 添加一個bond0的網(wǎng)卡
echo "DEVICE=bond0" > /etc/sysconfig/network-scripts/ifcfg-bond0
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-bond0
echo "IPADDR=192.168.3.104" >> /etc/sysconfig/network-scripts/ifcfg-bond0
echo "NETMASK=255.255.0.0" >> /etc/sysconfig/network-scripts/ifcfg-bond0
echo "GATEWAY=192.168.1.1" >> /etc/sysconfig/network-scripts/ifcfg-bond0
echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/ifcfg-bond0
echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-bond0
#--------
echo "ifenslave bond0" >> /etc/rc.local
#--------寫其他網(wǎng)卡的配置文件
for i in $(seq $ethnum);
do
num=`expr $i - 1`
echo "BOOTPROTO=none" >? /etc/sysconfig/network-scripts/ifcfg-eth$num
echo "DEVICE=eth$num" >>? /etc/sysconfig/network-scripts/ifcfg-eth$num
echo "ONBOOT=yes" >>? /etc/sysconfig/network-scripts/ifcfg-eth$num
echo "MASTER=bond0" >>? /etc/sysconfig/network-scripts/ifcfg-eth$num
echo "USERCTL=no" >>? /etc/sysconfig/network-scripts/ifcfg-eth$num
echo "SLAVE=yes" >>? /etc/sysconfig/network-scripts/ifcfg-eth$num
sed -i 's/ifenslave.*/& eth'"$num"'/g' /etc/rc.local
done;
echo "alias bond0 bonding" > /etc/modprobe.d/modprobe.conf
echo "options bond0 miimon=100 mode=balance-rr" >> /etc/modprobe.d/modprobe.conf
modprobe bonding
/etc/init.d/network? restart
fi