{{keywords>freebsd,unix,godaddy,dynamic,dns,update,script,bash,crontab,cronjob}}
====== Configuring Dynamic DNS Updates for GoDaddy ======
===== Environment =====
* FreeBSD 13.1
* Dynamic IP address
* Domain from GoDaddy
===== Required Ports =====
* ''ftp/curl''
* ''shells/bash''
===== Overview =====
** Since around March 2024, GoDaddy have blocked their API to all users who have less than 50 domains registered with them. I recommend you use [[https://www.cloudflare.com/plans/free/|Cloudflare's free DNS]] with ''dns/ddclient'', and move your registrar before your domain is next up for renewal. **
Most home users have a dynamic IP address provided by their ISP. If they want to host their own services, such as a web server, this poses a problem as if their IP changes, their domain no longer points to the correct address.
This article explains how to set up a cronjob which periodically calls a script to update a domain's DNS record if the server's external IP has changed.
===== Installation =====
If you do not already have ''ftp/curl'' and ''shells/bash'' installed then install them from [[https://docs.freebsd.org/en/books/handbook/ports/#pkgng-intro|packages]], or build it from the [[https://docs.freebsd.org/en/books/handbook/ports/#ports-using|ports]] collection.
Now download {{ :tech:unix:freebsd:updatedomain.sh |updatedomain.sh}}, and copy it to ''/usr/local/bin''. It is a bash version of [[https://github.com/markafox/GoDaddy_Powershell_DDNS|this PowerShell script]], which has been modified several times. The script is believed to be in the public domain.
Set the permissions on the script so only the owner can read and execute it:
# chmod 700 /usr/local/bin/updatedomain.sh
===== Configuration =====
==== GoDaddy API Key and Secret ====
Firstly you will need a GoDaddy API key and secret [[https://developer.godaddy.com/keys|from here]] for the Production environment. Make sure you keep it safe as it can be used to manipulate your domain.
==== Edit Script Variables ====
Now edit ''/usr/local/bin/updatedomain.sh'', and fill in the **key** and **secret** values that you got from GoDaddy.
key="" # key for godaddy developer API
secret="" # secret for godaddy developer API
If you intend to run the script as a user other than **root** then change the ownership to that user:
# chown nobody /usr/local/bin/updatedomain.sh
==== Add cronjob ====
Now edit the crontab for the user who will run the script. If it is **root** then simply run:
# crontab -e
Otherwise specify the name of the user:
# crontab -u nobody -e
If you want your domain, and all subdomains, to be updated when your IP changes, add the following line to your crontab:
*/5 * * * * /usr/local/bin/updatedomain.sh @ yourdomain.ro >> /var/log/updatedomain.log
If you only want one of your subdomains to be updated then add this one:
*/5 * * * * /usr/local/bin/updatedomain.sh subdomain yourdomain.ro >> /var/log/updatedomain.log
The script is set to run every 5 minutes. You can, of course, [[https://crontab-generator.org/|change this if you like]]. Note that the location for the log file, ''/var/log/updatedomain.log'' in this example, must be writable by the user running the script, or any domain updates will not be logged. Once you have confirmed that the script is working for you, you can replace ''/var/log/updatedomain.log'' with ''/dev/null'' to suppress the output of the script altogether.
===== DNS Record TTLs =====
I recommend you go to [[https://dcc.godaddy.com/manage/dns|GoDaddy DNS Management]], and change your domain and any subdomains' TTL setting from **1 Hour** to **1200 seconds** (20 minutes). This means that your new IP will be propagated in a maximum of 20 minutes. You could reduce this value further, but performance may be affected.
===== References =====
[[https://www.reddit.com/r/godaddy/comments/1bl0f5r/am_i_the_only_one_who_cant_use_the_api/|Reddit: Am I the only one who can't use the API?]]\\
[[https://community.godaddy.com/s/question/0D53t00006VmU0qCAF/dynamic-dns-updates|Dynamic DNS Updates thread on GoDaddy Community]]\\
[[https://github.com/markafox/GoDaddy_Powershell_DDNS|GoDaddy_Powershell_DDNS by markafox on GitHub]]