Computer >> Hướng Dẫn Máy Tính >  >> Kết Nối Mạng >> An Ninh Mạng

Cách chỉnh sửa quy tắc mặc định Network Security Group (NSG) trên Azure/AWS

Network Security Group (NSG) là gì?

NSG là tường lửa phân tán (distributed firewall) của Azure, chứa tập quy tắc Allow/Deny cho traffic inbound/outbound dựa trên: nguồn/đích (IP/CIDR/Service Tag/Application Security Group), cổng, giao thức, ưu tiên (priority 100-4096).

Quy tắc mặc định (Default Rules) của Azure NSG

Quy tắc mặc định không thể xóa, chỉ ghi đè bằng quy tắc ưu tiên cao hơn (số nhỏ hơn).

Chỉnh sửa NSG trên Azure Portal

  1. Tìm Network security groups → chọn NSG cần sửa.
  2. Menu Settings > Inbound security rules hoặc Outbound security rules.
  3. Nhấn + Add để tạo quy tắc mới (ghi đè default) hoặc Edit quy tắc tùy chỉnh hiện có.
  4. Điền: Source/Destination (Any, IP Addresses, Service Tag, ASG), Service (HTTP, HTTPS, RDP, Custom), Port ranges, Protocol, Action (Allow/Deny), Priority (100-4096), Name, Description.
  5. Nhấn Add / Save.

Application Security Group (ASG) – Quản trị quy tắc theo ứng dụng

  1. Tạo ASG: Create a resource > Application security group → đặt tên, region, resource group.
  2. Gán ASG cho NIC của VM: VM → Networking → Application security groups → Add ASG vừa tạo.
  3. Trong NSG rule: Source/Destination chọn Application security group → chọn ASG.
  4. Lợi ích: Không cần quản lý IP, tự động áp dụng khi scale VM.

Security Group trên AWS (EC2/VPC)

  • Stateful (khác NSG stateless): Allow inbound tự động allow response outbound.
  • Default SG: Allow all traffic giữa các instance cùng SG; Deny all inbound từ ngoài.
  • Chỉnh sửa: EC2 Console → Security Groups → chọn SG → Edit inbound/outbound rules → Save rules.
  • Quota: 2500 SG/VPC, 60 rules/SG (mặc định), có thể tăng quota.

So sánh NSG (Azure) vs Security Group (AWS)

Tên quy tắcHướngƯu tiênHành độngMô tả
AllowVNetInBoundInbound65000AllowCho phép traffic trong cùng VNet
AllowAzureLoadBalancerInBoundInbound65001AllowHealth probe Azure LB
DenyAllInBoundInbound65500DenyChặn tất cả inbound còn lại
AllowVNetOutBoundOutbound65000AllowCho phép traffic ra trong VNet
AllowInternetOutBoundOutbound65001AllowCho phép ra Internet
DenyAllOutBoundOutbound65500DenyChặn tất cả outbound còn lại
Đặc điểmAzure NSGAWS Security Group
StatefulKhông (Stateless)Có (Stateful)
Áp dụng cấpSubnet & NICENI (Instance level)
PriorityCó (100-4096)Không (đánh giá tất cả allow)
Service TagCó (AzureCloud, AzureLoadBalancer...)Không (dùng Prefix List)
ASG / SG groupingApplication Security GroupSecurity Group referencing SG
Default rules6 quy tắc ẩn, không xóa1 SG default cho VPC

Giới hạn NSG Azure

  • Tối đa 5.000 NSG/subscription (mặc định), 1.000 rules/NSG (mặc định 200, tăng qua support ticket).
  • Một NIC/subnet chỉ gán 1 NSG.

Best Practices

  1. Dùng ASG thay vì IP tĩnh cho workload động.
  2. Áp dụng NSG ở cấp Subnet cho quản trị tập trung, NIC cho exception.
  3. Luôn đặt quy tắc Deny All cuối (priority cao) – mặc định đã có.
  4. Ghi log NSG flow logs → Log Analytics / Sentinel để phát hiện bất thường.
  5. Test quy tắc mới trong môi trường dev/staging trước production.
  6. Document mọi quy tắc custom: mục đích, owner, review date.