تنظیم سرویس DDNS بر روی محصولات میکروتیک

با اجرای این دستورات روتر بورد میکروتیک وظیفه بروز کردن آی پی اینترنتی شما را بر عهده دارد.

تنظیم DDNS روی میکروتیک


برای تنظیم روتر های میکروتیک و استفاده از سرویس Daynamic DNS باید پس از دریافت اکانت از سایت dyndns.ir روتر خود را به صورت زیر تنظیم کرد.
  • به منوی system scripts مراجعه کرده و با توجه به ورژن سیستم عامل میکروتیک خود یک اسکریپت جدید ایجاد کنید و کد های زیر را در آن قرار دهید

  • OS Ver 4.x.x

    # Set needed variables
    :local username "YourUsername"
    :local password "YourPassword"
    :local hostname "nohostset"
    
    
    :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.ir" 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
    
    :if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
        :set dyndnsForce false
        :set previousIP $currentIP
        /tool fetch user=$username password=$password mode=http address="members.dyndns.ir" \
           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")
    }
    
    
    

    OS Ver 5.x.x

    # Set needed variables
    :local username "YOURUSER"
    :local password "YOURPASWORD"
    :local hostname "YOURHOSTNAME.dyndns.ir"
    
    :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.ir" 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
    
    
    :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.ir" \
          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")
    }                         
    
    						 

    OS Ver 6.x.x

    :global ddnsuser "USERNAME"
    :global ddnspass "PASSWORD"
    :global theinterface "INTERFACE"
    :global ddnshost ddns.dyndns.ir
    :global ipddns [:resolve $ddnshost];
    :global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
    :if ([ :typeof $ipfresh ] = nil ) do={
       :log info ("DynDNS: No ip address on $theinterface .")
    } else={
       :for i from=( [:len $ipfresh] - 1) to=0 do={ 
          :if ( [:pick $ipfresh $i] = "/") do={ 
        :set ipfresh [:pick $ipfresh 0 $i];
          } 
    }
     
    :if ($ipddns != $ipfresh) do={
        :log info ("DynDNS: IP-DynDNS = $ipddns")
        :log info ("DynDNS: IP-Fresh = $ipfresh")
       :log info "DynDNS: Update IP needed, Sending UPDATE...!"
       :global str "/nic/update?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
       /tool fetch address=members.dyndns.ir src-path=$str mode=http user=$ddnsuser \
             password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
        :delay 1
        :global str [/file find name="DynDNS.$ddnshost"];
        /file remove $str
        :global ipddns $ipfresh
      :log info "DynDNS: IP updated to $ipfresh!"
        } else={
         :log info "DynDNS: dont need changes";
        }
    } 
                             
    
    						 
  • حال برای اجرای اسکریپت بصورت زمان بندی شده یک رول اضافه میکنیم:
  • /system scheduler add name=dynDNS interval=00:01 on-event="/system script run dynDns\r\n"