Skip to content

Instantly share code, notes, and snippets.

@hospadar
Created October 18, 2018 16:11
Show Gist options
  • Save hospadar/e9869cf2dc9db753069a986e28ec8f50 to your computer and use it in GitHub Desktop.
Save hospadar/e9869cf2dc9db753069a986e28ec8f50 to your computer and use it in GitHub Desktop.
freedns dynamic dns update script
#!/bin/bash
#Handy update script for auto-updating your IP4 and IP6 dynamic DNS name if you use freedns.afriad.org.
#Probably other providers could be used as well if you modify the update URLs slightly
#uses opendns.com's magic resolver to try and figure out actual public-facing IP addresses
set -e
#To set up:
#go create an A record (for IP4) and a AAAA record (for IP6) for the same dynamic domain name
#replace the <angle bracketed sections> with the appropriate dynamic dns name and update URLs
MY_DOMAIN=<your freedns dynamic domain name>
IP4_UPDATE_URL=<your freedns ip4 update URL>
IP6_UPDATE_URL=<your freedns ip6 update URL>
ACTUAL_IP4=$(dig +short myip.opendns.com @resolver1.opendns.com)
ACTUAL_IP6=$(dig +short -6 myip.opendns.com aaaa @resolver1.ipv6-sandbox.opendns.com)
REGISTERED_IP4=$(dig +short ${MY_DOMAIN} @ns1.afraid.org)
REGISTERED_IP6=$(dig +short -6 ${MY_DOMAIN} aaaa @ns1.afraid.org)
if [ "$ACTUAL_IP4" != "$REGISTERED_IP4" ]
then
echo "Updating IP4 registration"
curl "${IP4_UPDATE_URL}&address=${ACTUAL_IP4}"
else
echo "IP4 Address has not changed (old: ${REGISTERED_IP4}, new: ${ACTUAL_IP4})"
fi
if [ "$ACTUAL_IP6" != "$REGISTERED_IP6" ]
then
echo "Updating IP6 registration"
curl "${IP6_UPDATE_URL}&address=$ACTUAL_IP6"
else
echo "IP6 address has not changed (old: ${REGISTERED_IP6}, new: ${ACTUAL_IP6})"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment