路由启动脚本
原创
©著作权归作者所有:来自51CTO博客作者jxwpx的原创作品,请联系作者获取转载授权,否则将追究法律责任
#!/bin/bash
HOST=http://169.254.169.254
COUNT=0
for DEV in `/sbin/ifconfig | grep -i "d0:.d" | grep "eth[0-9]* " | awk '{print $1}'`;do
TABLE=$((${DEV:3}+100))
IP="`/sbin/ifconfig "$DEV" | grep "inet " | awk '{print $2}' | awk -F":" '{print $2}'`"
NETWORK_MASK=`ip route | grep -w "$DEV proto"|awk '{print substr($1,1,length($1))}'`
NETWORK=`ip route | grep -w "$DEV proto"|awk '{print substr($1,1,length($1)-3)}'`
GATEWAY=${NETWORK%.*}.$(expr ${NETWORK##*.} + 1)
if [ -z $IP ]||[ -z $GATEWAY ];then
continue
fi
ip route flush table $TABLE
ip route add default via $GATEWAY dev $DEV src $IP table $TABLE prio 50
ip route add $NETWORK_MASK dev $DEV src $IP table $TABLE prio 50
ip rule add from $IP table $TABLE
COUNT=$(($COUNT+1))
done
if [ $COUNT -lt "2" ];then
exit
fi
for DEV in `/sbin/ifconfig | grep -i " d0:.d" | grep "eth[0-9]* " | awk '{print $1}'`;do
NETWORK=`ip route | grep -w "$DEV proto"|awk '{print substr($1,1,length($1)-3)}'`
GATEWAY=${NETWORK%.*}.$(expr ${NETWORK##*.} + 1)
TABLE=$((${DEV:3}+100))
HW=`/sbin/ifconfig "$DEV"|tr '[A-Z]' '[a-z]' | sed -n "/ d0:.d/s/.*hwaddr *//p" | sed -n 's/:/_/gp'`
FILENAME="${HW:0:6}route.txt"
FILEPATH="/tmp/$FILENAME"
wget $HOST/latest/meta-data/"$FILENAME" -q -O "$FILEPATH"; UNREACHEABLE=$?
while [ $UNREACHEABLE -ne "0" ]
do wget $HOST/latest/meta-data/"$FILENAME" -q -O "$FILEPATH"; UNREACHEABLE=$?; sleep 5;
done
while read line;do
if [ -z $line ];then
continue
fi
route add -net $line gw $GATEWAY
done < "$FILEPATH"
done
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java 应用启动脚本 java服务启动脚本
1.单独jar包形式启动
linux JVM jar java