Dynamic DNS setup for godaddy

This article will show you how to programmatically update DNS settings for your domain registered on godaddy.

Prerequisites

  • A registered and valid domain on godaddy
  • Your home server which host your domain can run a shell script.

The idea is running a cron job updating your godaddy DNS setting periodically in case your IP is changed by your ISP

Create an “A” record on your DNS record table

Type Name Data TTL
A	@	11.11.11.11	600 seconds

# The data will be changed once you have your script running, (Your current IP will show there)

Create godaddy API key to access developer API

Go to https://developer.godaddy.com/keys to create an API key, you’ll need this key and secret later

Create bash script to update DNS record

#!/bin/bash

# Replace with your domain here
mydomain="your-domain.here"
myhostname="mail"
# Make sure you have a colon separate your api key and secret
gdapikey="api_key:key_secret"
logdest="local7.info"

myip=`curl -s "https://api.ipify.org"`
dnsdata=`curl -s -X GET -H "Authorization: sso-key ${gdapikey}" "https://api.godaddy.com/v1/domains/${mydomain}/records/A/${myhostname}"`
gdip=`echo $dnsdata | cut -d ',' -f 1 | tr -d '"' | cut -d ":" -f 2`
echo "`date '+%Y-%m-%d %H:%M:%S'` - Current External IP is $myip, GoDaddy DNS IP is $gdip"

if [ "$gdip" != "$myip" -a "$myip" != "" ]; then
  echo "IP has changed!! Updating on GoDaddy"
  curl -s -X PUT "https://api.godaddy.com/v1/domains/${mydomain}/records/A/${myhostname}" -H "Authorization: sso-key ${gdapikey}" -H "Content-Type: application/json" -d "[{\"data\": \"${myip}\"}]"
  logger -p $logdest "Changed IP on ${hostname}.${mydomain} from ${gdip} to ${myip}"
fi

Create a cron job to run bash script in background.

In redhat 7, you can put your script under /etc/cron.daily/ folder, the cron job will pick up and run updating DNS script daily.

Check your cron job log

tail /var/log/cron-<yyyymmdd>

References:

Leave a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Scroll to Top