动态跟踪 PPPoE 上网的 IP 并重定向到固定地址的脚本(bchyi.sh)

这样就不用每次都登录到 server 上 ifconfig 去查看了^_^
#! /bin/bash
# get device name on platinum server
DEVICE=`ifconfig|awk '/ppp[1-9]/{print $1}'`
if [ "$DEVICE" != "" ]
then
# get the device named pppxx's IP
NEW_IP=`ifconfig $DEVICE|awk -F"[ :]" '/inet/{print $16}'`
# get the OLD IP if I found
OLD_IP=`iptables-save -t nat|awk '/5.5.5.5/{print $NF}'`
if [ "$OLD_IP" != "$NEW_IP" ]
then
if [ "$OLD_IP" != "" ]
then
# delete the OLD rule about the OLD IP
iptables -t nat -D PREROUTING -d 5.5.5.5 -j DNAT --to $OLD_IP
fi
# insert the NEW rule use NEW IP
iptables -t nat -I PREROUTING -d 5.5.5.5 -j DNAT --to $NEW_IP
fi
fi

你可能感兴趣的:(动态跟踪 PPPoE 上网的 IP 并重定向到固定地址的脚本(bchyi.sh))