afraid.org_update_script
This is the script I use to keep the dynamic DNS in sync.
- Afraid.Org_update.sh
#!/bin/sh # /usr/local/bin/Afraid.org.update.sh # Run me to set the external address up # # SRJ 2011-03-12 Initial build # SRJ 2012-12-10 Modified first wget line for new router # SRJ 2017-05-03 Updated the IP test again, IP Chicken is being weird # SRJ 2025-02-04 Verified this still works as expected, and spell check. # # A note about Cincinnati Bell/AltaFiber - I have records of address changes # going back to 2017-04-30 and as of 2025-02-04, my external address has # only changed 49 times. That includes two moves and at least one server # rebuild, plus the change in billing. I get amazing service from these # folks at a reasonable cost. Currently getting about 680MBS Down and 640 # Up, with a Max delay of 3ms connecting to Netflix servers; # https://stevejonescomputers.com/SpeedTest.png # This is tested using Sindre Sorhus' fast-cli # # - - - - 8< - - - - - >8 - - - - # This should be used from cron as below; # root@home:~$ crontab -l # # .---------------- minute (0 - 59) # # | .------------- hour (0 - 23) # # | | .---------- day of month (1 - 31) # # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # # | | | | .---- day of week (0-6) (Sun=0) OR sun,mon,tue,wed,thu,fri,sat # # | | | | | # # * * * * * command to be executed # */10 * * * * /usr/local/bin/Afraid.org.update.sh # Run every ten minutes # - - - - 8< - - - - - >8 - - - - # # Make sure that anybody or thing can read the Logfile # (In my environment, this is fine, ymmv) umask 000 Logfile=/var/log/Afraid.org.log # Once the log file is created with open permissions, this script can and should # be run as a regular user. # The variable 'Current' needs to be modified if you aren't getting # a proper IP address in it. # This sometimes failed to report, giving a nul that then triggered # an un-needed update. # Current=$( # wget -q -O- "http://checkip.dyndns.org/" \ # | grep -o -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" # ) # Let's give this a try for a while! Current=$( dig @resolver4.opendns.com myip.opendns.com +short -4 ) # Or # dig @resolver3.opendns.com myip.opendns.com +short # dig @ns1-1.akamaitech.net ANY whoami.akamai.net +short # curl -s http://whatismyip.akamai.com/ && echo # Present the date in an easily grepable fashion. Date=$( date +"%Y-%m-%d-%H-%M" ) # If the Logfile doesn't exist, create it with a known IP address. if [ ! -f $Logfile ] ; then echo "${Date} 0.0.0.0" >> ${Logfile} fi # If the Logfile still does not exist, something is wrong, cry for help. if [ ! -f $Logfile ] ; then echo "Cannot create ${Logfile} - check directory permissions" exit 1 fi # What was our IP address the last time it changed? Last=$( tail -1 ${Logfile} | cut -d " " -f 2 ) # If our current IP is the same as it was at last change, then there # isn't any reason to contact Afraid.org, just die with grace. if [ "${Current}" = "${Last}" ] ; then # No update is required, silently exit. exit 0 fi echo "Update of external IP address needed." echo "${Date} ${Current}" >> ${Logfile} # The line below is from afraid.org and is what actually sets the DNS entries # for the domain. Make sure you have a valid string for a domain you own! wget -q --read-timeout=0.0 --waitretry=5 --tries=400 -O- \ https://freedns.afraid.org/dynamic/update.php?ZHA5bbbNotARealThingdddTk3xWk5yeVI6MjIwNjI0MzA=
afraid.org_update_script.txt · Last modified: by steve
