Dynamic DNS service

From WickyWiki
Revision as of 17:47, 17 January 2015 by Wilbert (talk | contribs)

Dynamic DNS allows you to have a DNS name while your IP address changes frequently. You will need to register for an account with one of the dynamic DNS providers. This service is often provided freely.

More information:

Popular dynamic DNS registration sites:

Installation ddclient (dyndns and others)

This client updates the DynDNS record automatically.

sudo apt-get install ssh libio-socket-ssl-perl ddclient

Follow the instructions. Additionally configure a longer update interval 'daemon=3600' and use SSL:

sudo gedit /etc/ddclient.conf
protocol=dyndns2
use=web, web=checkip.dyndns.com, web-skip='IP Address'
server=members.dyndns.org
login=**dyndns-login**
password='**dyndns-pwd**'
wilbertvolkers.dyndns.org
daemon=3600
ssl=yes

View ddclient logging:

cat /var/log/syslog* | grep 'ddclient'

Test/force refresh:

sudo ddclient -force

Reconfigure and restart, you can edit the config file instead:

sudo dpkg-reconfigure ddclient
sudo /etc/init.d/ddclient restart

Installation ipUpdate (dnsexit)

The interface uses an (unsecure) http protocol and it is strongly recommended to configure a different password for this service. Logon at http://www.dnsexit.com and go to My Account -> Account profile -> IP Update Password.

WAN IP update script using Linux Upstart method:

sudo /etc/init/dyndns-ip-update.conf

Contents:

author "Wilbert Volkers"
description "Update WAN IP address at DynDNS service www.dnsexit.com"

start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!023456]

# write stdout to log
console log

script

	echo "$(date '+%Y-%m-%d %H.%M.%S') dyndns : start ..."

	# settings
	host="wilbertvolkers.linkpc.net"
	login="dnsexitusername"
	passtoken="dnsexitpassword"
	storedipfile="/opt/dyndns-ip-update.ip"

	# get current IP from checkip.dyndns.com
	currentIP=$( wget --quiet --output-document=- http://checkip.dyndns.com | sed -ne "s/.*[^0-9]\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)[^0-9].*/\1/p" )

	echo "$(date '+%Y-%m-%d %H.%M.%S') dyndns : current IP address = $currentIP"

	# get previous IP from a file, only if from today
	storedIP="none"
	if [ -f "$storedipfile" ] ; then
	  # get storedipfile modify date
	  storedipfiledate=$( stat -c %y $storedipfile | cut -d ' ' -f1 )
	  # only skip update if IP is from today
	  if [ $storedipfiledate = $(date '+%Y-%m-%d') ] ; then
	    storedIP=$(cat $storedipfile)	
	  fi
	fi

	echo "$(date '+%Y-%m-%d %H.%M.%S') dyndns : previous IP address = $storedIP"

	# update the dyndns IP if needed
	if [ $currentIP = $storedIP ] ; then
	  echo "$(date '+%Y-%m-%d %H.%M.%S') dyndns : update not needed, skipped"
	else
	  update_url="http://update.dnsexit.com/RemoteUpdate.sv?login=$login&password=$passtoken&host=$host"
	  echo "$(date '+%Y-%m-%d %H.%M.%S') dyndns : $( wget --quiet --output-document=- $update_url | tail -1 )"
	  echo $currentIP > $storedipfile
	fi

	echo "$(date '+%Y-%m-%d %H.%M.%S') dyndns : done."

end script

Test script with:

sudo start dyndns-ip-update

Check log:

sudo cat /var/log/upstart/dyndns-ip-update.log | tail -10

Remarks

Note that when your IP address has changed, the ddcient needs to announce this to your dyndns service. Then it is still possible that the DNS you are using does not give you the new IP address, it may take some time before updates are routed through the DNS network.