trhall chop image Thomas R. Hall Thoughts...

Configuring Dynamic DNS with Google Domains

One of the nice features of Google Domains is that they also support Dynamic DNS. While there are other services that support Dynamic DNS, why not take advantage of the free built-in functionality provided by Google Domains, using your own domain name? Let’s step through the process of setting up a Dynamic DNS entry with Google Domains, as well as updating the entry via ddclient on a computer within your home network.

Configuring Dynamic DNS with Google Domains

This process is really straight forward. Simply follow the instructions in the help article about Dynamic DNS under the Setting up a Dynamic DNS synthetic record heading. Create a Dynamic DNS entry under the Synthetic Records heading. This creates a DNS A record that can be dynamically updated.

Dynamic DNS Credentials

Expand the triangle and click View Credentials to see the generated username and password. This will be used in the next section.

Installing ddclient

Some routers have the ability to update Dynamic DNS entries directly within the router interface. In my case, I’m using an Apple Airport Extreme, so I need to install a client program on one of the computers in my network. In this case, I’ll use ddclient via Homebrew:

sudo brew install ddclient

Configuring ddclient

Create a configuration file /usr/local/etc/ddclient/ddclient.conf, adding details that Google Domains generated above.

ssl=yes
protocol=googledomains
use=cmd, cmd=/Users/example/bin/get_external_ip.sh
login=abcd
password=mypass
myhome.example.net

In my case, since I’m using a computer connected via a router, I need to get my external IP address. This article on OS X Daily was quite helpful to determine a quick dig command to accomplish this.

Create the script used in the cmd section above, in this case, get_external_ip.sh:

#!/bin/sh

dig +short myip.opendns.com @resolver1.opendns.com

Testing ddclient

First, let’s test ddclient to make sure it works:

sudo /usr/local/opt/ddclient/sbin/ddclient -verbose

If things worked, then the entry in Google Domains will now show your IP address.

Running ddclient regularly

On my Mac, I would also like to run ddclient regularly. This will keep my DNS entry updated in the event that my external IP address changes. You could accomplish this via cron, but we’ll use the built-in Mac functionality (launchctl). Homebrew already comes with the .plist file needed, it just needs to be activated.

sudo cp -fv /usr/local/opt/ddclient/homebrew.mxcl.ddclient.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.ddclient.plist

This will run every 300 seconds (5 minutes) and ensure that my IP is kept updated.