Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

Network Security Group (NSG) Rules ใน Azure คืออะไร?

NSG (Network Security Group) คืออะไร?

Virtual Firewall ใน Azure ควบคุม Inbound/Outbound Traffic ไปยัง Resources (VM, Subnet, NIC) โดยใช้ Rules แบบ 5-tuple

โครงสร้าง NSG Rule

Propertyคำอธิบาย
Nameชื่อ Rule (Unique ใน NSG)
Priority100-4096 (ยิ่งน้อย = สำคัญกว่า ประมวลผลก่อน)
DirectionInbound / Outbound
AccessAllow / Deny
ProtocolTCP, UDP, ICMP, ESP, AH, * (All)
Source / DestinationIP Address, CIDR, Service Tag, Application Security Group (ASG)
Source / Destination Port RangeSingle Port, Range (80-443), * (All)

Default Rules (ไม่สามารถลบได้ แต่อาจ Override ได้)

Inbound Defaults

  • AllowVNetInBound (Priority 65000): Allow VNet -> VNet
  • AllowAzureLoadBalancerInBound (65001): Allow Azure LB Health Probes
  • DenyAllInBound (65500): Deny Everything Else

Outbound Defaults

  • AllowVNetOutBound (65000): Allow VNet -> VNet
  • AllowInternetOutBound (65001): Allow -> Internet
  • DenyAllOutBound (65500): Deny Everything Else

Limits & Quotas

  • 200 Rules ต่อ NSG (Default) ขอเพิ่มได้ถึง 1,000 ผ่าน Support Request
  • 5,000 NSGs ต่อ Subscription
  • 1,000 IP Addresses ต่อ Rule (Source/Destination)

Best Practices

  • ใช้ Service Tags (VirtualNetwork, AzureLoadBalancer, Internet, Storage, Sql, ไม่ต้อง Update IP เอง)
  • ใช้ Application Security Groups (ASG) จัดกลุ่ม VMs ตาม Role (Web, App, DB)
  • Associate NSG กับ Subnet (แนะนำ) ไม่ใช่ NIC เดี่ยวๆ เพื่อ Manageability
  • Naming Convention: NSG---
  • Document Business Justification ใน Description
  • Test กับ IP Flow Verify และ Connection Troubleshoot

สร้าง NSG (Azure CLI)

az network nsg create -g MyResourceGroup -n MyNSG
az network nsg rule create -g MyResourceGroup --nsg-name MyNSG \
  -n Allow-HTTP --priority 100 --direction Inbound --access Allow \
  --protocol Tcp --source-address-prefix Internet --source-port-range '*' \
  --destination-address-prefix '*' --destination-port-range 80

NSG vs Azure Firewall

  • NSG: L3/L4, Distributed, Free, Stateless (mostly), Per Subnet/NIC
  • Azure Firewall: L3/L4/L7, Centralized, Paid, Stateful, Threat Intelligence, SNAT/DNAT, Forced Tunneling