Skip to content

dynu.com免费ddns通过api+curl进行动态更新

Tags:

创建一个新的免费的ddns域名 (免费账号最多可以建4个)

开启API Key

bash script 来更新ddns

方法1 – curl post

DYNU_API_KEY='6bbc6XXXXXXXX'
DYNU_DOMAIN_NAME='xxxxxfish.mywire.org'
THIS_IP=$(curl ip.sb)

# 获得所有的dns info (把对应的id记下来,赋值给 DYNU_DOMAIN_ID)
curl -X GET https://api.dynu.com/v2/dns \
        -H "accept: application/json" \
        -H "API-Key: $DYNU_API_KEY"
DYNU_API_KEY='6bbc6XXXXXXXX'
DYNU_DOMAIN_NAME='xxxxxfish.mywire.org'
THIS_IP=$(curl ip.sb)
DYNU_DOMAIN_ID=9411YYYY

# 注意url当中带有$DYNU_DOMAIN_ID
curl -X POST https://api.dynu.com/v2/dns/$DYNU_DOMAIN_ID \
        -H "accept: application/json" \
        -H "API-Key: $DYNU_API_KEY" \
        -d '{
  "name": "'$DYNU_DOMAIN_NAME'",
  "group": "office",
  "ipv4Address": "'$THIS_IP'",
  "ipv6Address": "1111:2222:3333::4444",
  "ttl": 90,
  "ipv4": true,
  "ipv6": true,
  "ipv4WildcardAlias": true,
  "ipv6WildcardAlias": true,
  "allowZoneTransfer": false,
  "dnssec": false
}'

方法2:wget get url – https://www.dynu.com/en-US/DynamicDNS/IP-Update-Protocol#ipupdate

THIS_IP=$(curl ip.sb)
DYNU_USERNAME='你自己的用户名'
DYNU_PASSWORD_MD5=$(echo -n '自己的密码或专门的IP Update 密码' | md5sum | awk '{print $1}')

# -q don't print out header info
# -O - don't save to local file, just stream it to stdout
wget --no-check-certificate -qO- "https://api.dynu.com/nic/update?hostname=$DYNU_DOMAIN_NAME&myip=${THIS_IP}1&myipv6=1111:2222:3333::4444&username=$DYNU_USERNAME&password=$DYNU_PASSWORD_MD5" 

方法3-使用客户端软件

https://www.dynu.com/DynamicDNS/IPUpdateClient/Linux

这个最不方便的就是不能通过hostname来指定哪个域名进行更新,而是需要通过location(也就是group)来更新该group当中的所有的域名。不然就只能更新默认的那一个!

# 安装
URL='https://www.dynu.com/support/downloadfile/31'; FILE=`mktemp`; wget "$URL" -qO $FILE && sudo dpkg -i $FILE; rm $FILE

DYNU_USERNAME='lastlavalake'
# 无法用md5之后,必须是登陆密码或者IP_UPDATE密码的原文
DYNU_PASSWORD_IPUPDATE='h2C5<你自己的密码>'
DYNU_DOMAIN_NAME='fffish.mywire.org'

cat > /etc/dynuiuc/dynuiuc.conf <<EOF
username $DYNU_USERNAME  
password $DYNU_PASSWORD_IPUPDATE  
hostname $DYNU_DOMAIN_NAME
location   XXXfish
ipv4 true              
ipv6 false            
pollinterval 300     
debug true          
quiet false        
EOF

systemctl daemon-reload
systemctl restart dynuiuc.service

# Commands Manage the service using systemd:

systemctl start dynuiuc.service
systemctl stop dynuiuc.service
systemctl restart dynuiuc.service
systemctl status dynuiuc.service

# To view and truncate log files:

# View live log:
tail -f /var/log/dynuiuc.log
# View entire log file: 
cat /var/log/dynuiuc.log
# Truncate log file: 
cat /dev/null > /var/log/dynuiuc.log
# View service status: 
systemctl status dynuiuc.service -l

验证

Leave a Reply

Your email address will not be published.