Home Assistant with Google Domains & Let's Encrypt

I wanted to create this topic specifically for people like me who use Google Domains. I’m not sure if it’s the best DNS provider, but it is simple and meets my needs. This thread is going to be a bit meandering as I’m documenting what I’ve done and would like to do but hopefully, some will find it useful.

Before I discovered HA, I was (and am still using) PiHole and OpenVPN (installed and managed by PiVPN) on a ODROID C2 device. When I log into domains.google.com, here is what my synthetic records look like:

As you can see, I have a mixture of Dynamic DNS and Subdomain forward entries. I have a NAS which is running Windows Server Essentials 2012 R2, and on that device, I host an IIS website called lights.example.com and I also run qbittorrent and you can see corresponding entries in my DNS records. Note that lights.example.com is a straight DNS entry, while torrent.example.com is a subdomain forward. Why did I do this? That’s because IIS allows you to use host headers. So when I visit lights.example.com, in the address bar I see lights.example.com. And while qbittorrent is also on the same machine as my IIS website, it’s internal webserver doesn’t use host headers. Since I have qbittorrent configured to use port 8085, a straight subdomain forward works well enough. So all I have to remember is torrent.example.com and google domains will forward that to example.com:8085. The only downside is that is also what appears in the address bar.

Like most dynamic dns services, you have to be cognizant that your IP address may change, and you need to update your records accordingly. I took a real simple approach. First I created a file /usr/local/bin/ggdns.sh and then did a chmod 777 /usr/local/bin/ggdns.sh to make the script executable. The script looks like:

curl -d '' https://<u1>:<p1>@domains.google.com/nic/update?hostname=example.com
curl -d '' https://<u2>:<p2>@domains.google.com/nic/update?hostname=lights.example.com
curl -d '' https://<u3>:<p3>@domains.google.com/nic/update?hostname=torrent.example.com

Note, that each google domain dynamic dns entry has it’s own username/password. If you click the arrow to the left of the DNS entry in question, you will see that entry expand. Clicking on View credentials will let you see the actual values. You can copy and paste those into the script (don’t forget to replace the <> as well). Now everytime you run ggdns.sh, those DNS entries will be updated to that of your WAN IP. To have this script run automatically on a timer, from the command line type:

crontab -e

Scroll all the way to the bottom of the file and add the following, which will run ggdns.sh every five minutes.

*/5 * * * * /usr/local/bin/ggdns.sh

That’s it for now. My next post will be a bit about installing Hassio and using Let’s Encrypt.

1 Like

You should reconsider moving away from a VPN. Open Home Assistant up and access the rest through the VPN. I hope you’re at least using Nginx (doesn’t sound like you are) for each service exposed to the internet.

VPN is on a different box.

Any suggestions on how to force ipv4 update to google domains? Instead of ipv6

That script above uses ip4 for me at least.