Page 1 of 1

Updating GoDaddy A Record to Dynamic IP with Crontab and Bash Script

Posted: Sun Sep 20, 2020 5:39 pm
by george
1) Go to godaddy, login to the host account and generate an API key/secret:

2) Make sure there is an a record created like such
a record.png
a record.png (23.73 KiB) Viewed 1212 times

3) Go to the host server and type:

Code: Select all

cd /home/YOUR-USERNAME-HERE; nano
but replace YOUR-USERNAME-HERE with your server username

4) paste the following code into the nano text editor, and make sure to replace YOUR-DOMAIN-HERE, YOUR-API-KEY-HERE, and YOUR-API-SECRET-HERE with the correct website (without www.), api key and api secret (supplied from the godaddy website in step 1):

Code: Select all


WanIP=`curl -s ""`

GDIP=`curl -s -X GET -H "Authorization: sso-key ${APIKey}:${APISecret}" "${domain}/records/A/${host}" | cut -d'[' -f 2 | cut -d']' -f 1`

if [ "$WanIP" != "$GDIP" -a "$WanIP" != "" ]; then
curl -s -X PUT "${domain}/records/A/${host}" -H "Authorization: sso-key ${APIKey}:${APISecret}" -H "Content-Type: application/json" -d " [{\"data\": \"${WanIP}\"}]"
5) Press Ctrl+O to save and then Ctrl+X to exit

6) Type:

Code: Select all

crontab -e
(select nano as the text editor, if asked, and make sure to not be logged in with root (sudo su - if you are type exit, then use crontab -e again without root permissions)

7) Below all the lines of comments, paste in the new crontab task:

Code: Select all

0 *    *   *   *          /home/YOUR-USERNAME-HERE/
but replace YOUR-USERNAME-HERE with your server username

This will execute every hour. Use to figure out your desired update formatting.

8) Press Ctrl+O to save and Ctrl+X to exit

Done! Now your GoDaddy A record will update dynamically every hour to your new IP address.