SG là stateful instance-level firewall; NACL là stateless subnet-level filter.
Security Group (SG) hoạt động ở cấp độ instance (ENI level), là stateful — khi cho phép inbound traffic, outbound response tự động được allow không cần rule riêng; chỉ có allow rules, không có deny rules; áp dụng cho EC2, RDS, Lambda (VPC mode), v.v.
Network ACL (NACL) hoạt động ở cấp độ subnet, là stateless — phải define cả inbound và outbound rules riêng biệt; có cả allow và deny rules; rule được evaluate theo thứ tự số (100, 200...), rule đầu tiên match sẽ áp dụng. Vì stateless, NACL phức tạp hơn để configure đúng — cần cho phép ephemeral ports (1024-65535) cho outbound responses.
Thực tế: Security Group là defense chính, được dùng cho mọi resource; NACL là defense thứ hai ở subnet level, dùng khi cần block toàn bộ subnet hoặc block IP/CIDR range cụ thể (ví dụ chặn IP tấn công DDoS nhanh). Best practice: principle of least privilege cho SG — chỉ mở port cần thiết, chỉ allow source cụ thể (không dùng 0.0.0.0/0 trừ khi cần public access).
SG is a stateful instance-level firewall; NACL is a stateless subnet-level filter.
Security Groups (SG) operate at the instance level (ENI level) and are stateful — when inbound traffic is allowed, the outbound response is automatically permitted without a separate rule; they support only allow rules, no deny rules; they apply to EC2, RDS, Lambda (VPC mode), etc.
Network ACLs (NACLs) operate at the subnet level and are stateless — you must define inbound and outbound rules separately; they support both allow and deny rules; rules are evaluated in numeric order (100, 200...) and the first matching rule is applied. Because they are stateless, NACLs are more complex to configure correctly — you must allow ephemeral ports (1024-65535) for outbound responses.
In practice: Security Groups are the primary defense and are used for every resource; NACLs are the secondary defense at the subnet level, used when you need to block an entire subnet or a specific IP/CIDR range (e.g., quickly blocking a DDoS attacker's IP). Best practice: apply least privilege to SGs — only open required ports and allow specific sources (avoid 0.0.0.0/0 unless public access is needed).