Dynamic DNS Updates on FreeDNS from RouterOS

FreeDNS

FreeDNS (https://freedns.afraid.org/) offers free DNS hosting for up to 5 subdomains. You can set up a domain like example.mooo.com and point it to any IP you want.

I wanted to set up Dynamic DNS updates, so that a certain subdomain would always point to my (potentially changing) home IP. The setup on FreeDNS is quite simple:

  1. Add a new subdomain (Type A) on https://freedns.afraid.org/subdomain/
  2. Go to https://freedns.afraid.org/dynamic/v2/
  3. Select your subdomain and enable Dynamic DNS

Next to your subdomain, a sync URL is automatically generated. It looks like this: http://sync.afraid.org/u/<random-token>/. If you request that URL with an HTTP client, the IP will automatically be updated:

$ curl https://sync.afraid.org/u/<random-token>/
Updated asdfasdfdsdasasdf.chickenkiller.com from 46.38.XX.XX to 213.144.XX.XX

Note that the URL displayed in the FreeDNS web interface is using the insecure http:// protocol by default, you should change that to https:// instead.

Setup on Mikrotik RouterOS

Configuring your Mikrotik router to periodically update the IP is also very simple using the following one-line script:

/system script
    add comment="Update DynamicDNS on freedns.afraid.org" name=dyndns-afraid 
    source="/tool fetch url="https://sync.afraid.org/u/<random-token>/""

Finally, schedule this script to be executed every 5 minutes:

/system scheduler
    add disabled=no start-time=startup interval=5m name=dyndns-afraid 
    on-event="/system script run dyndns-afraid"

(Small sidenote: The RouterOS “fetch” command does not verify the validity of the HTTPS certificate by default. You should probably add the root certificate used by the host to your certificate store and add the check-certificate=yes option to the fetch command.)