#!/bin/sh
##############################################################
#
# function: create linux bridge, centos 5 test pass.
# user: chenjian
# date : 2011-06-30 ^_^.
#
##############################################################
NETWORK_DIR=/etc/sysconfig/network-scripts
if ! `rpm -qi bridge-utils > /dev/null`;
then
echo "bridge-utils package not install."
fi
rm -rf $NETWORK_DIR/ifcfg-br*
read -p "Input your bridge name,ex br0: "
if [ `echo $REPLY|wc -L` -eq 0 ];
then
REPLY=br0
fi
BRIDGE=$REPLY
ETHERNET_ALL=$( ls -l $NETWORK_DIR|awk -F- /ifcfg-eth/{print $8})
while [ `echo $REPLY|wc -w` -lt 2 ];
do
read -p "Input you need to use the network adapter, separated by a space. current cards(`echo $ETHERNET_ALL`),chose two : "
done
ETHERNET=$REPLY
for i in `seq 1 3`;
do
read -p "Input the bridge ip address and netmask. separated by a space: "
if [ `echo $REPLY|wc -L` -eq 0 ];
then
echo "Input empty. this bridage will no ip address. "
REPLY="0.0.0.0 0.0.0.0"
sleep 3
break
elif `echo $REPLY|grep -v [0-9]. > /dev/null`;
then
echo "Use only numbers and points."
elif [ `echo $REPLY|awk {print $2}|wc -L` -eq 0 ]
then
echo "Input errors, exit."
exit 2
else
break
fi
done
IP=`echo $REPLY|awk {print $1}`
NETMASK=`echo $REPLY|awk {print $2}`
brctl addbr $BRIDGE
cat > $NETWORK_DIR/ifcfg-$BRIDGE <<-EOF
DEVICE=$BRIDGE
BOOTPROTO=static
ONBOOT=yes
NETMASK=$NETMASK
IPADDR=$IP
TYPE=Bridge
EOF
echo -------------------------------------
echo "Bridge info "
echo -------------------------------------
cat $NETWORK_DIR/ifcfg-$BRIDGE
echo ""
for i in `echo $ETHERNET`;
do
MAC=$(ifconfig $i|awk /HWaddr/{print $NF })
cat > $NETWORK_DIR/ifcfg-$i <<EOF
DEVICE=$i
HWADDR=$MAC
BOOTPROTO=none
ONBOOT=yes
HOTPLUG=no
TYPE=Ethernet
BRIDGE=$BRIDGE
EOF
echo -------------------------------------
echo "$i info"
echo -------------------------------------
cat $NETWORK_DIR/ifcfg-$i
echo ""
done
echo ""
echo -------------------------------------
echo -e "install successful ,you need to restart your network"
echo -------------------------------------
exit 0; (免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)