Skip to content

Instantly share code, notes, and snippets.

@RunningDroid
Last active May 7, 2022 08:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RunningDroid/ae37d1812168354bd3d53f6f0a9f1ed0 to your computer and use it in GitHub Desktop.
Save RunningDroid/ae37d1812168354bd3d53f6f0a9f1ed0 to your computer and use it in GitHub Desktop.
FreeDNS updater script with IPv4 and IPv6 support
#!/bin/sh
#FreeDNS updater script with IPv4 and IPv6 support
# (Initially) based on update.sh by Adam Dean: https://freedns.afraid.org/scripts/update.sh.txt
# requirements:
# curl
# dig
# posix-compatible shell
# Note: http://whatismyipaddress.com/api says:
# "You may programmatically query that server but limit queries to no more
# than once per five minutes and include an appropriate user agent that will
# allow us to contact you if needed. Requests with a blank user agent may be
# dropped."
# if you don't want to set the IPv4 or IPv6 address
# then replace "_YOURAPIKEYHERE_" with an empty
# string like this: ""
# TODO: pull all this from a config file
APIKEY_V4="_YOURAPIKEYHERE_"
APIKEY_V6="_YOURAPIKEYHERE_"
DOMAIN="_YOURDOMAINHERE_"
USER_AGENT='default'
update_url="https://freedns.afraid.org/dynamic/update.php?"
if [ "${USER_AGENT}" = 'default' ]; then
curl_opts=""
else
curl_opts="--user-agent ${USER_AGENT}"
fi
# FIXME:I have no idea how this will behave if
# whatismyipaddress can't find an address
if [ -n "${APIKEY_V4}" ]; then
registered_v4="$(dig +short @ns4.afraid.org ${DOMAIN} A)"
current_v4="$(curl --silent ${curl_opts} http://ipv4bot.whatismyipaddress.com/)"
if [ -n "${current_v4}" ]; then
if [ "$current_v4" != "$registered_v4" ]; then
curl "${update_url}${APIKEY_V4}&address=${current_v4}"
echo "DNS A record changed to: $current_v4"
fi
fi
fi
if [ -n "${APIKEY_V6}" ]; then
registered_v6="$(dig +short @ns4.afraid.org ${DOMAIN} AAAA)"
current_v6="$(curl --silent ${curl_opts} http://ipv6bot.whatismyipaddress.com/)"
if [ -n "${current_v6}" ]; then
if [ "$current_v6" != "$registered_v6" ]; then
curl "${update_url}${APIKEY_V6}&address=${current_v6}"
echo "DNS AAAA record changed to: $current_v6"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment