As many of you know, DynDNS will cease to have free dynamic DNS services within a month’s time.
As a result, I will be using one of the alternative free services instead - DuckDNS ( https://duckdns.org/ ) , and thought I’d share my script.
This script runs differently to almost all other Mikrotik dynamic DNS update scripts I have found on the Net. The usual method is to have the script run at intervals. Whereas my script runs all the time, monitors the WAN connection, and detects if the IP address changes. Not saying this is a better way, it is just the way I have done it.
So therefore, when setting it up in the Mikrotik scheduler, set it to run at startup only.
All you need to change in the script below is the “exampledomain” and the token.
Hope it’s handy for someone.
Nev
/ interface pppoe-client {
:global ExternalIP
:local clientip
:local clientstatus
:while (1 < 2) do={
monitor pppoe-out1 once do={:set clientip $“local-address”; :set clientstatus $status}
:if ($clientstatus=“connected” and $ExternalIP!=$clientip) do={
:delay 1
:log info “UpdateDuckDNS: IP change detected - $ExternalIP to $clientip. Updating Duck DNS.”
/tool fetch mode=https url=“https://www.duckdns.org/update?domains=exampledomain&token=a7c4d0ad-114e-40ef-ba1d-d217904a50f2&ip=$clientip” dst-path=duckdns.txt;
:delay 1
:local result [/file get duckdns.txt contents]
:log info “UpdateDuckDNS: Duck DNS update result: $result”;
:set ExternalIP $clientip
}
:delay 5
}
}
Do not help anyone to make and grow free service, when you have debugged “all the problem” and the program is near vital to you, the program end Free support, on 30 days… or 7 days only…
Very ransom example…
There are also many service like this two on the years…
Do not base your works on free product,
not be blind on Open source project. Not all bug discovered, because free code, are reported…
7 days I agree is too soon to allow users to transition, but if the service is “vital”, then it is probably worth paying for. Just remember that what they are providing does cost them money.
40 machines? If you are saying there are 40 different hostnames then you are violating the DynDNS free account terms anyway. You are only permitted to have 1 free account, and each account only allows 1 or 2 hostnames I believe.
On the follow sript replace MATRIX with ethernet interface or bridge (probably obtaining IP by DHCP client) you want to use as source IP for DuckDNS.
Obtain the ip of ethernet interface, the second instruction remove /xx if present:
:global actualIP value=[/ip address get [find where interface=MATRIX] value-name=address];
:global actualIP value=[:pick $actualIP -1 [:find $actualIP "/" -1] ];
Read if the previous IP is different from the actual. IT ALSO REMEMBER THE IP BETWEEN REBOOTS.
First part check for file existance, the last line set previousIP variables. The delay are inserted to do time to system to write the file.
:if ([:len [/file find where name=ipstore.txt]] < 1 ) do={
/file print file=ipstore.txt where name=ipstore.txt;
/delay delay-time=2;
/file set ipstore.txt contents="0.0.0.0";
};
:global previousIP value=[/file get [find where name=ipstore.txt ] value-name=contents];
If previous IP are different to new, update DuckDNS, and save permanently new value on files to mantain the info througt reboot:
@rextended
The script works only when executed from the MikroTik terminal for me.
It does not work if I click on “run” form the script menu or if I run it via the scheduler. It throws: “could not run script DuckDNS: not enough permissions”. i tried giving all permissions to the script, but I still get the same error. I create and run the script with the same user that I use to execute the script via terminal.
To reproduce this:
Delete the “actualIP”, “lastChange” and “previousIP” global variables from System->Scripts->Environment
Delete the “ipstore.txt” and “duckdns-result.txt” files
Run the script from System->Scripts->Scripts (select and click “run script”)
Any ideas what might be the problem?
As said, I am running as the same user with all permissions granted. I run routeros-mmips v6.44
Hi - when I try to use this, it appears that there is another private address between the my Mikrotik router and the internet. So it returns a private address. Any other way I can do this?
You are right. Maybe its not a private address. Basically my Fibre modem goes into ether1. When I set it using that script, the ip address is different than what I see if I use something like https://whatismyipaddress.com/.
Script gives me 172.22.###.###
Whatismyipaddress gives me a 103.252.###.### number
It pretty much looks like a private address - 172.22/16 is within 172.16/12 which is a private range.
And since the initial script is pulling the address from the interface, I’m sure you have a private address and your ISP is NATing your address.
-Chris
this is my script and works for me.
:global currentIP;
local newIP [ip cloud get public-address];
:if ($newIP != $currentIP) do={
:log info “IP address $currentIP changed to $newIP”;
:set currentIP $newIP;
/tool fetch mode=https url=“https://www.duckdns.org/update?domains=domain&token=xxxx-xxx-xx-xx-xxx=$newIP” dst-path=duckdns.txt;
:local result [/file get duckdns.txt contents];
:log info “Duck DNS update result: $result”;
}
This is the key line “local newIP [ip cloud get public-address];”
But the first “ip cloud” shoud be set, on newer MT versions. This also works if you have multiple IPs on WAN interfaces.
I had various issues with the update scripts found in this thread. You can find my version of the script below. Instead of caching the IP address, this script resolves the domain name and updates it if it is different from the actual address of the interface.
:local resolvedIP [:resolve "{{ domain }}.duckdns.org"];
:local currentIP [/ip address get [find interface="{{ interface }}"] address];
:local currentIP [:pick $currentIP 0 [:find $currentIP "/"]];
:if ($resolvedIP != $currentIP) do={
:log info ("Trying to update DuckDNS with actual IP ".$currentIP.", resolved IP is ".$resolvedIP);
:local response [/tool fetch url=("https://www.duckdns.org/update?domains={{ domain }}&token={{ token }}&ip=".$currentIP) check-certificate=yes as-value output=user];
:if ($response->"status" = "finished") do={
:if ($response->"data" = "OK") do={
:log info ("Successfully updated DuckDNS with new IP ".$currentIP);
} else={
:log error ("Failed to update DuckDNS with new IP ".$currentIP);
}
}
}
In order to use the script, you’ll have to do the following:
replace the variables in double curly braces
make the root certificate used to sign DuckDNS’s certificate chain available in the certificate store either by downloading it from here or using Mozilla’s list of trusted root certificates from here. The certfile should be downloaded on a trusted computer and uploaded to the router from there. It can be imported in Winbox under System > Certificates or using the