0%

Tomato路由器配置DNSPod动态域名

  花生壳免费级的解析服务做了各种限制,过分的是CNAME记录都不可以配置,因此将域名解析迁移至DNSPod,但是DNSPod的DDNS服务,只支持https的post方法,需要配置curl实现动态更新。

  准备工作:安装cURL

1
ipkg install libcurl

  根据DNSPod的官方API文档和示例文件,配置了一个简单的shell脚本,只需将相关的域名信息填入即可通过curl命令自动发送请求,脚本下载
  其中API Token需要前往DNSPod用户中心账号安全选项卡下创建。
  域名ID记录ID需要使用官方客户端查看。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
#==================================================
# OS Required: tomato
# Description: DNSPod Auto DDNS
# Author: Zhen
# Version: 1.0.150903
#==================================================

#API Token ID
i_api_token_id="10003"

#API Token
i_api_token="c12c3d60e9c45ffbe7b5e5ff8bbd7979"

#要修改的域名ID
i_domain_id="23173461"

#要修改的记录ID
i_record_id="168944391"

#修改后的主机头名称
i_sub_domain="home"

#记录值,这里会自动获取WAN1口的IP(WAN2口为wan2_ipaddr)
i_value=$(nvram get wan_ipaddr)

curl -k -X POST https://dnsapi.cn/Record.Modify -d 'login_token='${i_api_token_id}','${i_api_token}'&format=json&domain_id='${i_domain_id}'&record_id='${i_record_id}'&sub_domain='${i_sub_domain}'&value='${i_value}'&record_type=A&record_line=默认'

  最后配置路由器在WAN口联机时执行脚本即可。

  可以在/opt/dnspod-dns.log中查看日志。

1
2
3
4
5
root@RouterA:/opt# cat dnspod-ddns.log
{"status":{"code":"1","message":"Action completed successful","created_at":"2015-09-03 20:33:11"},"record":{"id":1176674xx,"name":"home","value":"202.192.174.144","status":"enable"}}
{"status":{"code":"1","message":"Action completed successful","created_at":"2015-09-03 20:35:16"},"record":{"id":1176674xx,"name":"home","value":"202.122.173.114","status":"enable"}}
{"status":{"code":"1","message":"Action completed successful","created_at":"2015-09-03 20:36:07"},"record":{"id":1176674xx,"name":"home","value":"202.233.163.114","status":"enable"}}
{"status":{"code":"1","message":"Action completed successful","created_at":"2015-09-03 20:37:09"},"record":{"id":1176674xx,"name":"home","value":"202.118.162.7","status":"enable"}}