双网卡bond脚本

本脚本用于实现网卡bonding 可以监控bonding 停止bonding


[root@crushlinux ~]# vi /etc/init.d/bond
#!/bin/bash
# chkconfig: 345 10 90
# description: Activates/Deactives bonding device
# filename: bond.sh
# auth: crushlinux
# date: 2013/09/28
IP=192.168.1.254
NETMASK=255.255.255.0
id root &>/dev/null||exit 1
start () {
/sbin/ifenslave bond0 &>/dev/null&&exit 0
/sbin/modprobe bonding mode=1 miimon=100
/sbin/ifconfig bond0 $IP netmask $NETMASK
/sbin/ifenslave bond0 eth0
/sbin/ifenslave bond0 eth1
}
stop () {
/sbin/ifenslave bond0 &>/dev/null||exit 1
/sbin/ifenslave -d bond0 eth0
/sbin/ifenslave -d bond0 eth1
/sbin/modprobe -r bonding
}
status () {
if
/sbin/ifenslave bond0 &>/dev/null
then
echo "Bonding is run"
echo "The ip address is `ifconfig bond0|grep 'inet addr'|awk '{print $2}'|awk -F: '{print $2}'`"
else
echo "Bonding is down"
fi
}
case $1 in
start)start;;
stop)stop;;
status)status;;
*)echo $"Usage: $0 {start|stop|status}"
esac
exit 0

将此脚本添加到chkconfig来管理

[root@crushlinux ~]# chmod a+x /etc/init.d/bond
[root@crushlinux ~]# chkconfig --add bond
[root@crushlinux ~]# chkconfig --list bond
[root@crushlinux ~]# service bond start
[root@crushlinux ~]# ifconfig


本文出自 “Crushlinux” 博客,谢绝转载!

你可能感兴趣的:(双网卡bond脚本)