Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

6.1.2. Security Groups and Network ACLs

šŸ’” First Principle: Security groups and NACLs both filter traffic, but they operate at different levels and with different evaluation models — and confusing them causes misconfigured architectures. Security groups are stateful (return traffic is automatically allowed); NACLs are stateless (return traffic must be explicitly allowed). Understanding this distinction is non-negotiable for the exam.

Security Groups — Stateful Firewall at the Instance Level:
PropertyDetail
Attached toENI (network interface) — EC2 instances, RDS, Lambda in VPC, etc.
Default behaviorAll inbound denied; all outbound allowed
Rule evaluationAll rules evaluated; most permissive wins (no explicit deny)
StatefulIf inbound is allowed, response traffic is automatically allowed outbound
Reference other SGsYes — allow traffic from instances in another security group

Security group chaining (referencing other groups) is a powerful pattern for tier-based access control:

Internet → ALB SG (port 443 allowed from 0.0.0.0/0)
         → App SG (port 8080 allowed from ALB SG only)
         → DB SG (port 5432 allowed from App SG only)

No instance's security group allows direct internet access to the database — the chain enforces the access model.

Network ACLs — Stateless Firewall at the Subnet Level:
PropertyDetail
Attached toSubnet
Default behaviorDefault NACL allows all traffic; custom NACLs deny all by default
Rule evaluationRules evaluated in number order (lowest first); first match wins
StatelessReturn traffic must be explicitly allowed (ephemeral ports!)
Explicit denyYes — unlike security groups, NACLs can explicitly deny

Ephemeral Ports Problem: When a client connects to a server, the server responds on an ephemeral port (typically 1024–65535) chosen by the client's OS. If your NACL allows inbound TCP 443 but doesn't allow outbound TCP 1024–65535, the response traffic is blocked.

NACL Inbound + Outbound rules required for web traffic:
DirectionPortProtocolSource/DestPurpose
Inbound443TCP0.0.0.0/0HTTPS requests in
Outbound1024–65535TCP0.0.0.0/0Ephemeral port responses out
Inbound1024–65535TCP0.0.0.0/0Ephemeral ports for outbound connections
Outbound443TCP0.0.0.0/0HTTPS requests to internet

VPC Flow Logs: Capture metadata about network traffic (source/dest IP, port, protocol, action: ACCEPT/REJECT, bytes, packets) at the VPC, subnet, or ENI level. Flow logs go to CloudWatch Logs or S3. They don't capture packet contents — just the flow record. Use flow logs to:

  • Identify rejected traffic (diagnose security group / NACL blocks)
  • Monitor traffic patterns
  • Detect port scans or unusual connection volumes

āš ļø Exam Trap: Security groups have no explicit deny — you can only allow or not-allow. NACLs have explicit deny rules. If you need to block a specific IP address from reaching your VPC (e.g., a known malicious IP), you cannot do this with a security group alone — you need a NACL deny rule or AWS WAF. Security groups can't say "deny traffic from this specific IP."

Reflection Question: An EC2 instance's security group allows inbound port 443 from all sources, and the subnet NACL allows inbound 443 from all sources. HTTPS requests are still being rejected. What is the most likely cause, and which AWS tool would you use to diagnose it?

Alvin Varughese
Written byAlvin Varughese
Founder•15 professional certifications