Sysnet Board คู่มือ การใช้งานอุปกรณ์ Network

การ Config อุปกรณ์ เครือข่าย Network Device => อุปกรณ์ Mikrotik Router => หัวข้อที่ตั้งโดย: yod เมื่อ วันที่ 20 ธันวาคม 2010, 22:08:36

ชื่อ: การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 20 ธันวาคม 2010, 22:08:36

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



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

2. เข้า Menu System --> Script

(https://www.sysnetcenter.com/board/images/routerboard/dynamic-dns/routeros-dyndns-001.gif)


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


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

# 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

# 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

(https://www.sysnetcenter.com/board/images/routerboard/dynamic-dns/routeros-dyndns-002.gif)

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


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

(https://www.sysnetcenter.com/board/images/routerboard/dynamic-dns/routeros-dyndns-003.gif)


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

(https://www.sysnetcenter.com/board/images/routerboard/dynamic-dns/routeros-dyndns-004.gif)

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

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

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

(https://www.sysnetcenter.com/board/images/routerboard/dynamic-dns/routeros-dyndns-005.gif)



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

การ Config NTP Client เพื่ออ้างอิงเวลาสากล stratum 0 (https://www.sysnetcenter.com/board/index.php/topic,423.0/)




เรียบร้อยครับ  ;D


ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 5 สิงหาคม 2013, 11:13:58
คุณ yod


     หากผมต้องการใช้กับ dvr ต้องทำส่วนไหนเพิ่มอีกครับ
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 5 สิงหาคม 2013, 12:25:13


Forward port ครับ dvr ส่วนใหญ่ จะต้องใช้ 2 port นะครับ ตรวจสอบที่อุปกรณ์ dvr จากนั้นทำการ config forward port ที่ routerboard ครับ
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 5 สิงหาคม 2013, 13:34:53
คุณ yod

    ผม Forward port แล้วครับ สามารถดูผ่านวงแลนเดียวกันได้โดยเข้าที่ ip ของ dvr แต่ไม่สามารถดูผ่าน host (dyndns) ได้ครับ
รบกวนขอวิธีด้วยครับ
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 5 สิงหาคม 2013, 14:06:21


ตัวอย่างการทำ forward port ครับ

https://www.sysnetcenter.com/board/index.php/topic,997.0/ (https://www.sysnetcenter.com/board/index.php/topic,997.0/)

ในตัวอย่างจะเป็นกล้อง ip camera จะใช้แค่ port เดียว โดยผม config ที่ตัวกล้องเป็น port 9000 ถ้า dvr ส่วนใหญ่จะใช้ 2 port ครับ ให้ตรวจสอบหมายเลขที่หน้า config อุปกรณ์ หรือสอบถามกับทางร้านที่ซื้อครับ ว่าต้อง config port ยังไง

ทดสอบการทำ dynamic dns ด้วยการ connect routerboard โดยผ่านทาง winbox ใส่ค่า hosy ที่สร้างไว้ตรงช่อง connect ถ้า config สำเร็จจะต้องเข้า winbox ได้ครับ ที่เหลือก็จะเป็นการ forward port
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 5 สิงหาคม 2013, 14:35:39
ผมทดสอบการทำ dynamic dns ด้วยการ connect routerboard โดยผ่านทาง winbox ใส่ค่า hosy ที่สร้างไว้เข้า winbox ได้ครับ

และก็ทำการ การทำ Port Forward ของผม DVR ใช้ port 37777 (tcp) กับ 37778 (udp) ทำตามที่คุณยอดส่งมาให้ทุกขั้นตอน

ก็ไม่ได้ครับ

(https://www.sysnetcenter.com/board/upload/files/images/mr1rp2-wireless-676bfe.png)

(https://www.sysnetcenter.com/board/upload/files/images/mr1rpn-wireless-e09b22.png)


ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 5 สิงหาคม 2013, 15:00:26


ต้องทำ 4 ครั้ง TCP,UDP 3777 และ TCP,UDP 37778
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 5 สิงหาคม 2013, 15:03:05
ถ้าทำถูกต้องจะเข้าหน้า login ของกล้องได้ครับ จากรูปจะเป็น DVR ของ HiView ครับ


(https://www.sysnetcenter.com/board/upload/files/images/mr1t0u-wireless-d7ed8f.jpg)
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 5 สิงหาคม 2013, 16:43:16
ไม่ผ่านครับ ยังดูไม่ได้เลย  :'(
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 5 สิงหาคม 2013, 17:41:12


ถ้า config dynamic dns แล้ว login เข้าหน้า config router ได้ ก็ตัดในส่วน dynamic dns ได้เลยครับ

ทีนี้ ลองตรวจสอบ port ของ dvr ครับ ถ้าเป็น dvr ของ HiView (ใช้ที่บ้าน) จะมี 2 Port ไว้ดู Port นึง ผมตั้งวไ้ที่ 10001 และ Remote อีก Port 1 ผมตั้งไว้ที่ 6060 ต้องสร้าง firewall ขึ้นมา 4 ชุดครับ ค่ือ TCP: 10001, UDP: 10001, TCP:6060 และ UDP:6060 ครับ

แต่ที่ผมเจอคือดูผ่าน Internet Explorer ไม่ได้ครับ ผมเลยต้องเปลี่ยนเป็น Firefox
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 7 สิงหาคม 2013, 14:06:04
ผมรบกวนคุณ yod ตรวจสอบครับว่าผิดตรงไหนรึเปล่า

(https://www.sysnetcenter.com/board/upload/files/images/mr5fox-wireless-9446f6.png)


(https://www.sysnetcenter.com/board/upload/files/images/mr5fpm-wireless-63a268.png)
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 7 สิงหาคม 2013, 16:56:23
ลองเปลี่ยน HTTP Port เป็น Port 9000 ครับ

ผม remote เข้าไป add port 9000, 554 ให้แล้วครับ


อุปกรณ์ dvr รุ่นนี้ทางผมยังไม่เคย set ครับ
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 8 สิงหาคม 2013, 10:04:44



ไม่ได้เหมือนเดิมครับ
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: njtd เมื่อ วันที่ 12 สิงหาคม 2013, 01:12:22
น่าจะเป็นปัญหาของ NAT Loopback หรือเปล่าครับ
ถ้าอยู่ในวงเดียวกันจะเข้าผ่าน Dyndns ไม่ได้ แต่ถ้าอยู่วงอื่นจะเข้าได้ไม่มีปัญหา
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: iamwiroj เมื่อ วันที่ 13 สิงหาคม 2013, 16:35:57
คนละวงก็ไม่ได้ครับ

ทำเอาผมงงมาก

ชื่อ: Re: การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org
โดย: artty เมื่อ วันที่ 5 มีนาคม 2014, 06:50:19
คุณยอด

   ผมต้องการทำ VPN  จาก OFFICE ถึง Site ผมอ่านวิธีที่คุณยอดแล้วทำตามทั้งหมด แต่ติดต้องนี้ครับ IP ที่ได้จะตรงกับ DynDns แต่ที่ Address มันไม่ตรงเพราะอะไรครับ ทำให้ผม VPN เข้าไม่ได้ครับ 3 วัน แล้วยังไม่ได้เลยครับ


(https://www.sysnetcenter.com/board/upload/files/images/n1xrgk-wireless-11ab21.jpg)


(https://www.sysnetcenter.com/board/upload/files/images/n1xre3-wireless-04c38c.jpg)
ชื่อ: Re: การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org
โดย: yod เมื่อ วันที่ 6 มีนาคม 2014, 13:37:48


ลองตั้งเวลาใน schedule ซัก 3 นาทีครับ แล้วปิด/เปิด router ดูใหม่ ช่วงเวลาที่ส่ง update ไป กับเวลา ณ.ปัจจุบันอาจจะไม่ตรงกัน
ชื่อ: Re: การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org
โดย: mobilesuit เมื่อ วันที่ 25 มีนาคม 2014, 13:32:25
พี่ยอดครับ ทำไมเวลาผม copy โค๊ดลงใน New Terminal แล้วมันขึ้นคำว่า stem ตัวสีแดงล่ะครับ (/system stem scheduler...)

ใช้โค๊ดนี้อ่ะครับ /system scheduler add name=dynDNS interval=00:01 on-event="/system script run dynDns\r\n"

ถ้ากด Enter ก็จะขึ้น error
ถ้าลบ stem ออก แล้วกด Enter ก็ไม่มีอะไรเกิดขึ้นครับ
ชื่อ: Re: การ Set Dynanic DNS บน RouterOS โดยใช้ Service DynDNS.org
โดย: somlith1988 เมื่อ วันที่ 23 เมษายน 2015, 15:12:31


ผมมีปัณหาแบบนี้ละท่าน พอมีวิธื แก้ไขไหม

ดูกล้องวงเดื่ยวกันผ่าน Dyndns ไม่ได้ แต่ถ้า ใช้วงอื่นจะดูได้
ชื่อ: Re: การ Set Dynanic DNS บน Mikrotik โดยใช้ Service DynDNS.org
โดย: kenro1997 เมื่อ วันที่ 18 พฤษภาคม 2015, 19:59:23
1. ถ้าเป็นเวอร์ชั่น 6 ขึ้นไปใช้อันไหนครับ พอดีผมไม่ได้ใช้กับกล้อง แต่ใช้กับเครื่องแสกนนิ้วพนักงานเก็บข้อมูลลงServer แล้วต้องออนไลน์ผ่านเน็ทได้ เปิดพอร์ทแล้ว ดูผ่านวงแลนด์ได้แล้ว ทางบริษัทที่ขายมาบอกให้ทำแบบเดียวกับกล้องวงจรปิดตือ เปิดพอร์ท ใส่Host dyndns
2. Mikrotix รุ่น 750G ใช้นเป็น hotspot ด้วยครับ เน็ทเส้นเดียว ทำยังไงให้ออกเป็น Hotsport 1 port อีก 3 port เป็น landport เหมือน AP ทั่วไป

ขอบคุณล่วงหน้าเลยครับ
วีรศักดิ์ ทับทองดี

Users found this pages searching for: