Skip to content

Instantly share code, notes, and snippets.

@mcarpenterjr
Created July 17, 2017 15:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcarpenterjr/1dedf9f9f842710ba5f07937ef4f5ae4 to your computer and use it in GitHub Desktop.
Save mcarpenterjr/1dedf9f9f842710ba5f07937ef4f5ae4 to your computer and use it in GitHub Desktop.
Linux bash script for updating dns on godaddy dynamically. You need a developer account to access the godaddy api to get your secret and token.
#!/bin/bash
# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
# Special thanks to mfox for his ps script
# https://github.com/markafox/GoDaddy_Powershell_DDNS
#
# First go to GoDaddy developer site to create a developer account and get your key and secret
#
# https://developer.godaddy.com/getstarted
# Be aware that there are 2 types of key and secret - one for the test server and one for the production server
# Get a key and secret for the production server
#
#Update the first 4 variables with your information
domain="" # your domain
name="" # name of A record to update
key="" # key for godaddy developer API
secret="" # secret for godaddy developer API
headers="Authorization: sso-key $key:$secret"
# echo $headers
result=$(curl -s -X GET -H "$headers" \
"https://api.godaddy.com/v1/domains/$domain/records/A/$name")
dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
# echo "dnsIp:" $dnsIp
# Get public ip address there are several websites that can do this.
ret=$(curl -s GET "http://ipinfo.io/json")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
# echo "currentIp:" $currentIp
if [ $dnsIp != $currentIp ];
then
# echo "Ips are not equal"
request='{"data":"'$currentIp'","ttl":3600}'
# echo $request
nresult=$(curl -i -s -X PUT \
-H "$headers" \
-H "Content-Type: application/json" \
-d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
# echo $nresult
fi
@spjspj
Copy link

spjspj commented Oct 20, 2022

request='[ { "data":"$currentIp", "ttl": 3600} ]'

^^ needs more square brackets! (based on https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName)

@mbuck1
Copy link

mbuck1 commented Apr 14, 2024

Script didn't work for me. I had to add record type to the request field:
request="[{\"data\":\"$currentIp\",\"ttl\":600,\"type\":\"A\"}]"

@SanPollo
Copy link

SanPollo commented May 3, 2024

This no longer works unless you have 20 or over (or maybe 50 or over) domains with GoDaddy as they have disabled the API without telling anyone. You will get a "Authenticated user is not allowed access" response.

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