Case Study - Defending against DDoS attacks, improving DNS management, and enhancing web redirects

Dynamic DNS configuration with MikroTik

Using Dynamic DNS with MikroTik routers allows businesses and home users to quickly and easily access their networks from anywhere in the world. Unfortunately, setting up a Dynamic DNS service on MikroTik routers can be complex. Still, once configured correctly, it provides fast and reliable access to internal systems without having to remember constantly changing IP addresses.

Pre-configuration requirements

Open the DNS zone which you want to connect with Dynamic URL. Find the A or AAAA record which you would like to be updated dynamically and click on the arrows on the row for this record. Afterwards, you have to Activate the Dynamic URL in the pop-up. Once you do it, you will see example scripts, used for record update. In this setup, you will need the first one, which looks like this:

https://ipv4.cloudns.net/api/dynamicURL/?q=your-string-here
or
https://ipv6.cloudns.net/api/dynamicURL/?q=your-string-here

Configuration using Winbox

In order to configure Dynamic URL in MikroTik RouterOS using Winbox, you have to follow the steps below:

1. Connect to your MikroTik RouterOS

2. Select System and click on Scheduler

3. Click on Add

4. Type in a name for your scheduled task

5. Make sure Start Time is set to startup

6. Set the Interval. We recommend to set it at 1 hour

7. In the text box On Event enter the following task:

/tool fetch url="https://ipv4.cloudns.net/api/dynamicURL/\?q=your-string-here" mode=https

8. Click on OK

Note: The following "policy" boxes must be checked:

  • ftp
  • read
  • policy
  • password
  • sensitive
  • reboot
  • write
  • test
  • sniff
  • romon

Configuration for multiple interfaces

To configure Dynamic URL in MikroTik RouterOS for multiple interfaces, you need to add a cron job that runs the following script:

## Get Current selected WAN Interface IP and send ClouDNS update if changed
from last check
##
## Select which WAN Interface to check
:global wanIf "wan2"
## Pull global variable value into script
:global wanIP "$wanIP"
## Get the current IP on the interface
:local nowIPmask [/ip address get [find interface="$wanIf" disabled=no]
address];
## IP without netmask
:local nowIP [:pick $nowIPmask 0 ([:len $nowIPmask]-3)];
## Check if IP has changed and update ClouDNS if it has
:if ($nowIP != $wanIP) do={
/log info "wan ip changed from $wanIP to $nowIP"
## Set the global $wanIP variable with the new IP address
:set wanIP $nowIP
## Execute ClouDNS DDNS Update Script with updated $wanIP
/tool fetch url="
https://ipv4.cloudns.net/api/dynamicURL/?q=your-dynamic-ip-string-here&ip=$wanIP"
mode=https
}

Configuration using console

If you prefer to use the RouterOS's console, you have to create a task at the Scheduler. To do it, please enter the following command:

/ system scheduler add name="cloudns" on-event="/tool fetch url=\"https://ipv4.cloudns.net/api/dynamicURL/\?q=your-string-here\" mode=https" start-date=jan/01/1970 start-time=startup interval=1h comment="" disabled=no

Note: The date above is an example. You can use any other date, but make sure it is not later, than the current day.


Last modified: 2024-02-09
Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more