Skip to content

A Bash script that keeps your Google Domains Dynamic DNS updated.

Notifications You must be signed in to change notification settings

noUsernamesLef7/google-dynamic-dns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

google-dynamic-dns

A Bash script that keeps your Google Domains Dynamic DNS updated.

Why

I have a domain registered with Google Domains and wanted to implement Dynamic DNS on one of my subdomains. The common method of using your router to keep it updated didn't work for me as my router only supports a two Dynamic DNS providers, neither of which is Google. I looked for an existing script but was unsatisfied with the ones I found so I decided to write my own.

How It Works

Google provides an API that you can use to change your Dynamic DNS record to match your current public IP. Documentation for this API is here. This script automates that process, provides feedback useful in troubleshooting, and tries to prevent you from accidentally getting Dynamic DNS blocked on your domain by running too many requests. It's meant to be run on a frequent basis, using something like cron, or you could optionally run it when a change in your public IP address is detected.

The script tries to keep you from making bad requests. It checks the current public IP every time it's run and if it hasn't changed it exits. If and request returns an error or something unexpected, it will change the value stored in the "success" file from 0 to 1. Once that happens, it won't run again until you have manually corrected the problem and changed that value back to 0. Better safe than sorry in my view.

The only other thing to note is that if you call the script with the "--test" argument, the scripts functions will be loaded into the current shell session but not run. This could be useful for importing them into a different script using "source" but in this case it's mostly to allow the test.sh script to test functions to make sure they are behaving as expected. This kind of testing in Bash is pretty hacky and I was mostly just curious to see how/if it could be done.

Dependencies

curl

Installation

  • Clone the repository to your preferred installation location. I suggest /opt but /usr/local or somewhere else is fine.
    git clone [email protected]:noUsernamesLef7/google-dynamic-dns.git
  • Edit the script and ensure that the $DATA_PATH variable matches the path to your install directory. While you have the file open, copy your hostname, username, and password from your Google Domains Dynamic DNS page. You can also edit the log file location if you wish.
  • Make the script executable
chmod +x /opt/google-dynamic-dns/google-dynamic-dns.sh
  • Create your log file directory and file
mkdir /var/log/google-dynamic-dns
touch /var/log/google-dynamic-dns/log.txt
  • Add a crontab entry to run with a certain frequency
crontab -e

And add an entry like */5 * * * * /opt/google-dynamic-dns/google-dynamic-dns.sh

That's it, now it will run every five minutes. Here is a handy tool for creating cron schedule expressions if you want something different.

About

A Bash script that keeps your Google Domains Dynamic DNS updated.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages