Dynamic DNS service: Difference between revisions

From WickyWiki
mNo edit summary
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 8: Line 8:


Popular dynamic DNS registration sites:
Popular dynamic DNS registration sites:
* http://dyndns.org
* http://duckdns.org
* http://www.dnsexit.com (free)
* http://www.dnsexit.com (free)
== 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.
* http://www.dnsexit.com/Direct.sv?cmd=userIpClients
Bash shell script to update:
<syntaxhighlight lang=bash>
#!/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
</syntaxhighlight>


== Installation ddclient (dyndns and others) ==
== Installation ddclient (dyndns and others) ==
Line 53: Line 114:
sudo dpkg-reconfigure ddclient
sudo dpkg-reconfigure ddclient
sudo /etc/init.d/ddclient restart
sudo /etc/init.d/ddclient restart
</syntaxhighlight>
== 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.
* http://www.dnsexit.com/Direct.sv?cmd=userIpClients
WAN IP update script using Linux Upstart method:
* Info: http://upstart.ubuntu.com/getting-started.html
<syntaxhighlight lang=bash>
sudo /etc/init/dyndns-ip-update.conf
</syntaxhighlight>
Contents:
<syntaxhighlight lang=bash>
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 )
  # can 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
</syntaxhighlight>
Test script with:
<syntaxhighlight lang=bash>
sudo start dyndns-ip-update
</syntaxhighlight>
Check log:
<syntaxhighlight lang=bash>
sudo cat /var/log/upstart/dyndns-ip-update.log | tail -10
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 18:56, 23 February 2021

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.