
Firewall Rules: หลักการเขียน ACL และ Firewall Policy ที่ถูกต้อง
Firewall Rules เป็นแนวป้องกันหลักของ network security กำหนดว่า traffic ไหนผ่านได้ traffic ไหนถูก block การเขียน firewall rules ที่ดีต้องเป็นระบบ มีหลักการ ไม่ใช่แค่เพิ่ม rules ไปเรื่อยๆ จนกลายเป็น “rule mess” ที่ไม่มีใครกล้าแก้ไข
องค์กรหลายแห่งมี firewall rules หลายพันข้อ ที่สะสมมาหลายปี ไม่มีใครรู้ว่า rule ไหนยังจำเป็น rule ไหนซ้ำซ้อน rule ไหนผิด นี่คือปัญหาที่ทำให้เกิดช่องโหว่ด้าน security บทความนี้จะอธิบายหลักการเขียน firewall rules ที่ถูกต้อง ตั้งแต่การออกแบบ policy ไปจนถึง best practices
หลักการพื้นฐาน
Default Deny
Default Deny (Whitelist approach): block ทุกอย่างก่อน แล้ว allow เฉพาะ traffic ที่จำเป็น ดีกว่า Default Allow (Blacklist approach) ที่ allow ทุกอย่างแล้ว block เฉพาะที่ไม่ต้องการ เพราะ default deny ปลอดภัยกว่า ถ้าลืม rule ก็ถูก block (ปลอดภัย) ในขณะที่ default allow ถ้าลืม rule ก็ผ่านได้ (ไม่ปลอดภัย)
Principle of Least Privilege
Allow เฉพาะที่จำเป็น อย่า allow กว้างเกินไป ตัวอย่าง: ผิด: allow any → web_server (any port) ถูก: allow 10.0.30.0/24 → web_server port 443 only กำหนด source, destination, port, protocol ให้เฉพาะเจาะจงที่สุด
โครงสร้าง Firewall Rule
| Field | คำอธิบาย | ตัวอย่าง |
|---|---|---|
| Rule Number/Priority | ลำดับที่ firewall ตรวจสอบ (บนลงล่าง) | 100, 200, 300 |
| Source | IP/subnet/zone ต้นทาง | 10.0.30.0/24, Staff_VLAN |
| Destination | IP/subnet/zone ปลายทาง | 10.0.20.10, Web_Server |
| Service/Port | Protocol และ port ที่อนุญาต | TCP/443 (HTTPS), TCP/22 (SSH) |
| Action | Allow หรือ Deny | Allow, Deny, Drop |
| Logging | บันทึก log หรือไม่ | Log, No Log |
| Comment | คำอธิบาย rule | “Allow staff to web server HTTPS” |
Rule Order สำคัญ
Top-Down Processing
Firewall ตรวจสอบ rules จากบนลงล่าง เมื่อ match rule แรก จะ execute action แล้วหยุด (ไม่ตรวจ rules ถัดไป) ดังนั้น: specific rules ต้องอยู่ก่อน general rules deny rules สำหรับ specific threats อยู่ก่อน allow rules ตัวอย่าง: Rule 1: Deny malicious_IP → any (block specific threat) Rule 2: Allow staff → web_server port 443 (specific allow) Rule 3: Allow staff → DNS_server port 53 (specific allow) Rule 999: Deny any → any (default deny)
Firewall Zone Design
| Zone | Trust Level | ตัวอย่างอุปกรณ์ |
|---|---|---|
| Inside (Trust) | สูง | Staff PCs, internal servers |
| DMZ | กลาง | Web servers, mail servers, DNS |
| Outside (Untrust) | ต่ำ | Internet |
| Guest | ต่ำ | Guest WiFi |
| Management | สูงสุด | Network equipment management |
Inter-Zone Traffic Rules
Inside → DMZ: Allow specific services (web, email) Inside → Outside: Allow web, email (ผ่าน proxy ดีกว่า) Outside → DMZ: Allow specific services (HTTP/HTTPS to web server) Outside → Inside: Deny all (ยกเว้น VPN, established connections) DMZ → Inside: Deny all (ยกเว้น specific DB connections) Guest → Outside: Allow web only Guest → Inside/DMZ: Deny all
ACL บน Cisco Router/Switch
Standard ACL vs Extended ACL
| ประเภท | Filter ตาม | Number Range | วาง ACL |
|---|---|---|---|
| Standard ACL | Source IP เท่านั้น | 1-99, 1300-1999 | ใกล้ destination |
| Extended ACL | Source, Dest, Port, Protocol | 100-199, 2000-2699 | ใกล้ source |
| Named ACL | เหมือน Extended แต่ใช้ชื่อ | ชื่อที่กำหนด | ใกล้ source |
Best Practices
1. Document ทุก Rule
ทุก rule ต้องมี comment อธิบายว่า rule นี้ทำอะไร ใครขอ เมื่อไหร่ ticket number อะไร ถ้า rule ไม่มี comment ไม่มีใครกล้าลบ เพราะไม่รู้ว่าลบแล้วจะพังอะไร
2. ใช้ Object Groups
สร้าง groups สำหรับ IP addresses, networks, services แทนที่จะมี rules ซ้ำๆ สำหรับแต่ละ IP ตัวอย่าง: สร้าง group “Web_Servers” = {10.0.20.10, 10.0.20.11, 10.0.20.12} สร้าง group “Web_Services” = {TCP/80, TCP/443} rule: allow Staff → Web_Servers : Web_Services เมื่อเพิ่ม web server ใหม่ แค่เพิ่ม IP ใน group ไม่ต้องเพิ่ม rule
3. Review Rules เป็นประจำ
ทุก 6 เดือน review firewall rules ลบ rules ที่ไม่จำเป็นแล้ว (servers ที่ decommission, users ที่ออก) ใช้ rule hit count ดูว่า rule ไหนไม่เคยถูกใช้ (0 hits) อาจลบได้ ลด rule clutter ทำให้ firewall performance ดีขึ้นและ security ดีขึ้น
4. Log Deny Rules
เปิด logging สำหรับ deny rules (อย่างน้อย default deny rule สุดท้าย) เพื่อเห็นว่า traffic อะไรถูก block ช่วยในการ troubleshooting (users บอกเข้า X ไม่ได้ → ดู firewall log → เห็น deny → เพิ่ม allow rule)
5. Change Management
ทุกการเปลี่ยนแปลง firewall rules ต้องผ่าน change management มี change request, approval, implementation, verification, documentation อย่าแก้ firewall rules โดยไม่บันทึก เพราะถ้ามีปัญหาจะ rollback ไม่ได้
ทิ้งท้าย: Firewall ดีแค่ไหนก็ขึ้นกับ Rules
Firewall ราคาแพงแค่ไหนก็ไม่มีประโยชน์ถ้า rules เขียนไม่ดี เริ่มจาก default deny, least privilege, document ทุก rule, review เป็นประจำ ใช้ object groups ลดความซับซ้อน ทำ change management ทุกครั้ง
อ่านเพิ่มเติมเกี่ยวกับ Network Segmentation และ Zero Trust Network ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com