04 March, 2012

gratisdns.sh - A GratisDNS.dk DDNSd module for Synology DSM

So I own a Synology DiskStation as well as various domains, and wanted a bit of automation for updating my own dynamic domain name. To that end I hacked this script together, which adds GratisDNS (a free DNS hosting company based in Denmark) as an option to the DDNS Controlpanel in the DiskStation Manager (DSM).

The script comes with no support and no guarantees that it will even work for you. I do however try my best to fix issues brought to my attention.


  1. Rasmus Trock Kinnerup05 March, 2012 00:28

    And how do you get this script into the DSM?

  2. Well. If you don't know, then I don't know if I would recommend messing with the configuration files on the DSM. I can't guarantee that my script won't do something NASty, like make some important service go all wonky, or even just blowing up :-) In essence, I take no responsibility for any misdeeds my script might do on your NAS.

    Getting the file there would be pretty easy, since it's a NAS, right? :-) Just open notepad. Copy the script content into notepad, then save it as "gratisdns.sh" (without the "quotes", obviously). Copy that file to some share on your NAS. Then you just SSH to your NAS and copy/move the file to the location specified in the Description section of the script.

  3. Thanks for the script. It looks like it works perfectly.
    Don't forget to chmod +x the script.

    chmod +x /sbin/gratisdns.sh <- it makes the file executable.
    I also had to change this line:




    Before I changed that, I kept getting an error from gratisdns, that the user didn't have permission to update the domain, or something like that.

    I'm using DSM 4.1 Beta.

  4. Of course, chmod the script. I never do that, because it's already eXecutable when transferring from a Windows computer over SMB :) But good point none the less :)

    Regarding the change of the __URL__ string, have you checked the /var/log/gratisdns_ddnsd.log file as to why?

    I have an idea as to why it might be failing (only guessing here), and that might be if you're using second-level subdomain (ie.: sub2.sub1.domain.tld).

    The __DOMAIN__ variable is merely the __HOSTNAME__ split into parts, delimited by a period/dot (.), and then returning the 2nd and 3rd delimiters. If it's a second-level subdomain, then it will of course be incorrect, because that would return "sub1.domain", with no tld.

    IF that is the case, then it should be enough to change the following line:
    __DOMAIN__="$(echo ${__HOSTNAME__} | cut -d. -f2-3)"

    To this instead:
    __DOMAIN__="$(echo ${__HOSTNAME__} | cut -d. -f2-)"

  5. Erik Bundgaard Poulsen19 December, 2012 23:44

    Just a tip after some time of frustration on my side:
    Make sure to save the gratisdns.sh file with UNIX style end-of-line characters. This can easily be achieved in for instance Notepad++ with the menu point "Edit"->"EOL Conversion"->"UNIX Format".

  6. Thanks for the tip. As you've probably gathered from the comments in the script, I also use Notepad++ :) For good measure I've updated the comments in the script, so it also includes this information.