#MikrotikTips - Dynamic DNS Update Script for dynDNS on Mikrotik

1
2756
Halaman:
Sertakan sumber dengan jelas jika ingin mencopy. Selalu cek tanggal, karena mungkin ada beberapa artikel lama yang belum disesuaikan dengan fakta terbaru

Dynamic DNS Update Script for dynDNS on Mikrotik

Informasi Umum

Router : Mikrotik Level 5

IP Publik : Dinamis




Tujuan : Digunakan untuk merubah IP dynDNS setiap IP Publik yang didapat berubah. (Biasa dipakai untuk forward IP Lokal)

Berikut langkahnya :

  1. Buat script berikut :

# Define User Variables
:global ddnsuser "DYNDNSUSER"
:global ddnspass "DYNDNSPASS"
:global ddnshost "DYNDNSHOST"

# 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=0.0.0.0/0 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&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
    /tool fetch address=members.dyndns.org 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
  }
}
  1. Tambahkan schedule agar script di atas di eksekusi setiap menit
/system scheduler add name=dynDNS interval=00:01 on-event="/system script run dynDnsrn"
  1. Sampai disini konfigurasi sudah selesai.
  2. Diambil dari Mikrotik Wiki
Artikel Terkait :  Forward FTP Server Behind NAT

 

Dynamic DNS Update Script for dynDNS on Mikrotik. Dynamic DNS Update Script for dynDNS on Mikrotik. Dynamic DNS Update Script for dynDNS on Mikrotik

1 COMMENT

Jangan lupa tinggalkan komentar ya gais

This site uses Akismet to reduce spam. Learn how your comment data is processed.