สคริปต์ Firewall ป้องกันระบบเต็มรูปแบบ (ROS v7)
เครื่องมือสร้างกฎไฟร์วอลล์ MikroTik RouterOS v7 ขั้นสูง พร้อมปุ่ม Quick-Add กฎทั่วไป จัดลำดับกฎ (Priority Reorder) แบบโต้ตอบ เลือกโหมดโปรไฟล์สำเร็จรูป และคำนวณสคริปต์ RouterOS CLI อัตโนมัติแบบเรียลไทม์
เปิดโหมด Safe Mode (คีย์ลัด [Ctrl] + [X]) บน WinBox ก่อน Paste วางสคริปต์ลงใน New Terminal ทุกครั้ง เพื่อป้องกันการถูกตัดขาดจากเราเตอร์หากคอนฟิกผิดพลาด
โปรไฟล์ความปลอดภัยสำเร็จรูป (Security Presets):
คลิกเพื่อโหลดชุดกฎทันทีปุ่มลัดเพิ่มกฎด่วน (Quick-Add Common Rules):
กดปุ่มเพื่อเพิ่มเข้าลำดับลำดับกฎไฟร์วอลล์ (0 กฎ)
ลำดับกฎมีผลต่อความปลอดภัย (First Match Wins)กำหนดกฎเองเพิ่มเติม (Add Custom Firewall Rule)
# ========================================================
# MikroTik RouterOS v7 - Enterprise Firewall Protection
# Generated by SIAM-LOGIN (https://www.siamlogin.com)
# ========================================================
# WAN Interface: ether1
# LAN Interface: bridge-lan
# Security Level: STANDARD
# ========================================================
# 1. Remove previous rules generated by this template safely (keep existing unrelated rules)
/ip firewall filter
remove [find where dynamic=no and comment~"SIAM-LOGIN"]
/ip firewall raw
remove [find where dynamic=no and comment~"SIAM-LOGIN"]
# ========================================================
# RAW FILTER - Drop attacks before connection tracking
# ========================================================
/ip firewall raw
add chain=prerouting in-interface=ether1 protocol=tcp tcp-flags=syn,!ack action=jump jump-target=syn_flood comment="SIAM-LOGIN: Check SYN Flood"
add chain=syn_flood in-interface=ether1 limit=100,50:packet action=return comment="SIAM-LOGIN: Allow normal SYN rate"
add chain=syn_flood in-interface=ether1 action=drop comment="SIAM-LOGIN: Drop SYN Flood attacks"
add chain=prerouting in-interface=ether1 protocol=tcp tcp-flags=!fin,!syn,!rst,!ack action=drop comment="SIAM-LOGIN: Drop TCP NULL packets"
add chain=prerouting in-interface=ether1 protocol=tcp tcp-flags=fin,syn action=drop comment="SIAM-LOGIN: Drop TCP SYN/FIN packets"
# ========================================================
# CONNECTION TRACKING & FASTTRACK
# ========================================================
/ip firewall filter
add chain=input action=accept connection-state=established,related,untracked comment="SIAM-LOGIN: Accept Established/Related"
add chain=input action=drop connection-state=invalid comment="SIAM-LOGIN: Drop Invalid Connections"
add chain=forward action=fasttrack-connection connection-state=established,related hw-offload=yes comment="SIAM-LOGIN: FastTrack Established/Related"
add chain=forward action=accept connection-state=established,related,untracked comment="SIAM-LOGIN: Forward Established/Related"
add chain=forward action=drop connection-state=invalid comment="SIAM-LOGIN: Drop Invalid Forward"
# ========================================================
# INPUT CHAIN - Protect Router Itself
# ========================================================
# Allow ICMP (Ping)
add chain=input action=accept protocol=icmp comment="SIAM-LOGIN: Accept ICMP Ping"
# Allow Local LAN Access
add chain=input action=accept in-interface=!ether1 comment="SIAM-LOGIN: Allow Internal LAN to Router"
# Allow WinBox (Optional - High Security disables this)
add chain=input action=accept protocol=tcp dst-port=8291 src-address=192.168.0.0/16 comment="SIAM-LOGIN: Allow WinBox from Internal"
# Allow SSH (Optional - High Security disables this)
add chain=input action=accept protocol=tcp dst-port=22 src-address=192.168.0.0/16 comment="SIAM-LOGIN: Allow SSH from Internal"
# Allow WebFig (Optional)
# WebFig disabled in standard mode
# Allow VPN Services (if configured)
add chain=input action=accept protocol=udp dst-port=500,1701,4500 comment="SIAM-LOGIN: Allow L2TP/IPsec"
add chain=input action=accept protocol=ipsec-esp comment="SIAM-LOGIN: Allow ESP"
# Drop All Other Input from WAN
add chain=input action=drop in-interface=ether1 comment="SIAM-LOGIN: Drop All Other WAN Ingress"
# ========================================================
# FORWARD CHAIN - Control Network Traffic
# ========================================================
# Block Bogon IPs from WAN
add chain=forward in-interface=ether1 src-address=0.0.0.0/8 action=drop comment="SIAM-LOGIN: Drop Bogon 0.0.0.0/8"
add chain=forward in-interface=ether1 src-address=10.0.0.0/8 action=drop comment="SIAM-LOGIN: Drop Private 10.0.0.0/8"
add chain=forward in-interface=ether1 src-address=127.0.0.0/8 action=drop comment="SIAM-LOGIN: Drop Loopback 127.0.0.0/8"
add chain=forward in-interface=ether1 src-address=169.254.0.0/16 action=drop comment="SIAM-LOGIN: Drop Link-Local 169.254.0.0/16"
add chain=forward in-interface=ether1 src-address=172.16.0.0/12 action=drop comment="SIAM-LOGIN: Drop Private 172.16.0.0/12"
add chain=forward in-interface=ether1 src-address=192.168.0.0/16 action=drop comment="SIAM-LOGIN: Drop Private 192.168.0.0/16"
add chain=forward in-interface=ether1 src-address=224.0.0.0/4 action=drop comment="SIAM-LOGIN: Drop Multicast 224.0.0.0/4"
add chain=forward in-interface=ether1 src-address=240.0.0.0/4 action=drop comment="SIAM-LOGIN: Drop Reserved 240.0.0.0/4"
# Allow LAN to Internet
add chain=forward action=accept in-interface=bridge-lan out-interface=ether1 comment="SIAM-LOGIN: Allow LAN to Internet"
# ========================================================
# NAT - Internet Sharing
# ========================================================
/ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade comment="SIAM-LOGIN: NAT Masquerade to WAN"
# ========================================================
# SECURITY NOTES
# ========================================================
# Basic: ป้องกันพื้นฐาน เหมาะสำหรับ Home/SOHO
# Standard: มาตรฐานองค์กร เหมาะสำหรับ Office/Branch
# High: ความปลอดภัยสูง บล็อก P2P, ป้องกัน DDoS
# Paranoid: ป้องกันขั้นสูงสุด ปิด WinBox/SSH จากภายนอกทั้งหมด
#
# หลังจากใช้สคริปต์นี้:
# 1. ทดสอบการเชื่อมต่อจาก LAN
# 2. ทดสอบ Ping จากภายนอก (ควรไม่ตอบ)
# 3. ตรวจสอบ Log ด้วย /log print
# 4. ปรับกฎเพิ่มเติมตามความต้องการ
วิธียกเลิก / คำสั่ง Rollback (ลบกฎที่เพิ่งสร้าง)
หากวางสคริปต์แล้วต้องการย้อนกลับการตั้งค่า สามารถรันคำสั่งด้านล่างนี้ใน Terminal:
# คำสั่ง Rollback / ยกเลิกการตั้งค่าสำหรับ สคริปต์ Firewall ป้องกันระบบเต็มรูปแบบ (ROS v7) /ip firewall filter remove [find comment~"SIAM-LOGIN"] /ip firewall raw remove [find comment~"SIAM-LOGIN"] /ip firewall nat remove [find comment~"SIAM-LOGIN"] # หรือหากเปิด Safe Mode ([Ctrl]+[X]) เพียงปิดหน้าต่าง Terminal ตัวเราเตอร์จะยกเลิกคำสั่งอัตโนมัติ
ต้องการทีมวิศวกรดูแลระบบเครือข่าย หรือจัดหาอุปกรณ์ MikroTik ราคาส่ง?
SIAM-LOGIN ให้บริการจัดจำหน่ายอุปกรณ์ MikroTik แท้ศูนย์ไทย พร้อมบริการติดตั้ง วางระบบ WiFi โรงแรม หอพัก และบริการดูแลระบบ (MA) รายปี
เครื่องมือสร้างสคริปต์ MikroTik ที่เกี่ยวข้อง
เครื่องมือช่วยคอนฟิก RouterOS v7 เพิ่มเติมที่จะช่วยให้ระบบ Network ของท่านสมบูรณ์ยิ่งขึ้น
สคริปต์ Smart PCC Load Balance & Recursive Failover (ROS v7)
เครื่องมือสร้างสคริปต์ PCC Load Balance ร่วมกับ Recursive Routing Check Gateway สำหรับ MikroTik RouterOS v7 เช็คการเชื่อมต่อจริงออกอินเทอร์เน็ตผ่าน DNS Target ป้องกันเน็ตค้างและสลับสายได้อย่างแม่นยำ 100%
สคริปต์ VRRP Router Redundancy สำรองเราเตอร์คู่ (High Availability ROS v7)
ตั้งค่าสำรองเราเตอร์คู่ VRRP บน RouterOS v7 สลับการทำงานอัตโนมัติภายใน 1 วินาทีเมื่อเราเตอร์หลักขัดข้อง ใช้ Virtual IP ร่วมกัน
สคริปต์ Watchdog ตรวจสอบเน็ตหลุด รีสตาร์ตเราเตอร์อัตโนมัติ
ตรวจสอบการเชื่อมต่ออินเทอร์เน็ตผ่านคำสั่ง Ping หากไม่สามารถติดต่อ DNS/Gateway ได้ตามจำนวนครั้งที่กำหนด จะสั่งรีบูตเราเตอร์อัตโนมัติ
สคริปต์ป้องกัน Brute-Force โจมตี WinBox / SSH ด้วย 3-Stage Blacklist
ตรวจจับและบันทึก IP ที่พยายามล็อกอิน WinBox พอร์ต 8291 หรือ SSH พอร์ต 22 ผิดติดต่อกัน 3 ครั้ง แล้วขึ้น Blacklist บล็อกการเชื่อมต่ออัตโนมัติเป็นเวลา 24 ชั่วโมง
สคริปต์บล็อก Bogon IP & Reserved IP Addresses ป้องกันทราฟฟิกปลอมจากภายนอก
บล็อก IP Address ขาเข้าจากภายนอกที่ไม่ควรปรากฏบน Public Internet (Martian IPs & Private IPs 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8) ป้องกัน IP Spoofing
สคริปต์ตรวจจับและบล็อกการสแกนพอร์ต (PSD - Port Scan Detection)
ตรวจจับผู้ไม่หวังดีหรือบอทที่พยายามสแกนเปิดพอร์ต (Port Scan) บนเราเตอร์ แล้วเพิ่ม IP เข้าสู่ Blacklist ทันที