Mikrotik X
Industrial DNS - DNS Dinamico Professionale - Dispositivi Supportati - Mikrotik

Configurazione dispositivi Mikrotik

La configurazione di dispositivi Mikrotik può essere effettuata in due varianti:

  • Mikrotik con checkipConfigurazione di Industrial DNS classica con verifica del cambio dell’IP su servizio esterno. Non genera aggiornamenti illeciti.
  • Mikrotik senza checkip: Configurazione di Industrial DNS su Mikrotik quando l’IP pubblico è assegnato direttamente alla porta esterna e non cambia. Da chiamarsi una sola volta.

Mikrotik con checkip

# Set needed variables
:local username "dyndns.it username"
:local password "dyndns.it password"
:local hostname "your_hostname.homepc.it"

:global dyndnsForce
:global previousIP

# print some debug info 
:log info ("UpdateDynDNS: username = $username")
: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.it" src-path="/" dst-path="/dyndns.checkip.html"
: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 available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="update.dyndns.it"
    src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :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")

Lo script deve essere eseguito dallo scheduler una volta al minuto per verificare il cambio IP.

/system scheduler add name=dynDNSit interval=00:01 on-event="/system script run dynDnsIT\r\n"

Mikrotik senza checkip

# Define User Variables
:global ddnsuser "DYNDNSITUSER"
:global ddnspass "DYNDNSITPASS"
:global ddnshost "DYNDNSITHOST.homepc.it"

# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }

:global ddnsinterface
:global ddnssystem ("mt-" . [/system package get system version] )

# Define Local Variables
:local int

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address= active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]

# Grab the current IP address on that interface.
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
    :log info "DynDNS: Sending UPDATE!"
    :local str "/nic/update?hostname=$ddnshost&myip=$ddnsip"
    /tool fetch address=update.dyndns.it src-path=$str mode=http user=$ddnsuser \
        password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ddnslastip $ddnsip