Dynamic update scrip for Changeip.com (FreeBSD) version.

I have been fiddling with Mikrotik some time now, and have come to love it. It didn't take long time until I noticed the best service for getting the dsl pipes a working dns you could script it against Changeip. However, since I also use the domain for lots of FreeBSD boxes I was in some sort of trouble since I then needed to move the whole domain from Zoneedit to Changeip. In the matter of need I made a "whack" script to get the little red ones updating against Changeip.

//Cheers
Goran

Installation:

  1. mkdir -p /etc/ddns
  2. touch /etc/ddns/update.log
  3. cd /usr/ports/ftp/curl && make install clean
  4. Edit crontab (crontab -e) add the entry (The path is for finding stuff in the system)
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
    */15 * * * * /etc/ddns/update.sh >/dev/null 2>&1
  5. Below the ------------ line copy the lot and save it as /etc/ddns/update.sh
  6. Edit the update.sh to your needs that's 1) Interface 2) Username 3) Password 4) Domain
  7. That's it.
    Shell scripting has a nice feature, to see what the script does edit the first line
    in the script to looks like below, run it the from the promt. This will show you that all things get set right. When it all looks great just remove it and fire up the crontab.

#!/bin/sh -x


#!/bin/sh

FreeBSD ddns script for changeip.com

Created by Goran[AT]Partman.se, "The need has no law".This script only update one host @ changeip.com


\

Set the wan interface. Remember to pick the one connected to your router/modem/3G,

if="nfe0"

Logfile, no need to change that.

log="/etc/ddns/update.log"

Set your Changeip.com username in the " " area.

uid="MY_UID_AT_CHANGEIP"

Set your Changeip.com password in the " " area.

pw="MY_PASS_AT_CHANGEIP"

Set your domain in the " " area.

host="MY.COOL.DOMAIN.SE"

################### CONFIG AREA ABOVE, THIS IS THE LAZY PART ###############################
wanip=ifconfig $if | grep inet | cut -f2 | awk '{ print $2 }'

if [ -z $wanip ];then
echo "Check your interface, no wanip noticed"
exit 1
fi
regdns=dig $host | grep -v ";" | grep $host | awk '{ print $5 }'
if [ -z $regdns ];then
echo "Check your hostname. It cannot be resolved"
exit 1
fi

Check out if we dig out ok.

if [ $wanip = $regdns ];then
echo "DNS is fresh, no update needed"
exit 0
else
echo "date New IP ($wanip), updating DNS" >> $log
/usr/local/bin/curl -k -s "https://nic.changeip.com/nic/update?u=$uid&p=$pw&cmd=update&hostname=$host&ip=$w
anip" >/dev/null 2>&1
exit 0
fi

Hello - excellent!

I do recommend you using this:

–user-agent, and set it to your email address or some way to contact you. It’s even nicer to include a version number so you can tell who is running older scripts vs newer ones.

–user user:password, this way you aren’t getting your user ID and password stuff into logs somewhere. Even though it is SSL, since you are passing these in the querystring (and not the body) they will get captured sometimes. Telling curl to include them using Basic Auth they will get encrypted in the SSL session.

Thx!
Sam

Thanks for the input. That’s two good pointers.

/Cheers
Goran