Skip to content

Instantly share code, notes, and snippets.

@cyrusboadway
Created February 20, 2016 17:21
Show Gist options
  • Star 88 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save cyrusboadway/5a7b715665f33c237996 to your computer and use it in GitHub Desktop.
Save cyrusboadway/5a7b715665f33c237996 to your computer and use it in GitHub Desktop.
Script to update a Google Domains DNS record
#!/bin/bash
### Google Domains provides an API to update a DNS "Syntheitc record". This script
### updates a record with the script-runner's public IP, as resolved using a DNS
### lookup.
###
### Google Dynamic DNS: https://support.google.com/domains/answer/6147083
### Synthetic Records: https://support.google.com/domains/answer/6069273
USERNAME=""
PASSWORD=""
HOSTNAME="yoursubdomain.yourdomain.here"
# Resolve current public IP
IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
# Update Google DNS Record
URL="https://${USERNAME}:${PASSWORD}@domains.google.com/nic/update?hostname=${HOSTNAME}&myip=${IP}"
curl -s $URL
@AdamKearn
Copy link

AdamKearn commented May 20, 2020

I know this is an old thread but you can just send a request to the URL and not include the IP just pass the username and password.
The API will then use the IP the request was sent from.

e.g.
curl https://username:password@domains.google.com/nic/update?hostname=subdomain.yourdomain.com

For more details see the section at the bottom of this page labelled "Using the API to update your Dynamic DNS record"
https://support.google.com/domains/answer/6147083?hl=en-GB

Copy link

ghost commented Dec 8, 2020

I had to change line 15 to IP=$( curl ifconfig.me ). Other than that the script works.

@Dayday10
Copy link

A stare is born

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment