π
- π NACL vs Security Group (SG) β FULL PACKET FLOW EXPLAINED
- 1οΈβ£ First, the Core Difference (Must Remember)
- 2οΈβ£ Where NACL and SG Sit in AWS Networking
- 3οΈβ£ NACL vs SG β High-Level Comparison
- 4οΈβ£ What βStatefulβ vs βStatelessβ REALLY Means
- 5οΈβ£ FULL PACKET FLOW β Public Web Server Example
- 6οΈβ£ PACKET FLOW: Client β EC2 (Inbound Traffic)
- 7οΈβ£ PACKET FLOW: EC2 β Client (Outbound Response)
- 8οΈβ£ REQUIRED RULES SUMMARY (VERY IMPORTANT)
- 9οΈβ£ What Happens If One Rule Is Missing?
- π FULL PACKET FLOW β Private EC2 with NAT Gateway
- 1οΈβ£1οΈβ£ NACL vs SG β Decision Rule (EXAM GOLD)
- 1οΈβ£2οΈβ£ Common AWS Exam Traps
- 1οΈβ£3οΈβ£ Mental Model (REMEMBER THIS)
- 1οΈβ£4οΈβ£ One-Line Exam Definitions
- 1οΈβ£5οΈβ£ Final Summary (Must Remember)
π NACL vs Security Group (SG) β FULL PACKET FLOW EXPLAINED
1οΈβ£ First, the Core Difference (Must Remember)
NACL works at the subnet level and is stateless, while Security Group works at the instance level and is stateful.
Everything else comes from this.
2οΈβ£ Where NACL and SG Sit in AWS Networking
Letβs first fix the order of traffic flow, because this is where most confusion happens.
π Actual AWS Traffic Flow Order
Internet
β
Internet Gateway (IGW)
β
Route Table (decides path)
β
NACL (Subnet-level firewall)
β
Security Group (Instance-level firewall)
β
EC2 Instance
π Both NACL and SG must allow traffic If either blocks, traffic is blocked.
3οΈβ£ NACL vs SG β High-Level Comparison
| Feature | NACL | Security Group |
|---|---|---|
| Level | Subnet | Instance |
| Stateful | β No | β Yes |
| Allow rules | β Yes | β Yes |
| Deny rules | β Yes | β No |
| Rule order | Numbered (evaluated in order) | No order |
| Default inbound | Allow all (default NACL) | Deny all |
| Return traffic | Must be explicitly allowed | Automatically allowed |
4οΈβ£ What βStatefulβ vs βStatelessβ REALLY Means
πΉ Stateless (NACL)
NACL does NOT remember traffic.
If a request is allowed in, the response is NOT automatically allowed.
You must allow:
- Request
- Response Both directions
πΉ Stateful (Security Group)
Security Group remembers traffic.
If a request is allowed:
- Response is automatically allowed
- No extra rule needed
5οΈβ£ FULL PACKET FLOW β Public Web Server Example
Letβs take a real scenario.
π§© Setup
- VPC:
10.0.0.0/16 - Public Subnet:
10.0.1.0/24 - EC2 private IP:
10.0.1.10 - EC2 public IP:
54.12.34.56 - Website running on port 80
6οΈβ£ PACKET FLOW: Client β EC2 (Inbound Traffic)
π Step 1: Client Sends Request
Client IP: 203.0.113.5
Client Port: 53000 (ephemeral)
Destination IP: 54.12.34.56
Destination Port: 80
Protocol: TCP
π Step 2: Internet Gateway (IGW)
- IGW maps:
54.12.34.56 β 10.0.1.10
IGW does NOT filter traffic.
π£ Step 3: Route Table
- Route table confirms destination subnet
- Traffic forwarded internally
π Step 4: NACL (Inbound Rule Check)
NACL checks inbound rules:
Required NACL inbound rule:
Allow TCP 80 from 0.0.0.0/0
β If allowed β packet continues β If denied β packet dropped here
π Step 5: Security Group (Inbound Rule Check)
Security Group checks inbound rules:
Required SG inbound rule:
Allow TCP 80 from 0.0.0.0/0
β Allowed β packet reaches EC2 β Denied β packet dropped
π₯ Step 6: EC2 Receives Request
EC2 processes HTTP request.
7οΈβ£ PACKET FLOW: EC2 β Client (Outbound Response)
Now comes the MOST IMPORTANT PART.
π₯ Step 7: EC2 Sends Response
Source IP: 10.0.1.10
Source Port: 80
Destination IP: 203.0.113.5
Destination Port: 53000
π Step 8: Security Group (Outbound Check)
Here is where stateful behavior matters.
π Because inbound traffic was allowed:
- Response traffic is automatically allowed
- No outbound rule needed
β SG allows response automatically
π Step 9: NACL (Outbound Rule Check)
Since NACL is stateless, it checks outbound rules.
You MUST have:
Allow TCP 1024β65535 to 0.0.0.0/0
Why?
- Client port = 53000 (ephemeral)
β If missing β response blocked β If present β response allowed
π Step 10: IGW Sends Response to Internet
IGW maps private IP back to public IP.
Client receives website response.
8οΈβ£ REQUIRED RULES SUMMARY (VERY IMPORTANT)
β Security Group Rules
Inbound:
TCP 80 from 0.0.0.0/0
Outbound:
Allow all (default)
β NACL Rules
Inbound:
Allow TCP 80 from 0.0.0.0/0
Allow TCP 1024β65535 from 0.0.0.0/0
Outbound:
Allow TCP 80 to 0.0.0.0/0
Allow TCP 1024β65535 to 0.0.0.0/0
π Ephemeral ports are mandatory in NACLs
9οΈβ£ What Happens If One Rule Is Missing?
β Missing NACL outbound ephemeral ports
- Request reaches EC2
- Response blocked
- Browser hangs
β Missing SG inbound rule
- Packet blocked at instance
- No response
β Missing NACL inbound rule
- Packet blocked before reaching EC2
π FULL PACKET FLOW β Private EC2 with NAT Gateway
Letβs quickly understand private subnet flow.
π§© Setup
- Private subnet
- EC2 has no public IP
- NAT Gateway in public subnet
Flow
EC2 β SG β NACL β Route Table β NAT Gateway β IGW β Internet
Return traffic:
Internet β IGW β NAT β Route Table β NACL β SG β EC2
π NACL must allow:
- Outbound ephemeral ports
- Inbound ephemeral ports
π SG auto-allows response traffic
1οΈβ£1οΈβ£ NACL vs SG β Decision Rule (EXAM GOLD)
| Requirement | Use |
|---|---|
| Instance-level access | Security Group |
| Subnet-wide blocking | NACL |
| Explicit deny | NACL |
| Stateful control | Security Group |
| Simple management | Security Group |
1οΈβ£2οΈβ£ Common AWS Exam Traps
β SG allows traffic but app not reachable β‘ NACL blocking
β Return traffic blocked β‘ Missing ephemeral ports in NACL
β Want to block a single IP β‘ NACL (SG cannot deny)
β Multiple SGs attached β‘ Rules are combined (OR logic)
1οΈβ£3οΈβ£ Mental Model (REMEMBER THIS)
NACL = Border control (stateless)
SG = Door lock (stateful)
1οΈβ£4οΈβ£ One-Line Exam Definitions
NACL
A stateless subnet-level firewall that controls inbound and outbound traffic using allow and deny rules.
Security Group
A stateful instance-level firewall that allows traffic and automatically permits response traffic.
1οΈβ£5οΈβ£ Final Summary (Must Remember)
- NACL is checked before SG
- NACL is stateless β allow both directions
- SG is stateful β return traffic automatic
- Both must allow traffic
- Ephemeral ports are key for NACLs