动态域名解析IP并修改防火墙规则 发表于 2016-10-12 | 分类于 shell 12345678910111213141516#!/bin/bashwhile truedo#刷新DNSnscd -i hostsOLD_IP=`iptables -L -n | grep :22 | awk '{print $4}'| head -1`NEW_IP=`ping www.baidu.com -c1 -n| grep from | awk '{ print $4 }'| awk -F":" '{print $1}'`if [ $NEW_IP != $OLD_IP ]thensed -i 's/'$OLD_IP'/'$NEW_IP'/g' /etc/sysconfig/iptables/etc/init.d/iptables restartecho " `date +%Y-%m-%d\ %H:%M:%S` Ip has changed, the new ip is $NEW_IP" >> /tmp/ip_change.logfi#每60秒判断一次sleep 60done 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏 支付宝打赏