Dynamic DNS for Synology NAS with Digital Ocean

I have some services sitting in Digital Ocean on virtual machines, and some sitting at home on my NAS. Using Digital Ocean as my main DNS provider allows me to conveniently manage this mixed cloud and home environment. All of my services can sit seamlessly as subdomains on one main domain for my home.

By default, Synology Disk Station does not come with an out of the box method for using Digital Ocean as a DDNS provider, but with a little effort, you can get this working. For the method that I am using, we will not be using the default DDNS manager inside the Disk Station UI. This method utilizes a scheduled task to achieve the same result.

Before starting, you’ll need to make sure that the DNS for your website is actually managed on Digital Ocean. I don’t show how to do that here, but Digital Ocean has some great documentation that explains exactly how to do that.

Create a folder on your Synology NAS where your scripts will live

I like to use a folder called “scripts” directly at the root of the volume.

Download the Digital Ocean DDNS Script

https://github.com/bensquire/Digital-Ocean-Dynamic-DNS-Updater/blob/master/updater.py

Save the contents of this script to a text file on your local computer. I called mine dns_updater.py. Upload the file to your scripts directory on the NAS.

Obtain a Digital Ocean API key

First we need to create an API key that has permissions to modify your Digital Ocean resources. This API key should be treated like a password. Keep it safe!

Log into to your Digital Ocean account and click on the API button on the left navigation.

On the Applications & API page under the “Tokens/Keys” tab, click on the “Generate New Token” button.

Choose a name that makes sense for your new token. I named mine “Synology NAS”. Make sure that your token has both “Read” and “Write” scopes.

Digital ocean tokens are scoped read-only by default. Make sure that you select the “write” scope for this token.

Copy your newly-created token and save it to a text file. I named mine do_token.txt.

Upload your do_token.txt to the scripts folder we created earlier on your NAS.

Create a Shell Script Containing the Domain Update Configuration

I named my script digital_ocean_ddns.sh.

Since this is a bash script, line 1 should be #!/bin/bash

After this, we’ll use python3 (should already be installed) to launch the dns_updater.py script for each hostname we want to point back home.

As you can see from the screen shot above, for each hostname we’re running the Python script. Let’s breakdown one of the lines.

python3 /volume1/scripts/dns_updater.py -t `cat /volume1/scripts/do_token.txt` @ paultrotter.com

  • python3 – the python interpreter running the script (this should already be installed by default on Disk Station)
  • /volume1/scripts/dns_updater.py – the actual DNS updater script that we copied earlier.
  • -t `cat /volume1/scripts/do_token.txt` – this prints out your API token to be ingested by the dns_updater.py script.
  • @ – the hostname you wish to update. This could be any valid hostname. For example, I’m using nas and project1 on subsequent lines. Use @ if you want to update the IP of your domain name without a subdomain.
  • paultrotter.com – my domain–change this to your domain!
  • A or AAAA – as of writing, the dns_updater.py script only supports these two types of records.

Important! For each hostname that you create, you’ll want to have already defined this hostname in your Digital Ocean control panel. The dns_updater.py script only updates IP addresses for each hostname. It will not create new hostname entries.

Set up a Scheduled Task to Trigger Your Script

Now that we have specified all of the domains that we would like to have automatically updated in our digital_ocean_ddns.sh script, we’ll need to set up a scheduled task to actually launch it.

The Task Scheduler can be found in the Control Panel under the Services section of your Synology Disk Station.

Control Panel -> Services -> Task Scheduler

Create a new User Defined Script Scheduled Task.

Click the Create button -> Scheduled Task -> User-defined script

Under the “General Settings” tab, enter a name for your script. I called mine Digital Ocean DDNS. Also, make sure that you’re running this script as the root user.

Select the name and the user for this task.

Click the schedule tab and create a schedule for your script. I have mine running hourly.

Example of running task daily with a frequency of every hour.

Click on the “Task Settings” tab and enter the final details.

If you’d like to be notified every time the task runs, you can check the “Send run details by email” box and enter your email address. Please note, this requires email sending to be set up properly on your Synology NAS.

For the user-defined script blank, enter the path of the script with your hostname configuration. I am using: bash /volume1/scripts/digital_ocean_ddns.sh

Testing the Script

Once the script has been created and scheduled, test your script by clicking the instance in the Task Scheduler, then clicking “Run”.

One of the easiest ways to test this is to change the IP address of one of your host names in Digital Ocean to a random address. Then run the script and see if the IP address of the host changes to the correct address.

Leave a Comment