IPv6 動態DNS更新腳本

暫時無法分類的文章
回覆文章
garyjuang
系統管理員
文章: 50
註冊時間: 2022年 6月 25日, 01:11

IPv6 動態DNS更新腳本

文章 garyjuang »

代碼: 選擇全部

#!/bin/sh
#VERSION:202202020900
#IF CHECK CHANGED THEN NSUPDATE IPv6
#CHECK IPv6 empty
#Author: GaryJuang garyjuang@gmail.com
rndc=`mktemp`
cat << EOF > ${rndc}
key "outside.rcteam.org" {
        algorithm hmac-sha256;
        secret "xxxxxxxxxxxxx";
};
EOF

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NS=$(dig -6 AAAA +short ns1.rcteam.org @resolver1.opendns.com)
FQDN="mx1.rcteam.org."
ZONE=rcteam.org.
KEY=/usr/local/etc/scripts/rcteam.org.key
MYIP6=$(dig AAAA +short myip.opendns.com @resolver1.opendns.com)
OLDIPv6=$(dig -6 AAAA +short ${FQDN})
TIME=`date`
NOTICETO='garyjuang@gmail.com'
NOTICEFROM="${FQDN} <mx1@rcteam.org>"

if [ "${MYIP6}" = "" ];then

logger "Can't Get IPv6 IP"
cat << EOF  | sendmail ${NOTICETO}
From: ${NOTICEFROM}
To: ${NOTICETO}
Subject: ${FQDN} IPv6 ERROR
Date: ${TIME}

${TIME} `hostname` NO IPv6

EOF

NIC=`ifconfig -l | xargs -n 1 | grep -v lo0`
IPv6List=`ifconfig ${NIC} inet6 | grep inet6 | grep autoconf | awk '{print $2}'`
for i in ${IPv6List}
do
        ifconfig ${NIC} inet6 ${i} delete
done
/bin/rm -fr ${rndc}
exit
fi

if [ "${OLDIPv6}" = "${MYIP6}" ];then
logger "IPv6 Not Changed"
/bin/rm -fr ${rndc}
exit
else
nsupdate -6 -k ${rndc} -v << EOF
server ${NS}
zone ${ZONE}
update delete ${FQDN} AAAA
update add ${FQDN} 30 AAAA ${MYIP6}
send
EOF
logger "OLD IPv6:${OLDIPv6}"
logger "NEW IPv6:${MYIP6}"
fi

echo "remove temp file"
/bin/rm -fr ${rndc}
回覆文章