คำตอบสรุป: ขีดจำกัดกฎ NSG ใน Azure
| ประเภทขีดจำกัด | ค่าเริ่มต้น (Default) | ขีดจำกัดสูงสุด (Max Limit) | วิธีเพิ่ม |
|---|---|---|---|
| กฎต่อ NSG หนึ่งกลุ่ม (Rules per NSG) | 200 กฎ | 1,000 กฎ | เปิด Support Request (Ticket) ไปที่ Azure Support |
| NSG ต่อ Subscription ต่อ Region | 5,000 NSG | ไม่ระบุ (ขึ้นกับโควต้า) | ขอเพิ่มโควต้าผ่าน Support Request |
| NSG ที่ผูกกับ Subnet เดียว | 1 NSG | 1 NSG | ไม่สามารถเพิ่มได้ (1 Subnet = 1 NSG) |
| NSG ที่ผูกกับ NIC เดียว | 1 NSG | 1 NSG | ไม่สามารถเพิ่มได้ (1 NIC = 1 NSG) |
NSG (Network Security Group) คืออะไร?
Network Security Group (NSG) เป็นไฟร์วอลล์ระดับเครือข่ายใน Azure ใช้ควบคุมการจราจรเข้า-ออก (Inbound/Outbound) ไปยังทรัพยากร Azure เช่น Virtual Machines, Subnets, Network Interfaces
โครงสร้างกฎ NSG (Security Rule)
แต่ละกฎประกอบด้วย:
- Name - ชื่อกฎ (ไม่ซ้ำใน NSG เดียวกัน)
- Priority - ลำดับความสำคัญ (100-4096, ต่ำกว่า = สำคัญกว่า)
- Source / Destination - IP CIDR, Service Tag, Application Security Group
- Source Port / Destination Port - พอร์ตหรือช่วงพอร์ต (เช่น 80, 443, 1000-2000)
- Protocol - TCP, UDP, ICMP, ESP, AH, หรือ * (ทั้งหมด)
- Action - Allow (อนุญาต) หรือ Deny (ปฏิเสธ)
- Direction - Inbound (เข้า) หรือ Outbound (ออก)
กฎเริ่มต้นของ NSG (Default Rules)
Inbound (เข้า)
- AllowVNetInBound (Priority 65000) - อนุญาตจราจรภายใน VNet เดียวกัน
- AllowAzureLoadBalancerInBound (Priority 65001) - อนุญาต Health Probe ของ Azure Load Balancer
- DenyAllInBound (Priority 65500) - ปฏิเสธทั้งหมดที่ไม่ตรงกฎข้างบน
Outbound (ออก)
- AllowVnetOutBound (Priority 65000) - อนุญาตออกไป VNet เดียวกัน
- AllowInternetOutBound (Priority 65001) - อนุญาตออกสู่อินเทอร์เน็ต
- DenyAllOutBound (Priority 65500) - ปฏิเสธทั้งหมดที่ไม่ตรงกฎข้างบน
หมายเหตุ: กฎเริ่มต้นไม่สามารถลบได้ แต่สามารถเขียนกฎใหม่ Priority ต่ำกว่า (เช่น 100-1000) เพื่อ Override ได้
NSG vs Azure Firewall
| คุณสมบัติ | NSG | Azure Firewall |
|---|---|---|
| Layer (OSI) | Layer 3 (Network) + Layer 4 (Transport) | Layer 3, 4, 7 (Application) |
| Stateful Inspection | ใช่ (พื้นฐาน) | ใช่ (ขั้นสูง) |
| Application Rule (FQDN, HTTP/HTTPS) | ไม่มี | มี |
| Threat Intelligence | ไม่มี | มี (Built-in) |
| SNAT / DNAT | ไม่มี | มี |
| ราคา | ฟรี (จ่ายค่า NSG rules limit) | จ่ายตามชั่วโมง + ข้อมูลที่ประมวลผล |
| เหมาะสำหรับ | ควบคุมพอร์ต/IP พื้นฐาน | Enterprise, App-layer filtering, Centralized logging |
Best Practices การใช้ NSG
- ผูก NSG ที่ Subnet ระดับแรก (Management, Web, App, DB Subnet แยกกัน)
- ใช้ Application Security Groups (ASG) แทนการระบุ IP เฉพาะ - จัดกลุ่ม VM ตามบทบาท
- Service Tags ใช้แทน IP Range ของ Azure Services (เช่น AzureCloud, Storage, Sql)
- Priority ให้ห่างกัน (100, 200, 300...) เพื่อแทรกกฎใหม่ง่าย
- Document ทุกกฎ ใน Description field
- Monitor ด้วย NSG Flow Logs ส่งไป Log Analytics / Event Hub
- Review กฎทุกไตรมาส ลบกฎไม่ใช้, รวมกฎซ้ำ
การสร้าง NSG ใน Azure Portal
- Azure Portal > Create a resource
- ค้นหา Network Security Group > Create
- Subscription, Resource Group, Region, Name
- Create > รอ Deploy สำเร็จ
- เข้า NSG > Inbound/Outbound security rules > Add
- ผูกกับ Subnet: Subnets > + Associate
ข้อจำกัดเพิ่มเติมที่ควรทราบ
- Priority Range: 100 - 4096 (สำหรับกฎผู้ใช้), 65000+ (สำหรับกฎเริ่มต้น)
- ไม่สามารถมี Priority ซ้ำ ใน Direction เดียวกัน (Inbound/Outbound แยกกัน)
- กฎถูกประมวลผลตาม Priority ต่ำสุดก่อน หาตรงกฎแรกก็หยุด (First Match Wins)
- Flow Logs เก็บได้สูงสุด 1 ปี ใน Storage Account
- NSG ไม่รองรับ Geo-blocking ต้องใช้ Azure Firewall หรือ WAF
สรุป
Default: 200 กฎ/NSG | Max: 1,000 กฎ/NSG (ต้องขอ Support Ticket) | 1 NSG ต่อ 1 Subnet/NIC | ใช้ ASG + Service Tags เพื่อลดจำนวนกฎและจัดการง่ายขึ้น