Dynamic DNS with launchd and cURL

As someone who opts for home hosting services and websites, having a dynamic IP assigned from my ISP is quite troublesome. Dynamic DNS helps solve the headache of a non-static (frequently changing) IP address by allowing immediate updating of DNS records. Fortunately, many services like DynDns and No-IP have software integrated into routers to perform these updates as the IP address changes. Unfortunately, I use Google Domains as my registrar, and their Dynamic DNS service is not available as an endpoint for my router. However, Dynamic DNS is super simple, and we don’t need any specialized software to perform these updates.

Google Domains has a simple HTTP api that lets you update the IP address for dns records. The format is as follows: https://username:password@domains.google.com/nic/update?hostname=subdomain.yourdomain.com&myip=

This is where launchd comes in. If I can easily update my DNS records with a simple cURL, I can replace the recommended programs (ddclient and inadyn) with building blocks my operating system comes with.

launchd manifest

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

dynamic dns update script

IP=`curl -s ifconfig.me`
curl -v "https://username:password@domains.google.com/nic/update?hostname=@.worldpeace.social&myip=$IP"
curl -v "https://username:password@domains.google.com/nic/update?hostname=dynamic.haze.cool&myip=$IP"
curl -v "https://username:password@domains.google.com/nic/update?hostname=server.haze.cool&myip=$IP"
curl -v "https://username:password@domains.google.com/nic/update?hostname=music.haze.cool&myip=$IP"