易网时代-编程资源站
Welcome
微信登录
首页
/
操作系统
/
Linux
/
Linux 配置网桥脚本
Linux 配置网桥脚本
#!/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; <!--cjhp13141人了这篇文章-->
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图