Skip to content

Instantly share code, notes, and snippets.

@RulerOf
Last active November 30, 2022 21:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RulerOf/71cd2a53ad37bec72b59e34960c0629d to your computer and use it in GitHub Desktop.
Save RulerOf/71cd2a53ad37bec72b59e34960c0629d to your computer and use it in GitHub Desktop.
Dynamic DNS Script I used for Google Domains with DD-WRT

DD-WRT Dynamic DNS for Google Domains

Create a Synthetic Record for Dynamic DNS. Copy the script and substitute your synthetic record's username, password, and FQDN in the config section.

Go to Administration > Commands tab and paste the code into the Command box, then click Save Custom Script.

Go to Administration > Management tab. Scroll down to the Cron section, and toggle Cron: Enable

In the Additional Cron Scripts section, put:

17 * * * * root /tmp/custom.sh

Scroll to the bottom. Click Apply Settings. Wait for the page to reload. Scroll back to the bottom and click Reboot Router.

Notes

  • The actual call to Google's API to update your IP address will not be made unless it has changed.
  • The cron timing I supplied above runs this at the 17th minute of every hour (e.g. 12:17, 1:17, etc).
#!/bin/sh -e
### CONFIG
DDNS_USERNAME="your-dynamic-domain-username"
DDNS_PASSWORD="your-dynamic-domain-password"
DDNS_HOSTNAME="your.dynamic.domain"
### END CONFIG
# Quit if we're not up very long
UPTIME=$(cat /proc/uptime | cut -f1 -d.)
if [ "$UPTIME" -lt "180" ]; then
exit 0
fi
# Get my public IP
PUBLIC_IP=$(ip route get 8.8.8.8 | grep -Eo 'src .*' | grep -Eo '(\d{1,3}\.){3}\d{1,3}')
# Resolve IP for DDNS record
DNS_IP=$( nslookup $DDNS_HOSTNAME | grep -Eo '(\d{1,3}\.){3}\d{1,3}' )
if [ "$DNS_IP" != "$PUBLIC_IP" ] ; then
URL="https://${DDNS_USERNAME}:${DDNS_PASSWORD}@domains.google.com/nic/update?hostname=${DDNS_HOSTNAME}"
wget -O - $URL 2> /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment