Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Last active May 23, 2019 00:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/04ee1a5427af0a6e2b10e0884bab8a08 to your computer and use it in GitHub Desktop.
Save TooTallNate/04ee1a5427af0a6e2b10e0884bab8a08 to your computer and use it in GitHub Desktop.
Google Domains Dynamic DNS record update script - syncs a host to a target (pseudo-ALIAS)
#!/usr/bin/env sh
#
# Usage:
# USERNAME=abcd12345 PASSWORD=ghij67890 HOST=n8.io TARGET=alias.zeit.co ./updater.sh
URL="https://domains.google.com/nic/update"
HOST_IP=$(dig @8.8.8.8 +short A "$HOST" | sort | tail -1)
TARGET_IP=$(dig @8.8.8.8 +short A "$TARGET" | sort | tail -1)
if [ "$HOST_IP" != "$TARGET_IP" ]; then
echo "Updating Dynamic DNS record for host $(tput bold)$HOST$(tput sgr0) to IP $(tput bold)$TARGET_IP$(tput sgr0)"
curl \
--silent \
--request POST \
--user "$USERNAME:$PASSWORD" \
--header "Content-Length: 0" \
--header "User-Agent: https://git.io/v6LQz" \
"$URL?hostname=$HOST&myip=$TARGET_IP"
echo
else
echo "Dynamic DNS for host $(tput bold)$HOST$(tput sgr0) is up-to-date!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment