全部博文(230)
分类: LINUX
2006-01-26 02:16:17
初步测试成功,可以实现热切换,不必等待漫长的 arp time out,但需要一块心跳网卡
#! /bin/bash
LAN_IP=192.168.0.254
LAN_MASK=255.255.255.0
WAN_IP=172.17.39.250
WAN_MASK=255.255.255.0
WAN_GATEWAY=172.17.39.254
OTHER_IP="10.1.1.1"
WAN_ETH=eth0
LAN_ETH=eth1
LAST_FLAG=M
SLEEP=10
WAN_MAC=`ip addr list dev $WAN_ETH|grep ether|awk '{print $2}'`
LAN_MAC=`ip addr list dev $LAN_ETH|grep ether|awk '{print $2}'`
while : ; do
LOCAL_IP=`ifconfig eth2|grep inet|awk '{print $2}'|awk -F: '{print $2}'`
if [ "$LOCAL_IP" != "$OTHER_IP" ]; then
if ping -c1 -w1 $OTHER_IP &>/dev/null; then
if [ "$LAST_FLAG" = "S" ]; then
ifconfig $WAN_ETH down
ifconfig $LAN_ETH down
ifconfig $WAN_ETH hw ether $WAN_MAC
ifconfig $LAN_ETH hw ether $LAN_MAC
ifconfig eth2 10.1.1.2 netmask 255.255.255.252
LAST_FLAG=M
fi
else
if [ "$LAST_FLAG" = "M" ]; then
ifconfig $WAN_ETH down
ifconfig $LAN_ETH down
ifconfig $WAN_ETH hw ether 00:01:19:80:03:09
ifconfig $LAN_ETH hw ether 00:02:19:80:03:09
ifconfig $WAN_ETH $WAN_IP netmask $WAN_MASK
ifconfig $LAN_ETH $LAN_IP netmask $LAN_MASK
ip route replace via $WAN_GATEWAY
ifconfig eth2 10.1.1.1 netmask 255.255.255.252
LAST_FLAG=S
fi
fi
fi
sleep $SLEEP
done