GoDaddy DDNS Updater

As I’m running this site itself on my 4TB WDMyCloud home NAS, refer to my post WebHosting on WDMyCloud V4 Firmwares, I will need my DNS to be always pointing to it when my public IP changes.

Although my public IP seldom changes, I’ve been using a Python based script with its ‘pygodaddy’ module for a while to auto update my GoDaddy DDNS pointing to my WDMyCloud NAS. The script is supposed to update my current public IP by parsing GoDaddys DNS update form. But on few occasions when there’s the need to update, the script failed to work because obviously GoDaddy had changed something in their front-end. I’ve also used a similar PHP based script but that too failed to work. And worst still, for as long that I know of, GoDaddy hasn’t provide any means of updating the records other than manually from their site itself.

Like many others with paid GoDaddy domain account, I’ve been looking for permanent solution not until recently and long awaited for, GoDaddy has finally implemented some APIs for developments which now provides the ability to update the DNS records via a REST call. You can see more details at their developer’s site, https://developer.godaddy.com.

Disclaimer: As I’m frequently updating the original guides and installers here on TeaNazaR.com, I will not be responsible for any brick issues if you were to follow my obsolete guides copied elsewhere. Thus subscribe to this post to get latest updates. Modifying any part of a device may void its warranty.

With this API, I’ve written another simple shell script to perform the DDNS update which can be scheduled with a 5mins repeating Cron job. It should work on any Linux based systems. Why shell script? It’s simple, low-resource and does the update faster than any similar Python, PHP, Perl, Java JIT compiler I’ve tested on the NAS. On each run, the script will check for public IP changes against the local cache and GoDaddy records itself using cURL and only attempt to update if necessary. Even though GoDaddy did not specify the minimum update interval, updating too frequently could affect DNS propagation which could cause delay of the DNS being updated across the internet.

GoDaddy.sh
GoDaddy.sh

First you will need is of course your paid domain name, then a GoDaddy “ProductionAPI key/secret to use with this script. Go to this specific link, log in with your GoDaddy account then generate the API key/secret. Note that the very first time you do this, it will be created as “Test” environment (seen at the time of writing). Go back to the same page again or click on the “Keys” top menu then generate a new “ProductionAPI key/secret instead.

GoDaddy API
GoDaddy API

You can place this script anywhere on your server. I’ll explain more for users who’s not familiar with Linux.

Launch the editor i.e. nano /root/scripts/GoDaddy.sh; . Copy & paste the script source from the bottom of this post into the terminal, update the API key/secret , Domain and other desired options, then CTRL+X to save. Test the script if it’s working:

Once the script is in place, schedule a Cron job every 5mins, crontab -e; , examples below on a single line:

a. No logging (recommended):

b. With logging for debugging purposes (you will need to do your own log housekeeping, try logrorate?):

To update a subdomain (second-level domain i.e. subdomain.domain.com) instead of primary domain (top-level domain i.e. domain.com), set Type=A Type=CNAME (Updated: CNAME by default  can’t point to an IP) and Name=subdomain where subdomain is your subdomain.domain.com as seen in the GoDaddy DNS setup page.

I’ve also added optional advanced variables to include any custom scripts, programs or commands to execute when the IP update occurs or failed. This is so that you can place this script on top of your other applications i.e. those which requires public IP update cached in /tmp/current_ip or those which triggers upon IP changes. Read the script’s comments for more details. For instance, you can use Postfix‘s sendmail to trigger an email notification upon IP update or failures by setting the SuccessExec or FailedExec values. Those who’s using my WebHosting on WDMyCloud V4 Firmwares mods, you can configure its ESMTP to get similar results. For an example to get notified upon successful IP update, set the  SuccessExec value to:

This should be the permanent solution for now until GoDaddy decides to make other changes. Need a Windows based DDNS client updater? Not sure why would anyone leave their PC always awaked, unless it’s a Windows based NAS/server. Perhaps I can help to write a simple Windows executable. But you can always run Cygwin to deploy shell scripts also Ubuntu is already runnable in Windows 10 Insider Preview (at the time of writing). For now, only my NAS running 24/7 needs this. Any questions you can post it here, enjoy (-:

GoDaddy.sh

189 thoughts on “GoDaddy DDNS Updater”

  1. Great work, implemented it yesterday! Not only small, but very intuitive. Thanks!

    You might want to consider removing your API-Key (and Secret!) from the Script, though. 😉

    1. Thanks glad it helps. No worries they (API-Key/Secret) are dummies 😛

      1. I have had i few issues since yesterday. (Ubuntu 16.04)

        Invoking it via cron results in:
        “Checking current ‘Public IP’ from ‘http://api.ipify.org’…Fail! 80.145.94.116”

        When running manually by:
        – ‘/etc/godaddy/ddns_update.sh’: it works like a charm.
        – ‘/bin/sh /etc/godaddy/ddns_update.sh’, it results in “Checking current ‘Public IP’ from ‘http://api.ipify.org’…/etc/godaddy/ddns_update.sh: 73: /etc/godaddy/ddns_update.sh: [[: not found
        Fail! 80.145.94.116”

        Turns out you had a malformed first line:
        #/bin/bash -> #!/bin/bash

        Additionally, I changed
        – ‘/5 * * * * /bin/sh /etc/godaddy/ddns_update.sh>>/var/log/ddns_update.sh.log’ to
        – ‘
        /5 * * * * /etc/godaddy/ddns_update.sh>>/var/log/ddns_update.sh.log’
        in cron.

        Since then the issue didn’t show again and my log is clear:
        “Checking current ‘Public IP’ from ‘http://api.ipify.org’…80.145.94.116!
        Current ‘Public IP’ matches ‘Cached IP’ recorded. No update required!”

        I hope this is helping someone!

        1. Hey there! Thanks a lot for pointing out, didn’t realized the shebang was missing an exclamation mark. I didn’t spot the issue earlier because on my NAS the sh is actually a symlink of bash 🙁 Without the exclamation mark, sh treats the first line like any other comments thus not calling the actual bash interpreter which also caused the ‘not found’ error during bash RegExp. I’ve updated the original script. Also updated the guide to point to bash instead of sh.

  2. Has anyone had any issues like this
    Error: Can’t write to /tmp/current_ip.
    This is on a Centos Server.
    I have this script working on a few Ubuntu 14.04 servers and its going fine.

    1. Hello Ben,

      You need to ensure the /tmp path is writable by the user who’s running the script. The tmp path should have sticky bit set i.e. sudo chmod 1777 /tmp means if a user created a file, another user will not be able to modify or delete it. If you had run this script earlier with another user, then you need to remove the current_ip manually to run as another user.

      You can also change to another path in the script, CachedIP=/tmp/current_ip.

      Edited: You might also wanna check if the touch command exists, /usr/bin/touch.

  3. Thanks for this, it works great! I do have one question and I have tried myself but have had 0 luck. In my A records I have a @ and www record. When I do this it changes the A with no issues. When I add another ‘Name=www’ below the ‘Name=@’ it just will change the www, basically changing only one or the last ‘Name=’ but not both. What do I add to the ‘Name=’ field to get it to change both A records or is there a wildcard that I can put in so that it changes all A records to the IP. FYI – both A fields use the the same IP. Or is it best to create another script and run that www one in the SuccessExec=? If so what would that look like? Hopefully I am making sense, I am some what new.

    1. Hi Zac,

      To simplify the script, I only made it to work with single domain.

      Another reason is that you can simply point the DNS settings CName to the main A host @ to use the same IP as the main A host. E.g. under CNames, set the ‘Alias Name’ to www or * (wildcard refers to any non-listed CNames, i.e. you didn’t setup www2, but www2 will resolve to A host since you used *) and ‘Points To’ to @.

      You could however run multiple instance of this script. Just append any unique alphanumeric characters to both the script name and /tmp/current_ip variable, set the Name variable then schedule a separate cron. Note current_ip cache variable needs to be unique else it won’t trigger the changes.

  4. I have been searching for an answer to my dynamic IP problem for some time and I finally found it in your script. I thought I had a solution using GoDaddy’s DNS updater service app for Windows SBS because it successfully ran on my Win 7 machine. However only one instance of the service could be running at any one time and it could only be configured with one domain…I have 3. I noticed your answer to Zac and realized my problems were solved. I used your script in triplicate (uniquely named) along with 3 unique IP cache and log files. I set up a 30 minute cron for each and rebooted my ADSL router to force an IP change…VOILA! You are the man. Thank you for sharing Nazar!

      1. Everything’s been working great Nazar…I just have a quick query. I’ve set up an email server and to overcome a few hurdles I’ve created another A record (mail) pointing to the same Dynamic IP as my root domain. I’m using a separate script and I’ve left line 28 as Type=A and changed line 31 to the mail.MYDOMAIN.com record I’ve created in my zone file. It appears to be logging into my zone ok, however I receive this terminal error when I test the script. —–>Checking current ‘Public IP’ from ‘http://api.ipify.org’…68.131.250.64!
        Checking ‘mail.MYDOMAIN.net’ IP records from ‘GoDaddy’…changed!
        Updating ‘mail.MYDOMAIN.net’…Fail! {“code”:”UNKNOWN_DOMAIN”,”message”:”The given domain is not registered, or does not have a zone file”,”name”:”_Class”}
        <—–is this something I can fix with a few edits or is it just the nature of how this script works with the GoDaddy API.
        Thank you for your time.

        1. Hello Rudy,

          For your mail subdomain, the line 31 should be only Name=mail (without the root .MYDOMAIN.com).

          1. That was the issue. I had foolishly left the @ on line 31 and actually edited line 24 with the full domain name. Thanks for getting me back on track.

    1. No problem, glad it helps (-: I should have thought about the “touch” command in a non-standard environment paths but you can always do export PATH=$PATH:/new/path prior running any shell scripts.

  5. Well done, buddy! Thanks for sharing!

    I’m going to look into running this as a for loop to account for multiple records.

    1. Hello John,

      No problem glad it helps (-:

      I did thought about the “for loop” (I previously modified the Python ‘pygodaddy’ to do this array loop) but just wanna make it simple this time round. But it’s still possible to update multiple accounts or domain records by running multiple instance of this script without compromising your server resources, do take a look at my previous reply:

      Just append any unique alphanumeric characters to both the script name and /tmp/current_ip variable, set the Name variable then schedule a separate cron. Note current_ip cache variable needs to be unique else it won’t trigger the changes.

    2. Hey John,

      I have a bunch of domains at godaddy I need to update using this script…and they all reside on the same server (using the same dynamic IP). Each of those domains has more than one DNS record that needs to be updated as well…

      Before I start hacking on this (linux shell scripts are really something I work in a lot) I wonder if you already did this? Would you share the code? I think we need two loops…one for each domain and one for each record / hostname to be updated.

      I guess ideally these two things would be in external files so the script itself doesn’t have to be updated when domain names come and go…

      Thanks in advance,

      Charles

  6. Thanks a bunch for this. The old PHP version I was using was always a bane! got this rolling on my FreeNAS box this morning after a power outage (you know, because you always have to update)

Leave a Reply

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

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax