Skip to content

Instantly share code, notes, and snippets.

@jacobq
Last active July 14, 2020 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobq/eb6cb46c66eea1695f4ccd656845a665 to your computer and use it in GitHub Desktop.
Save jacobq/eb6cb46c66eea1695f4ccd656845a665 to your computer and use it in GitHub Desktop.
FreeDNS (afraid.org) dynamic DNS updater script: e.g put in /etc/cron.hourly/update-dynamic-dns.sh
#!/bin/sh
# FreeDNS updater script
# Adapted from https://freedns.afraid.org/scripts/update.sh.txt
# sudo apt install dnsutils wget
DOMAIN="foo.my-custom-domain.com"
API_KEY="put your API key (base64 string) here"
SHOULD_UPDATE=0
# -f is the only argument supported right now (forces update even if address appears correct)
[ "${@:-0}" = "-f" ] && {
echo "Forcing update"
SHOULD_UPDATE=1
}
current=$(/sbin/ifconfig eth0 | grep 'inet' | cut -d: -f2 | awk '{ print $2}'|head -n 1)
registered=$(nslookup $DOMAIN|tail -n2|grep A|sed s/[^0-9.]//g)
external=$(wget -q -O - http://checkip.dyndns.org|sed s/[^0-9.]//g)
echo "current = $current, registered = $registered, external = $external"
[ "$current" != "$registered" ] && {
echo "Current entry does not appear to match"
SHOULD_UPDATE=1
}
[ "$SHOULD_UPDATE" = "1" ] && {
echo "Updating now ($(date))"
#UPDATEURL="http://freedns.afraid.org/dynamic/update.php?$API_KEY" # Use public IP / default
UPDATEURL="http://freedns.afraid.org/dynamic/update.php?$API_KEY&address=$current" # use address specified in $current
wget -q -S -O - $UPDATEURL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment