DEV Community

Cover image for Access your Synology NAS with a custom domain on Bunny.net (DDNS)
Steeve
Steeve

Posted on • Edited on

Access your Synology NAS with a custom domain on Bunny.net (DDNS)

This article is born because Bunny.net does not support Dynamic DNS (for the moment?), I contacted the support but I received a negative result:

I wanted to migrate all my domain from OVH/Cloudflare to Bunny, because their DNS performances are on the top chart (they are the best?), it's free, the UI/UX of the admin panel is clean, and MOST OF ALL: They got rabbits EVERYWHERE.

However there is a big problem: to access my Synology NAS through a custom domain name, DDNS is required because:

  • My internet provider changes IP everytime the Internet Box restarts, so I have to notify my DNS provider of the new IP!
  • My internet provider doesn't give fixed IPV4 for free (to be honest I won't pay).

After experimenting, I created a Node script executed regularly on my NAS that:

  • Fetch the current public IPv4 of the NAS from public IP APIs (several are tried, with retries, in case one is down).
  • Read the A Record value directly from the Bunny DNS API and compare it with the current IP: if the IP is different, the record is updated with the new IP!
  • Repeat this process 5 minutes later: compare again, etc...

The script is fully stateless: nothing is written on disk, the source of truth is always the DNS record itself.

Bunny Setup

First, make sure you have loaded your domain on your Bunny admin interface, if not, here is the setup link:
https://dash.bunny.net/dns/zones/add

Create a A Record and set the public IP of your Synology NAS. If the IP is not correct, it will be corrected with the Node Script on the next section:

In my case, I have a subdomain photos.domain.com pointing to my Synology NAS. The Value column shows the IP you entered (in my case I prefer to keep it private :D).

Finally on your Bunny account, get you API key, it will be use to update the IP of your A Record:
https://dash.bunny.net/account/settings

Synology Setup

Synology NAS can run Node (install Node.js v18 or later from the Package Center if needed, the script relies on the built-in fetch), so I decided to create a Node Script instead of a Bash script, copy the following file to the directory of your choice. Personnally, I copied to /volume1/homes/admin/ddns-bunny.js:

https://github.com/steevepay/ddns-bunny-synology/blob/main/ddns-bunny.js

Let's create a new Task executing the Script regularly, like every 5 minutes (each run makes an API call to Bunny to read the record, so every minute is more aggressive than needed).

  1. Open the Control Panel application > Click on Task Scheduler
  2. On the bar, click on Create > Schedule Task > User Defined Script
  3. Name the new Task like DDNS Bunny and select a User, like the admin.
  4. Now select the second tab Schedule: Ensure the Run on the following day is selected, and set at Daily.
  5. On the second tab Schedule: Set the start time at midnight, and check Continue running the same day. Set the Repeat into to 5 minutes and Last Run Time to 23h55.
  6. Now select the third tab Task Settings, and add to the "User Defined Script"the following command: BUNNY_ACCESS_KEY="" NAS_URL="photos.domain.com" DDNS_SOFT_FAIL=1 node /volume1/homes/admin/ddns-bunny.js. The command must written in one single line, otherwise the API KEY and the URL won't be retrieved by the script. Write your Bunny API key under the first double quotes for the environment variable BUNNY_ACCESS_KEY. Then write the domain of your NAS between the second double quotes for the env NAS_URL, without https://. Finally the command execute the Script with Node. The optional DDNS_SOFT_FAIL=1 makes the script exit successfully when your internet connection is temporarily down, so you won't receive an "Interrupted" email on every WAN hiccup, you only get emails for real errors.
  7. To verify if the script is working, enable the option "Send Run details by emails" and provide your email.
  8. Save the new task, then wait five minute, to verify if everything went fine:
    • Check the email you received: it should print OK {YOUR PUBLIC IP}. If something went wrong, it should print an error message detailing the issue.
    • Visit your custom domain: Your Synology panel should load
    • Verify the IP: open your Bunny DNS panel, you should see the public IP of your NAS
    • If you didn't received email: You probably didn't configure right your NAS to send emails.
    • Optional, make the script lighter: on its first successful update, the script prints the Bunny zone and record IDs. Add them to the command as BUNNY_DNS_ZONE_ID="..." BUNNY_DNS_RECORD_ID="..." to skip the zone lookup on every run.

Known limitations

  • The script updates only one domain per scheduled task: to update several domains, create one task per domain with a different NAS_URL.
  • Only IPv4 (A records) is supported: the script deliberately ignores IPv6, because Bunny A records only accept IPv4 and dual-stack ISPs would otherwise publish the wrong address.

Conclusion

Now Bunny.net supports DDNS by simply requesting their DNS API, and I can migrate all my domains to Bunny, youhouuu 🐰🎉

Top comments (3)

Collapse
 
steeve profile image
Steeve • Edited

To create this article, I passed:

  • 3h Experimenting with my Synology NAS and the Bunny API, and writing the Node DDNS Script two times.
  • 1h30 writing: Find the article structure, writing, and prepare examples.
  • 15 minute: Find a perfect image for the banner, I used Adobe Firefly with the following prompt: "A scientist astronaute bunny conduct experiments with different flavors of carrot juice, there is multiple carrot-powered rocket and a leaf umbrella in the background. Inside of a spaceship with neons, windows all around and behind with a view on planet earth and other planets, carrots are floating due to gravity, the stars are reflecting on windows."
Collapse
 
neurabot profile image
Neurabot

Excellent.

Collapse
 
steeve profile image
Steeve

Important Tips for people who want to use Bunny DNS servers with OVHCloud as a domain register:

I had a DNS propagation issue; I was not able to reach my servers for a week. After a lot of investigation, I contacted the Bunny support, and we found the issue.

On the OVHCloud admin panel, make sure you have:

  • Disabled DNSSEC: The "DNSSEC" is enabled by default on all domain on OVHCloud, that's a security option I didn't notice and never heard about. I just turned the option off, and it says it would take 24 hours to be fully disabled. (screenshot 1)
  • Deleted all DS records: Even if you disable DNSSEC, DS records are not deleted automatically. It contain a hash of a DNSKEY record, which helps verify the authenticity of DNS responses, which are expected to be OVH. However, I want to use Bunny as DNS. Just delete those dam annoying records. (screenshot 2)

Ten minutes later, the problem was solved: I can now access my server with my domains powered by Bunny DNS.

OVHCloud DNSSEC option

OVHCloud DS Record Tab