Dynamic DNS service

From WickyWiki

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 ipUpdate (dnsexit.com)

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

Bash shell script to update:

#!/bin/bash
#dyndns update

# settings
host="HOSTNAME.linkpc.net"
login="LOGINNAME"
passtoken="***"
storedipfile="/var/tmp/dyndns-ip-update.ip"
forceafterdays=30

# get current IP using checkip.dyndns.com, try again if error
tries=4
retrywait=1
i=0
while [ ${i} -lt ${tries} ]; do
  sleep ${retrywait}s;
  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" )
  if [ -n "${currentIP}" ]; then break; fi;
  echo try ${i}/${retries} failed, waiting ${retrywait}
  currentIP="unknown"
  i=$((i + 1))
  retrywait=$((retrywait + retrywait))
done;

echo current IP = '${currentIP}'

# get previous IP from file
storedIP="unknown"
storedipfiledate=$( stat -c %y ${storedipfile} | cut -d ' ' -f1 )
storedipdays=$(( (`date +%s -d $(date '+%Y%m%d')` - `date +%s -d ${storedipfiledate}`)/86400 ))
if [ -f "${storedipfile}" ] ; then
  #force update if stored IP older then ${forceafterdays} days
  if [ ${storedipdays} -gt ${forceafterdays} ] ; then
    storedIP="old"
  else
    storedIP=$(cat ${storedipfile})
  fi
fi

echo previous IP = '${storedIP}' (${storedipfiledate})

# update the dyndns IP if needed
if [ "${currentIP}" = "${storedIP}" ] ; then
  echo update not needed
else
  updateurl="http://update.dnsexit.com/RemoteUpdate.sv?login=${login}&password=${passtoken}&host=${host}"
  response=$( wget --quiet --output-document=- ${updateurl} | tail -1 )
  echo updated : ${response}
  echo ${currentIP} > ${storedipfile}
fi

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

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.