การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org

การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org

1. Login โดย Winbox เข้า RouterOS ครับ

2. เข้า Menu System –> Script

3. นำ Code ข้างล่างแปะลงใน Script โดยตั้งชื่อเป็น dynDns (ตัวใหญ่-เล็ก มีผลนะครับ) ครับ

สำหรับ Router OS Version 5.xx

โค๊ด: [Select] # Set needed variables
:local username “username”
:local password “password”
:local hostname “hostname”

: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.org” 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
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

: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.org” \
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”)
}

สำหรับ Router OS Version 4.xx

โค๊ด: [Select] # Set needed variables
:local username “username”
:local password “password”
:local hostname “hostname”

:global dyndnsForce
:global previousIP

# print some debug info
#:log info (“dyndns-update: username = $username”)
#:log info (“dyndns-update: password = $password”)
#:log info (“dyndns-update: hostname = $hostname”)
#:log info (“dyndns-update: previousIP = $previousIP”)

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address=”checkip.dyndns.org” 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 “dyndns-update: currentIP = $currentIP”

# 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=”members.dyndns.org” src-path=”/nic/update?hostname=$hostname&myip=$currentIP” dst-path=”/dyndns.txt”
:local result [/file get dyndns.txt contents] :log info (“dyndns-update: Dyndns update needed”)
:log info (“dyndns-update: Dyndns Update Result: “.$result)
:put (“Dyndns Update Result: “.$result)
} else={
:log info (“dyndns-update: No dyndns update needed”)
}

จากนั้นแก้ไข Code ในส่วนนี้ครับ
:local username “username”
:local password “password”
:local hostname “hostname”

username –> UserName ที่สมัครใน DynDNS.org
password –> Password ที่สมัครใน DynDNS.org
hostname –> ชื่อ Host ที่ตั้งไว้ใน DynDNS.org

แล้ว Click [Run Script] แล้ว Click [OK]

4. ตรวจสอบ IP ฝั่งขา WAN ที่ IP –> Address

5. Login เข้า Web DynDNS.org ตรวจสอบ IP ที่ทาง Server ของ DynDNS ตรวจจับได้

ถ้าตรงกันแสดงว่าสำเร็จเรียบร้อยครับ

6. ที่ Winbox ให้ Click เลือก Menu New Terminal ให้ทำการ Copy Script ด้านล่างนี้แปะลงไปใน Terminal แล้วเคาะ Enter ครับ จะเป็นการสั่งให้ RouterOS ทำการ Run Script จากข้อ 3 ทุกๆ 1 นาที ถ้า IP ขา WAN ไม่ตรงกับค่าเดิม ถึงจะทำการส่งข้อมูลไป Update ที่ DynDNS ครับ

โค๊ด: [Select] /system scheduler add name=dynDNS interval=00:01 on-event=”/system script run dynDns\r\n”

ปล.อย่าลืม Update เวลาใน Router ด้วยนะครับ ไม่งั้น Script Update DNS จะไม่ run ต่อเนื่องครับ


ทิ้งคำตอบไว้

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