DDNS for FREE with GoDaddy

why DDNS is needed

You may need DDN in following cases:

  • You don’t have static IP (or don’t want to pay for it) for your home router, but you would like to have access to your home network from the internet (with openvpn for example).
  • You have a cloud server instance (AWS, Azure, GCP, etc.) and don’t want to pay for a static address. Unfortunately, cloud-based instances can change their public IP from time to time.

HOW it works with godaddy

Fortunately, GoDaddy (one of the most popular hosting providers and DNS name registers) provides the ability to change IP address association for your domain name with API. 

So, you can check actual public IP of your server/router/instance and update it in your GoDaddy DNS configuration with a script.

Unfortunately, I didn’t find any information about limitations for the quantity of API calls per any period (hour/day/etc.). But, as usual, API providers have such limitations and block API if the limit is exceeded. 

To avoid such situation you should call the API then IP changed only, but not with timer only.

Lets start to configure your DDNS

HOW to get your API key

GoDaddy API key can be obtained with following link: https://developer.godaddy.com/keys

Press “Create New API Key”

So, you have got your API key and can use it for the DDNS script.

DDNS Script

So, you have got your API key and can use it for the DDNS script.

I’m using vi editor for the example but feel free to use your preferred one.

host:# touch /opt/update_my_ip.sh
host:# chmod +x /opt/update_my_ip.sh
host:# vi /opt/update_my_ip.sh
#!/bin/bash

mydomain="YorDomainName.com"
myhostname="@"
gdapikey="GoDaddy API Key from previous step"

#Getting your actual public IP
myip=`/usr/bin/curl -s "https://api.ipify.org"`

#Getting your carrent DNS resolving. 
#Name server 8.8.8.8 is used to avoid local DNS cache affecting
dnsip=`/usr/bin/nslookup $mydomain 8.8.8.8 | tail -n 2 | grep Address`

dnsip=${dnsip##*' '}

#Debugging output

echo "MyIP: $myip"
echo "CurrentDNS record: $dnsip"

#Update your DNS record in GoDaddy config

if [ "$dnsip" != "$myip" ]; then
echo "IP is changed to: $myip"
/usr/bin/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}\"}]"
fi

The last step is configuring crontab to run your script periodically by adding the following string to crontab file.

host:# sudo vi /etc/crontab
*/10 * * * * root /opt/update_my_ip.sh > /dev/null

Now you should restart your cron daemon to apply the config.

host:# sudo /etc/init.d/cron restart
Restarting cron (via systemctl): cron.service.

Now you should restart your cron daemon to apply the config.

The article on how to install OpenVPN on OpenWRT can be interesting for you as well.

Please ask any questions in the comments for the article.

Leave a Reply

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