Home computer programming, mikrotik noip ddns and mikrotik script
computer programmingmikrotik

noip ddns and mikrotik script

if you have mikrotik on your place and your ISP not allowing static ip public, you still connect the no-ip ddns using this script below

why we do need this script? if your ISP not allowing using static ip public, your internet ip public will change everytime the ISP services restart

#Script created and modified by ronny
#22 dec 2020, 20:21
#this script is detecting your current ip public address and auto setup to your no-ip account

#your previous IP public
:global previousIP
#:set previousIP "!23"
#your noip credential
:local noipuser "your noip user"
:local noippass "your noip password"
:local noiphost "your noip host"
:local cctvip "192.168.25.120"

#your internet/wan interface
:local inetinterface "your wan interface"

#get your current IP Public and remove the /subnet
:local currentIP [/ip address get [find interface=$inetinterface disabled=no] address]
:for i from=( [:len $currentIP] - 1) to=0 do={
       :if ( [:pick $currentIP $i] = "/") do={
           :set currentIP [:pick $currentIP 0 $i]
       }
   }
#:log info $currentIP 

#if prev IP is different than current, then set the no-ip new ip
:if ($previousIP != $currentIP ) do={ 
        :log info "$previousIP is different to $currentIP, updating" 
        :local url "http://$noipuser:$noippass@dynupdate.no-ip.com/nic/update?hostname=$noiphost&myip=$currentIP"
        /tool fetch url=($url)
        :set previousIP $currentIP
#updating cctv ippublic too
        :log info "updating cctv"
        /ip firewall nat add chain=dstnat dst-address=$currentIP protocol=6 dst-port=8014 action=dst-nat to-addresses=$cctvip to-port=8014
        /ip firewall nat add chain=srcnat dst-address=$cctvip protocol=6 dst-port=8014 out-interface=$inetinterface action=src-nat to-addresses=$currentIP to-ports=8014
        :log info "updating done"		
    } else={ 
        :log info "no need to change the ip" 
}

 

resources:

  • https://www.noip.com/integrate/add-noip

Author

Ronny

Leave a Reply

EnglishIndonesian