Last active
July 9, 2018 00:35
-
-
Save longshorej/791ccf474b7564f7d0c93c8d98fb18df to your computer and use it in GitHub Desktop.
Update Google Domains Dynamic DNS entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Updates a Dynamic DNS entry hosted on Google Domains. | |
hostname="yourhost.example.com" | |
# These are specific to Google Domains, do not use account credentials / app passwords | |
# See the Google Domains dashboard. | |
username="yourusername" | |
password="yourpassword" | |
last_ip= | |
while [ true ]; do | |
ip=$(dig +short myip.opendns.com @resolver1.opendns.com) | |
if [ "$ip" != "$last_ip" ]; then | |
# Pass authentication to curl over stdin so that credentials don't appear in /proc | |
curl -H "User-Agent: dns-updater" \ | |
-H "Host: domains.google.com" \ | |
"https://domains.google.com/nic/update?hostname=${hostname}&myip=${ip}" \ | |
-K- <<< "-u $username:$password" | |
last_ip="$ip" | |
fi | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment