MIKROTIK DDNS – DYNAMIC PUBLIC IP
In this tutorial, we will cover how to resolve your dynamic public IP with a third-level domain DDNS for free on your Mikrotik router.
How often does your provider give you a dynamic public IP and not provide a free DDNS service?
No problem! In the following paragraphs, we will see how to solve this problem without purchasing any paid services. We will analyze two possible solutions, a proprietary system, and Duck DNS.
Let’s proceed to configure the DDNS with Mikrotik.
Required components:
- Any Mikrotik router
- A working internet connection
- A PC with Winbox
- Difficulty level: Easy
Let’s assume we have a network like the following diagram:

We will analyze two possible methods to configure our DDNS:
Objective 1: Use the proprietary Mikrotik DDNS.
Our fantastic Mikrotik router, on all available hardware models, offers a proprietary platform on which a unique, non-customizable, but free third-level domain is generated. Let’s see how to configure it:
- Open Winbox and connect to your router.
- Click on the IP tab, Cloud.
- A window will appear to configure the cloud service.
- Check the DDNS Enabled field.
- In the DDNS Update Interval field, enter 00:00:01.
- Click the Apply button.
- The DNS Name field will appear.
- The DNS Name field indicates our DDNS.
- By calling the DDNS mentioned on the web, we will be directed to our dynamic public IP. You should see a screen similar to figure 2.

Objective 2: Use Duckdns.
For those who do not know, Duck DNS is a third-party service that offers the possibility to obtain some third-level domains that will point to our dynamic public IP.
First, register or login to the website: DUCKDNS.
fig.3 – Logged in to DuckDNS
After logging in, you will see a screen similar to figure 3.

Let’s follow the steps below to create a domain:
- In the subdomain field, enter a name of your choice (e.g., mariored).
- Click add domain.
- You should see a notification like “success: domain mariored.duckdns.org added to your account” as shown in figure 4. Also, the current IP field will appear in the lower right corner, which I have obscured for security reasons.

Now that the domain is created, connect to our Mikrotik router with Winbox and follow these steps:
- Click on the System tab, Script, and then on the + button.
- In the name field, type duck-script
- Check the Don’t Require Permissions field
- In the Source window, at the bottom, enter the following script, taking care to replace the green fields with those present on your DuckDNS page:
#----------SCRIPT INFORMATION------------------ # # Script: DuckDNS.org Dynamic DNS Update Script # Created: 29/12/2022 # Author: Fabio Fois # Website: foisfabio.it # #----------MODIFY THIS SECTION AS NEEDED-------- # DuckDNS Sub Domain :local duckdnsSubDomain "mariored.duckdns.org" # DuckDNS Token :local duckdnsToken "63cd6662-e190-4e47-adcd-51d6e694494a" # Set true if you want to use IPv6 :local ipv6mode false; # Online services which respond with your IPv4, two for redundancy :local ipDetectService1 "https://api.ipify.org/" :local ipDetectService2 "https://api4.my-ip.io/ip.txt" # Online services which respond with your IPv6, two for redundancy :local ipv6DetectService1 "https://api64.ipify.org" :local ipv6DetectService2 "https://api6.my-ip.io/ip.txt" #---------------------------------------------------- :local previousIP; :local currentIP # DuckDNS Full Domain (FQDN) :local duckdnsFullDomain "$duckdnsSubDomain.duckdns.org" #:log warning message="START: DuckDNS.org DDNS Update" if ($ipv6mode = true) do={ :set ipDetectService1 $ipv6DetectService1; :set ipDetectService2 $ipv6DetectService2; :log error "DuckDNS: ipv6 mode enabled" } # Resolve current DuckDNS subdomain ip address :do {:set previousIP [:resolve $duckdnsFullDomain]} on-error={ :log warning "DuckDNS: Could not resolve dns name $duckdnsFullDomain" }; # Detect our public IP adress useing special services :do {:set currentIP ([/tool fetch url=$ipDetectService1 output=user as-value]->"data")} on-error={ :log error "DuckDNS: Service does not work: $ipDetectService1" #Second try in case the first one is failed :do {:set currentIP ([/tool fetch url=$ipDetectService2 output=user as-value]->"data")} on-error={ :log error "DuckDNS: Service does not work: $ipDetectService2" }; }; :log info "DuckDNS: DNS IP ($previousIP), current internet IP ($currentIP)" :if ($currentIP != $previousIP) do={ :log info "DuckDNS: Current IP $currentIP is not equal to previous IP, update needed" :log info "DuckDNS: Sending update for $duckdnsFullDomain" :local duckRequestUrl "https://www.duckdns.org/update\?domains=$duckdnsSubDomain&token=$duckdnsToken&ip=$currentIP&verbose=true" :log info "DuckDNS: using GET request: $duckRequestUrl" :local duckResponse :do {:set duckResponse ([/tool fetch url=$duckRequestUrl output=user as-value]->"data")} on-error={ :log error "DuckDNS: could not send GET request to the DuckDNS server. Going to try again in a while." :delay 5m; :do {:set duckResponse ([/tool fetch url=$duckRequestUrl output=user as-value]->"data")} on-error={ :log error "DuckDNS: could not send GET request to the DuckDNS server for the second time." :error "DuckDNS: bye!" } } # Checking server's answer :if ([:pick $duckResponse 0 2] = "OK") do={ :log info "DuckDNS: New IP address ($currentIP) for domain $duckdnsFullDomain has been successfully set!" } else={ :log warning "DuckDNS: There is an error occurred during IP address update, server did not answer with \"OK\" response!" } :log info "DuckDNS: server answer is: $duckResponse" } else={ :log info "DuckDNS: Previous IP ($previousIP) is equal to current IP ($currentIP), no need to update" } #:log warning message="END: DuckDNS.org DDNS Update finished"
After clicking the Apply button, the script will be operational. It will appear as in figure 5.

Now let’s see how to schedule the script to run continuously:
- Click on the System tab, Scheduler, and then on the + button.
- In the name field, enter duck-schedule.
- In the Interval field, enter 00:01:00.
- In the On Event window, type duck-script.
- Finally, click Apply.
In this way, the Mikrotik router will connect to your DuckDNS account and synchronize your dynamic IP with your domain.

Thanks to Foisfabio.it for providing the content for this blog post. His expertise and knowledge have made it possible for us to share this valuable tutorial with our readers. We appreciate Fabio Fois contribution to the tech community!
Lascia un commento