Updating GoDaddy A Record to Dynamic IP with Crontab and Bash Script
Updating GoDaddy A Record to Dynamic IP with Crontab and Bash Script
1) Go to godaddy, login to the host account and generate an API key/secret: https://developer.godaddy.com/keys
2) Make sure there is an a record created like such
3) Go to the host server and type: 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):
5) Press Ctrl+O to save and then Ctrl+X to exit
6) Type: (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: but replace YOUR-USERNAME-HERE with your server username
This will execute every hour. Use https://crontab.guru/ 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.
2) Make sure there is an a record created like such
3) Go to the host server and type:
Code: Select all
cd /home/YOUR-USERNAME-HERE; nano ddns-a-update.sh
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
#!/bin/bash
domain=YOUR-DOMAIN-HERE.com
host=@
APIKey=YOUR-API-KEY-HERE
APISecret=YOUR-API-SECRET-HERE
WanIP=`curl -s "https://api.ipify.org"`
GDIP=`curl -s -X GET -H "Authorization: sso-key ${APIKey}:${APISecret}" "https://api.godaddy.com/v1/domains/${domain}/records/A/${host}" | cut -d'[' -f 2 | cut -d']' -f 1`
if [ "$WanIP" != "$GDIP" -a "$WanIP" != "" ]; then
curl -s -X PUT "https://api.godaddy.com/v1/domains/${domain}/records/A/${host}" -H "Authorization: sso-key ${APIKey}:${APISecret}" -H "Content-Type: application/json" -d " [{\"data\": \"${WanIP}\"}]"
fi
6) Type:
Code: Select all
crontab -e
7) Below all the lines of comments, paste in the new crontab task:
Code: Select all
0 * * * * /home/YOUR-USERNAME-HERE/ddns-a-update.sh
This will execute every hour. Use https://crontab.guru/ 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.