Community discussions

MikroTik App
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

ddns name in firewall nat action ip

Thu Jan 26, 2023 1:36 pm

:global newIP 1.1.1.1
:foreach i in=[/ip firewall nat find comment=TEST] do={
  /ip firewall nat set $i to-addresses=$newIP
}
I am having setup that some mikrotik routers get IP of another router and use it with some firewall rules, but problem is where IP has changed and i must mannualy go to every router and change IP like in the script above.
Its not possible to use ddns name from ip-cloud, so there is another thing i can do? I am having dyndns account and i tried something like this, but its a raw code, never worked :D
:global newIP
:global ddnsServer dyn.com
:global hostname myhostname
:global username myusername
:global password mypassword

:log info "Getting current IP from $ddnsServer"
/tool fetch url="http://members.dyndns.org/nic/update?hostname=$hostname" user=$username password=$password
:set newIP [/tool fetch get value]

:log info "New IP is $newIP"
:foreach i in=[/ip firewall nat find comment=TEST] do={
  /ip firewall nat set $i to-addresses=$newIP
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ddns name in firewall nat action ip  [SOLVED]

Thu Jan 26, 2023 4:17 pm

:foreach i in=[/ip firewall nat find where comment="TEST"] do={
  /ip firewall nat set $i to-addresses=[:resolve "8734562v8374t.sn.mynetname.net"]
}

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], CGGXANNX, jamesperks, sgiglio, tjr and 76 guests