fast and easy dtdns bash client (linux)

dtDNS is a free and efficient dynamic dns solution. This little script will help keeping your server ip updated.
This is a modified version of the script written by Jason R. Pitoniak here.
To run the script periodically use the command:

crontab -e

to open the cronjob configuration file and then add the following line to the end of it:

*/5 * * * * /path/to/dtdns-update >/dev/null 2>&1

#!/bin/bash
# dtDNS Dynamic IP update Script
# Author: Jason R. Pitoniak, Francesco Illuminati
# 
# Copyright (c) 2015 Jason R. Pitoniak

# Set your dtDNS hostname and password below
HOSTNAME='YOURNAME.dtdns.net'
PASSWORD='YOURPASS'

# We need to find your external IP address as your system may have an non-public address
# on your local network. icanhazip.com (or any number of other sites) will do this for us
EXTIP=`curl -s http://icanhazip.com/`
echo external ip: $EXTIP

# Now we check which IP dtDNS currently has recorded by checking their DNS server
LASTIP=`dig +short ${HOSTNAME}`
echo reported ip: $LASTIP

# If the current external IP is different from the one with dtDNS, update dtDNS
if [ "$EXTIP" != "$LASTIP" ]
then
    curl "https://www.dtdns.com/api/autodns.cfm?id=$HOSTNAME&pw=$PASSWORD&ip=$EXTIP"
else
    echo "no update needed."
fi

Leave a comment