版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:
https://blog.csdn.net/Kaven_W/article/details/121662594
材料准备
阿里云域名 阿里云打开AccessKey,得到AccessKey ID/Secret RecordId【稍后得到此数据】 linux服务器一台(公网动态IP,必须公网,没有穿透功能)
服务器准备工作,安装阿里云CLI软件(Linux)
安装包下载链接 下载后解压出运行文件aliyun (64位),root权限拷贝到/usr/local/bin下
sudo chmod 777 /usr/local/bin/aliyun
kaven@SkyWant-ThunderRobot:~$ aliyun configure
Configuring profile 'default' in 'AK' authenticate mode...
Access Key Id [*********************McW]:
Access Key Secret [***************************D8M]:
Default Region Id [cn-shanghai]:
Default Output Format [json]: json (Only support json)
Default Language [zh|en] zh:
Saving profile[default] ...Done.
Configure Done!!!
..............888888888888888888888 ........=8888888888888888888D=..............
...........88888888888888888888888 ..........D8888888888888888888888I...........
.........,8888888888888ZI: ...........................=Z88D8888888888D..........
.........+88888888 ..........................................88888888D..........
.........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........
.........+88888888 ............. ************* ..............O8888888D..........
.........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........
.........+88888888...........................................88888888D..........
..........D888888888888DO+. ..........................?ND888888888888D..........
...........O8888888888888888888888...........D8888888888888888888888=...........
............ .:D8888888888888888888.........78888888888888888888O ..............
kaven@SkyWant-ThunderRobot:~$
获取RecordId
kaven@SkyWant-ThunderRobot:~$ aliyun alidns DescribeDomainRecords --DomainName $DomainName
shell运行脚本设计(aliyunDDNS.sh)
#!/bin/bash
DomainName=*************
RecordId=********************
RR=www
Type=A
ping -c 4 www.baidu.com
if [ $? != 0 ];then
echo --TIMEOUT
sleep 5
exit 691
fi
setip=`aliyun alidns DescribeDomainRecords --DomainName $DomainName|grep $RecordId -A 4|grep Value`&&setip=${setip:14}&&setip=${setip%\"*}
curlip=`curl icanhazip.com`
if [ $setip = $curlip ];then
echo --Done
exit 0
fi
aliyun alidns UpdateDomainRecord --RecordId $RecordId --RR $RR --Type $Type --Value $curlip
将脚本文件添加进系统变量,并设置定时运行
cp aliyunDDNS.sh /usr/local/bin/aliyunDDNS
sudo chmod 777 /usr/local/bin/aliyunDDNS
剩余定时任务可以根据corntab定时任务来设置,推荐5分钟一次。 corntab设置手册 困了,怎么设置定时,各位小伙伴自己研究一下吧
|