วันอังคารที่ 26 ธันวาคม พ.ศ. 2560

DNS Caching

DNS  Caching ให้ Client มา Request ขอใช้ DNS  ได้สักพัก
เมนู IP > DNS > Allow Remote Requests คือการเปิดใช้งาน DNS Caching Server เพื่อบริการ DNS กับเครื่องลูกข่าย
แต่ถ้าไม่กำหนด firewall อะไรเลย ก็เป็นการให้บริการกับคนทั้งโลก!!!  โอ… บริการของเรา ระดับโลกจริงๆ นะฮัฟฟ์ฟ์
หลังจากใช้งานไปสักพัก ก็เริ่มรู้สึกประหลาดใจกับ DNS Cache หน้าตาแปลกๆ 0.0.0.0  เอ… ที่ไหนก็ได้ เอ๊ะ.. กลิ่นชักไม่ดีแล้ว
ทดสอบ ลอง solve dns ด้วย real ip ของ Mikrotik ปรากฎว่า ทำได้??
การทดสอบง่ายๆ ใช้คำสั่ง
nslookup imhofocus.com real-ip-mikrotik
ตัวอย่าง
root@pollhsp2:~# nslookup www.imhofocus.com 11.22.33.44
Server:         11.22.33.44
Address:        11.22.33.44#53
Non-authoritative answer:
Name:   www.imhofocus.com
Address: 27.254.35.142
อื้ม… Mikrotik ที่ใช้ทำหน้าที่เป็น Gateway ของเรา เป็นผู้ให้บริการ Free DNS Cache ระดับโลกไปซะแล้ว
เปิดการป้องกัน!!!
เปิด New terminal แล้ววางสคริปต์นี้ลงไป ก่อนที่จะเอาไปใช้งานกัน ให้ก๊อปปี้คำสั่งลงใน Notepad แล้วแก้ไข in-interface ให้เป็น interface ที่ใช้ออกเน็ตนะครับ ถ้าเป็น pppoe-client ก็แก้ไขชื่อตามให้เรียบร้อย ก่อนที่จะวางคำสั่งลงไป
#ป้องกันการขอใช้ DNS Caching จากภายนอก อย่าลืมแก้ไข Interface ที่ใช้ต่อ internet ล่ะ
/ip firewall filter
add chain=input in-interface=ether11 protocol=udp dst-port=53 action=drop
add chain=input in-interface=ether11 protocol=tcp dst-port=53 action=drop
#ป้องกันการโดนทำ DHCP Relay จากภายนอก จัดไป
/ip firewall filter
add chain=forward protocol=udp dst-port=53 out-interface=!ether11 action=drop
add chain=forward protocol=tcp dst-port=53 out-interface=!ether11 action=drop
#ป้องกันเครื่องลูก กำหนด ip dns เอง ซึ่งจะมีผลทำให้บางคนไม่ได้หน้า login hotspot ในกรณีกำหนด splash screen แบบ domain name
/ip firewall nat
add chain=dstnat protocol=udp dst-port=53 in-interface=!ether11 action=redirect
add chain=dstnat protocol=tcp dst-port=53 in-interface=!ether11 action=redirect
ทดสอบซ้ำอีกที
root@pollhsp2:~# nslookup www.imhofocus.com 11.22.33.44
;; connection timed out; no servers could be reached
สำเร็จ เราป้องกัน Gateway ของเรา ออกจากการให้บริการระดับโลกได้สำเร็จ  จบครับ 😀
** ข้อควรระวัง การทดสอบการ solve dns ควรใช้เครื่องที่อยู่ภายนอกเน็ตเวิร์กที่จะทดสอบ เพื่อป้องกันการสับสนของผู้ทดสอบเอง **
Credit
http://forum.mikrotik.com/viewtopic.php?f=2&t=69677

ไม่มีความคิดเห็น:

แสดงความคิดเห็น