-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DDNS Sample Scripts
Asus DDNS for use in multiple-NAT environment.
#!/bin/sh
# based on asuswrt-merlin.ng-master\release\src\router\rc\services.c
# by DSR! - https://github.com/xchwarze
# only for ddns_server_x === WWW.ASUS.COM
host=$(nvram get ddns_hostname_x)
ip=$(curl --silent http://api.ipify.org/)
# nserver=$(nvram get ddns_serverhost_x)
nserver="nwsrv-ns1.asus.com"
ez-ipupdate -S dyndns -a $ip -h $host -A 2 -s $nserver -q > /dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Here is a working example, for afraid.org’s free DDNS (you can find your API key here).
#!/bin/sh
API="xxxxxxxxxxxxxxxx" # Your afraid.org API Key
curl -fs -o /dev/null "https://freedns.afraid.org/dynamic/update.php?${API}"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
If you run your own DNS server with BIND9, this script uses nsupdate to update an A record. This requires that you are updating a zone configured for use with dynamic updates rather than the standard zone config files.
#!/opt/bin/bash
# A bash script to update BIND9 DDNS using nsupdate and tsig key
# Tested with bash and bind-client to be installed from entware-ng
#User variables - replace with your variables
NS="ns1.example.com"
ZONE="dynamic.example.com"
DHOST="dhost.dynamic.example.com"
TSIGFILE="/tmp/sda1/mykey.tsig"
NSUPDATE=$(which nsupdate)
IP=$1
echo "server $NS" > /tmp/nsupdate
echo "debug yes" >> /tmp/nsupdate
echo "zone $ZONE." >> /tmp/nsupdate
echo "update delete $DHOST A" >> /tmp/nsupdate
echo "update add $DHOST 600 A $IP" >> /tmp/nsupdate
echo "send" >> /tmp/nsupdate
$NSUPDATE -k $TSIGFILE /tmp/nsupdate 2>&1 &
wait $!
echo $?
if [ $?==0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Here is a very basic script for ChangeIP.com.
#!/bin/sh
USERNAME="user" # Your username
PASSWORD="password" # Your password
HOSTNAME="hostname" # Your DNS hostname
curl -fs -o /dev/null "https://nic.changeip.com/nic/update?u=${USERNAME}&p=${PASSWORD}&hostname=${HOSTNAME}"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
If you use CloudFlare for your domains, this script can update any A record on your account.
#!/bin/sh
EMAIL= # Your Email
ZONEID= # Your zone id, hex16 string
RECORDID= # You DNS record ID, hex16 string
RECORDNAME= # Your DNS record name, e.g. sub.example.com
API= # Cloudflare API Key
IP=${1}
curl -fs -o /dev/null -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONEID/dns_records/$RECORDID" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $API" \
-H "Content-Type: application/json" \
--data "{\"type\":\"A\",\"name\":\"$RECORDNAME\",\"content\":\"$IP\",\"ttl\":120,\"proxied\":false}"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
DigitalOcean DNS has a more involved JSON-based API, but
do-ddns can update records with only
sh and curl as system dependencies. It has automatic support for
executing /sbin/ddns_custom_updated
on success or failure.
#!/bin/sh
#---------------------------------------------------------------------------
# Update using dnsmadeeasy.com API
#---------------------------------------------------------------------------
update_dynamic_dns () {
if [ -n "$WAN_IP_ADDRESS" ]; then
logger "$0: using WAN IP address $WAN_IP_ADDRESS for dynamic DNS"
resp=`curl -k $DYNDNS_URL`
rcode=$?
logger "$0: ddns response: $resp; result code: $rcode"
if [ $resp != "success" ] && [ $resp != "error-record-ip-same" ]; then
/sbin/ddns_custom_updated 0
return 1
else
/sbin/ddns_custom_updated 1
return 0
fi
else
logger "$0: WARNING: no WAN IP address available. Not updating dynamic DNS."
/sbin/ddns_custom_updated 0
return 1
fi
}
#===========================================================================
logger "$0 event called with args: $@"
WAN_IP_ADDRESS=${1}
DYNDNS_ID="<set to your dyn DNS record ID"
DYNDNS_PASSWORD="set to your dyn DNS record password"
DYNDNS_URL="https://www.dnsmadeeasy.com/servlet/updateip?id=$DYNDNS_ID&password=$DYNDNS_PASSWORD&ip=$WAN_IP_ADDRESS"
update_dynamic_dns
If you use DNS-O-Matic to update your domains, this script can update
all or a single host record on your account. To use this, replace
dnsomatic_username
, dnsomatic_password
with your own values. You can
refer to the DNS-O-Matic API Documentation for additional info.
Note: the HOSTNAME specified in the script below will update all records setup in your DNS-O-Matic account to have it only update a single host you will need to modify it accordingly. In some cases this may require you to specify the host entry, sometimes the domain entry.
To troubleshoot update issues you can run the curl command directly from the command line by passing in your details and removing the --silent option. If you get back good and your IP address back you’ve got it setup correctly. If you get back nohost, you’re not passing in the correct hostname value.
#!/bin/sh
# Update the following variables:
USERNAME=dnsomatic_username
PASSWORD=dnsomatic_password
HOSTNAME=all.dnsomatic.com
# Should be no need to modify anything beyond this point
/usr/sbin/curl -k --silent -u "$USERNAME:$PASSWORD" "https://updates.dnsomatic.com/nic/update?hostname=$HOSTNAME&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG&myip=" > /dev/null
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Note: It seems that the DNS-O-Matic API (at least when using a single https command) does not like an email address as the user name and will fail. DNS-O-Matic no longer allows the creation of a separate user name. However there is a workaround: Your DNS-O-Matic account is the same as your OpenDNS account. If you go to my account at opendns.com and choose display name (purportedly for forum use), this will also work in this script for user name. The suggestion above about running the curl command directly from the command line to test is really useful!
ℹ️
|
The example below uses non-HTTPS which isn’t recommended. dnsExit.com doesn’t have HTTPS method available. |
Free DNS server that also offers DDNS services.
#!/bin/sh
USER=
PASS=
DOMAIN=
wget -qO - "http://update.dnsexit.com/RemoteUpdate.sv?login=$USER&password=$PASS&host=$DOMAIN"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
This script adds DNSimple support, get token, account_id, zone_id and record_id from the site or API and edit all the constant variables at the top of the script.
#!/bin/sh
TOKEN="youroauth2token" # The API v2 OAuth token
ACCOUNT_ID="123456789" # Replace with your account ID
ZONE_ID="yourzoneid.com" # The zone ID is the name of the zone (or domain)
RECORD_ID="123456789" # Replace with the Record ID
IP=${1}
curl --silent \
-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\"}" > /dev/null
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Just replace yoursubdomain
and your-token
with the values you got
from duckdns. The hostname you set up in the GUI doesn’t matter, but I
recommend setting it to your subdomain anyway.
#!/bin/sh
# register a subdomain at https://www.duckdns.org/ to get your token
SUBDOMAIN="yoursubdomain"
TOKEN="your-token"
# no modification below needed
curl --silent "https://www.duckdns.org/update?domains=$SUBDOMAIN&token=$TOKEN&ip=" >/dev/null 2>&1
if [ $? -eq 0 ];
then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Just edit USERNAME, PASSWORD and HOSTNAME according to your setup, and you should be good to go. Dy.fi drops hosts after 7 days of inactivity, so I’d also recommend setting the "Forced refresh interval (in days)" setting in the web ui to 7.
#!/bin/sh
# http://www.dy.fi/page/specification
USERNAME="[email protected]"
PASSWORD="yourtopsecretpassword"
HOSTNAME="yourhostname.dy.fi"
curl -D - --user $USERNAME:$PASSWORD https://www.dy.fi/nic/update?hostname=$HOSTNAME >/dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
ℹ️
|
the example below uses non-HTTPS which isn’t recommended. See example for afraid above. |
provide a number of free and premium DNS related services for home or office use.
#!/bin/sh
#
# http://dyns.cx/documentation/technical/protocol/v1.1.php
USERNAME=
PASSWORD=
HOSTNAME=
DOMAIN= # optional
IP=${1}
DEBUG= # set to true while testing
URL="http://www.dyns.net/postscript011.php?username=${USERNAME}&password=${PASSWORD}&host=${HOSTNAME}&ip=${IP}"
if [ -n "${DOMAIN}" ] ; then
URL="${URL}&domain=${DOMAIN}"
fi
if [ -n "${DEBUG}" ] ; then
URL="${URL}&devel=1"
fi
wget -q -O - "$URL"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
#!/bin/sh
#
# https://www.dynu.com/en-US/DynamicDNS/IP-Update-Protocol
HOSTNAME=YOUR-HOSTNAME.dynu.com
PASSWORD=YOUR-SUPERSECRET-PASSWORD
IP=${1}
URL="https://api.dynu.com/nic/update?hostname=${HOSTNAME}&myip=${IP}&password=${PASSWORD}"
ANSWER=$(wget -q -O - "$URL")
if [ "$ANSWER" == "good" ] || [ "$ANSWER" == "nochg" ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
#!/bin/sh
# Update the following variables:
TOKEN=your_real_token
# Should be no need to modify anything beyond this point
resp=$(/usr/sbin/curl -s -k -X PUT -d "" https://entrydns.net/records/modify/$TOKEN)
rcode=$?
if [ "$rcode" == "0" -a "$resp" == "OK" ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
#!/bin/sh
#
# This script provides dynamic DNS update support for the EasyDNS service on
# the Merlin asuswrt router firmware.
#
#
# Command Line examples you can try in your web browser or CLI
# wget -qO - "http://api.cp.easydns.com/dyn/tomato.php?login=EDIT-ME&password=EDIT-ME&wildcard=no&hostname=EDIT.ME.EM&0ED.IT0.0ME.TOO"
#
# curl -k "http://EDIT-USER:[email protected]/dyn/tomato.php?&wildcard=no&hostname=EDIT-ME&myip=0ED.IT0.0ME.TOO"
date >> /tmp/ddns-start.log
echo "$#: $*" >> /tmp/ddns-start.log
# This should be the domain (or hostname) to be updated.
# Seems as you can add more DDNS with this method, This works for me very well
# as I need two A records to be updated from DDNS.
# You should be able to add a C, D, etc if needed.
DOMAIN_A=ADD DOMAIN HERE
DOMAIN_B=ADD 2nd DOMAIN HERE
# This is where your EasyDNS user name and the update token obtained from
# EasyDNS needs to be modified.
EASYDNS_USERNAME=Change to your login name.
EASYDNS_PASSWORD=Change to your taken.
# Set wildcard "on" if you want this to map any host under your domain
# to the new IP address otherwise "off".
WILDCARD=off
# This is set directly from http://helpwiki.easydns.com/index.php/Dynamic_DNS#Setting_up_your_system_to_use_Dynamic_DNS
# Their possibly may be another URI_BASE='https://members.easydns.com/dyn/dyndns.php'
# I have had no luck with this other URI so far, but the one currently set works great.
URI_BASE="http://api.cp.easydns.com/dyn/tomato.php"
# This is where your wan IP comes from.
WAN_IP=$1
# This is curl, update to DOMAIN_A
curl --silent -k -u "$EASYDNS_USERNAME:$EASYDNS_PASSWORD" \
"$URI_BASE?wildcard=$WILDCARD&hostname=$DOMAIN_A&myip=$WAN_IP"
# This is curl update to DOMAIN_B Remove the comment from the last
# two lines from this section to activate the secound DDNS updater.
# If you need more updaters you should be able to copy the curl lines, and change
# DOMAIN_B to DOMAIN_X if you are on the same account and server. If not you will
# Need to make a few other changes for each.
#curl --silent -k -u "$EASYDNS_USERNAME:$EASYDNS_PASSWORD" \
# "$URI_BASE?wildcard=$WILDCARD&hostname=$DOMAIN_B&myip=$WAN_IP"
# The last lines tell the web gui that we have or have not updated.
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
|
Beta API methods and resources are not fully stabilized and may yet change. |
This updates the @
and *
A
records while leaving any others intact.
#!/bin/sh
APIKEY="XXXXXXXXXXXXXXXXXXXXXXXX" # Your 24-character API key
DOMAIN="example.com" # The domain to be updated
IP=${1}
curl -fs -o /dev/null -X PUT -H "Content-Type: application/json" \
-H "X-Api-Key: ${APIKEY}" \
-d "{\"rrset_ttl\": 10800, \"rrset_values\": [\"${IP}\"]}" \
"https://dns.beta.gandi.net/api/v5/domains/${DOMAIN}/records/{@,*}/A"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Transfer your domain to Google and enjoy free DDNS and other features.
#!/bin/sh
set -u
U=xxxx
P=xxxx
H=xxxx
# args: username password hostname
google_dns_update() {
CMD=$(curl -s https://$1:$2@domains.google.com/nic/update?hostname=$3)
logger "google-ddns-updated: $CMD"
case "$CMD" in
good*|nochg*) /sbin/ddns_custom_updated 1 ;;
abuse) /sbin/ddns_custom_updated 1 ;;
*) /sbin/ddns_custom_updated 0 ;;
esac
}
google_dns_update $U $P $H
exit 0
#!/bin/sh
USER=username-goes-here
PASS=unbreakable-password
DOMAIN=mydomain.site
wget --no-check-certificate -qO - "https://dyndns.topdns.com/update?hostname=$DOMAIN&username=$USER&password=$PASS"
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Activate Dynamic DNS Authentication from DNS control panel in order to get authentication details that you will need in the following example. Create a DYNA or DYNAAAA record and choose your subdomain. Your IP is detected automatically at this point, but you can change it, so you can confirm your setup is working.
#!/bin/sh
USERNAME=your_username
PASSWORD=your_password
DOMAIN=your_domain (e.g. subdomain.example.com)
curl -k "https://svc.joker.com/nic/update?username=$USERNAME&password=$PASSWORD&hostname=$DOMAIN" >/dev/null 2>&1 &
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
This scripts add Loopia support using curl just edit hostname and cred.
#!/bin/sh
#https://support.loopia.com/wiki/CURL
url= # add the domain name here (example: test.com)
credentials= # add username and password here (example: username:password)
resolver=https://dns.loopia.se/XDynDNSServer/XDynDNS.php
wanip=${1}
loopia_dns_update() {
for domain in $url
do
redirect="$resolver"'?hostname='"$domain"'&'myip="$wanip&wildcard=NOCHG"
status=$(curl -s --user "$credentials" "$redirect")
logger -s -t ddns "The following domain $domain reports $status"
done
case "$status" in
good*|nochg*) /sbin/ddns_custom_updated 1 ;;
abuse) /sbin/ddns_custom_updated 1 ;;
*) /sbin/ddns_custom_updated 0 ;;
esac
}
loopia_dns_update
exit 0
If you use Namecheap for your domains, this script can update any A
record on your account. The script is currently (as of Aug 1 2015)
required because the built-in script uses HTTP, while Namecheap requires
HTTPS. To use this, replace HOSTNAME
, DOMAIN
and PASSWORD
with
your own values. You can refer to the
DDNS
FAQ at Namecheap for steps required.
#!/bin/sh
# Update the following variables:
HOSTNAME=hostname
DOMAIN=domain.com
PASSWORD=XXXXXXXXXXXXXXXXXXXXXXXX
# Should be no need to modify anything beyond this point
/usr/sbin/wget --no-check-certificate -qO - "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD&ip="
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
-
Support Oray default
-
You can add functions and add them to the update_all_ddns function to support other DDNS service providers
Tested and working on spanish version of OVH but should work in any language. This is a Domain/Hosting provider, if you have domains with them you can use their DDNS service with the following script.
#!/bin/sh
###
# Git development:
# https://gist.github.com/atais/9ea6595072096ab8077f619bd3648da8
# Based on
# https://github.com/RMerl/asuswrt-merlin/wiki/Custom-DDNS#google-domains
# https://github.com/RMerl/asuswrt-merlin/wiki/Custom-DDNS#bind9-ddns-using-nsupdate
###
#set -u
USER=YOUR USER IN DDNS CONFIG
PASS=YOUR PASSWORD IN DDNS CONFIG
HOST=mydomain.com
# args: username password hostname ip
ovh_dns_update() {
CMD=$(curl -s -u $1:$2 "https://www.ovh.com/nic/update?system=dyndns&hostname=$3&myip=$4")
logger "ovh-ddns-updated: $CMD"
case "$CMD" in
good*|nochg*) /sbin/ddns_custom_updated 1 ;;
*) /sbin/ddns_custom_updated 0 ;;
esac
}
IP=$1
### you can obtain your external IP with this API
#IP=$(curl -s ifconfig.co)
ovh_dns_update $USER $PASS $HOST $IP
exit 0
If you use domain.yandex.com for your domains, this script can update
any A/AAAA record on your account. Replace router.yourdomain.com
,
token
and id
with your own values.
#!/bin/sh
# Get token at https://pddimp.yandex.ru/token/index.xml?domain=yourdomain.com
token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Get record ID from https://pddimp.yandex.ru/nsapi/get_domain_records.xml?token=$token&domain=yourdomain.com
# <record domain="router.yourdomain.com" priority="" ttl="21600" subdomain="router" type="A" id="yyyyyyyy">...</record>
id=yyyyyyyy
/usr/sbin/curl --silent "https://pddimp.yandex.ru/nsapi/edit_a_record.xml?token=$token&domain=yourdomain.com&subdomain=router&record_id=$id&ttl=900&content=${1}" > /dev/null 2>&1
if [ $? -eq 0 ];
then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Strato uses the DynDNS v2 protocol from dyndns.org to execute the DynDNS-update.
-
Server : https://dyndns.strato.com/nic/update
-
Host : the domain or subdomain that you want to refer to (example: myrouter.yourstratodomain.com)
-
User : the domain from your contract (example: yourstratodomain.com)
-
Password: the Dynamic DNS-password that you have configured in your Security dashboard
#!/bin/sh
USERNAME="<my-username>"
PASSWORD="<my-password>"
HOSTNAME="<my-hostname>"
# Should be no need to modify anything beyond this point
curl -D - --user $USERNAME:$PASSWORD https://dyndns.strato.com/nic/update?hostname=$HOSTNAME >/dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi
Woima is a free Finnish Dynamic DNS service. After ordering you’ll get the necessary info in an e-mail. Pay attention to the URL in the e-mail. Every example I encountered had dyn.woima.fi/update. Mine on the other hand was nic/update.
#!/bin/sh
USERNAME=your_username
PASSWORD=your_password
HOSTNAME=your_domain (e.g. subdomain.dyn.woima.fi)
curl -D - -4 --user $USERNAME:$PASSWORD https://dyn.woima.fi/nic/update?$HOSTNAME >/dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/ddns_custom_updated 1
else
/sbin/ddns_custom_updated 0
fi