这样就不用每次都登录到 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
|