一、DDNS那些事儿
本人用的dnsimple做域名dns解析,这家有一套完整的API来管理DNS记录,路由器上各种ddns插件、脚本均不支持dnsimple,故自己来搞。
1. DNSimple的DNS A记录更新脚本
新建 /jffs/.koolshare/ddns/update_dnsimple.sh 文件,写入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/sh TOKEN="XXXXXXXXXXXXXXX" # The API v2 OAuth token ACCOUNT_ID="NNNNN" # Replace with your account ID ZONE_ID="example.com" # The zone ID is the name of the zone (or domain) RECORD_ID="NNNNNNNN" # Replace with the Record ID IP=`nvram get wan0_ipaddr` logger "WAN IP is $IP, Updating DNS record..." curl -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -X "PATCH" \ -i "https://api.dnsimple.com/v2/$ACCOUNT_ID/zones/$ZONE_ID/records/$RECORD_ID" \ -d "{\"content\":\"$IP\"}" if [ $? != 0 ]; then logger "Failed to update dnsimple DNS record." else logger "Update dnsimple DNS record successful." fi |
2. wan口连接/重连接后自动运行脚本
打开文件 /jffs/scripts/wan-start ,末尾添加两行(高亮部分):
1 2 3 4 |
#!/bin/sh /koolshare/bin/ks-wan-start.sh start sleep 10 /koolshare/ddns/update_dnsimple.sh |