Community discussions

MikroTik App
 
candrian
just joined
Topic Author
Posts: 1
Joined: Sun Apr 05, 2020 1:47 pm

DynDNS Script from Mikrotik Wiki (correction)

Sun Apr 05, 2020 1:58 pm

Hi all,

I'm new to Mikrotik. I just bought the HAP AC2 and i'm on the configuration period. I have set this router as the main router of my home network which also connects to the internet via PPPoE through the ISP modem. I have also set up Pi-Hole as the local DNS. While i was trying to find a script for updating my DynDNS domain i found in the official wiki a page with a script for this purpose. https://wiki.mikrotik.com/wiki/Dynamic_ ... _No-IP_DNS. I tried the script several times with no success but after some debugging i noticed that firstly, the router couldn't resolve the domain (http://dynupdate.no-ip.com/) so i found out that the user must have set a DNS IP address under IP->DNS->Servers (maybe this must only be set up in the case you are using a local DNS as i do) and the second one was that the $previousIP variable in the script it seemed that on each run didn't have the previous value. So i noticed here that the suggested permissions write, test, read wasn't enough for the global variable to be set. So i granted policy permissions also and now everything works.

If the $previousIP is not set then on each run the script will send an ip update request to the DynDNS server even when the ip has not be changed (this is only noticeable though the logs. Otherwise the user is not affected)

So these two are suggestions if you are interested to be added in your official wiki page.

Thanks,
Haris
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1930
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: DynDNS Script from Mikrotik Wiki (correction)

Mon Apr 06, 2020 12:12 pm

You can use MikroTik Colud DNS, its free. Then you can point your dyndns to the MikroTiok clod DNS name. (if its possible)
Or drop dyndns and only use Mikrotik Cloud DNS as your public DNS name.

IP->Cloud [x] DDNS Enable.
Then you should get a fixed DNS name like this:

PublicIP: 65.232.13.123 (your outside IP)
DNS Name: 6f3806exxxxx.sn.mynetname.net (Serial number your router + .sn.mynetname.net)
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
aceror
just joined
Posts: 3
Joined: Sat Apr 11, 2020 12:23 pm

Re: DynDNS Script from Mikrotik Wiki (correction)

Sat Apr 11, 2020 1:44 pm

Hello
Make script call DynDns and paste this

# Set needed variables
:local username "YOURUSERNAME"
:local password "YOURPASSWORD"
:local hostname "YOURHOSTNAME.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
dst-path="/dyndns.txt"
:delay 1
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}

then run this in command
/system scheduler
add interval=1m name=DynDns on-event=DynDns policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1930
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: DynDNS Script from Mikrotik Wiki (correction)

Sun Apr 12, 2020 12:32 pm

Thanks for the script.
Use code tags. Select text and click the </> button.

Like this: (with tabs as well)
# Set needed variables
	:local username "YOURUSERNAME"
	:local password "YOURPASSWORD"
	:local hostname "YOURHOSTNAME.dyndns.org"

	:global dyndnsForce
	:global previousIP

# print some debug info
	:log info ("UpdateDynDNS: username = $username")
	:log info ("UpdateDynDNS: password = $password")
	:log info ("UpdateDynDNS: hostname = $hostname")
	:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
	/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
	:delay 1
	:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
	:local resultLen [:len $result]
	:local startLoc [:find $result ": " -1]
	:set startLoc ($startLoc + 2)
	:local endLoc [:find $result "</body>" -1]
	:local currentIP [:pick $result $startLoc $endLoc]
	:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

	:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
		:set dyndnsForce false
		:set previousIP $currentIP
		:log info "$currentIP or $previousIP"
		/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
		src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
		dst-path="/dyndns.txt"
		:delay 1
		:local result [/file get dyndns.txt contents]
		:log info ("UpdateDynDNS: Dyndns update needed")
		:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
		:put ("Dyndns Update Result: ".$result)
	} else={
		:log info ("UpdateDynDNS: No dyndns update needed")
	}
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
tuxedo21
just joined
Posts: 1
Joined: Sat Feb 20, 2021 4:56 pm

Re: DynDNS Script from Mikrotik Wiki (correction)

Sat Feb 20, 2021 5:57 pm

hi I am new here, I got software routeros 4.86.1 and in my IP section, I did not see "IP cloud" feature in the list , I like to use my dynamic service with dyndns, can anyone can help me to get this feature back to IP section ?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1930
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: DynDNS Script from Mikrotik Wiki (correction)

Tue Feb 23, 2021 11:19 am

I guess, you have 6.48.1 and Cloud should be there.

In Winbox (3.27) it looks like this:
cloud.jpg
cloud.jpg
You do not have the required permissions to view the files attached to this post.
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
texmeshtexas
newbie
Posts: 48
Joined: Sat Oct 11, 2008 11:17 pm

Re: DynDNS Script from Mikrotik Wiki (correction)

Tue Mar 02, 2021 7:09 am

I noticed that if I changed the IP in my dyndns.org account. This script would not correct it.
To fix that, I made these changes.

:local dyndnsForce
:local previousIP [resolve $hostname]

Now the script truly compares the routes current IP with that resolved by $hostname

Who is online

Users browsing this forum: Jotne, Lajci and 20 guests