Lesson 3 of 3 Amazon VPC Configuration

Filtering Traffic with Security Groups and Network ACLs

This lesson explains how security groups and network ACLs filter traffic at different layers with different behaviour, on which many connectivity and security questions turn.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish stateful security groups from stateless network ACLs.
  • Design rules for each tier.
  • Block an IP range with a network ACL.

Security groups

A security group is a stateful virtual firewall attached to network interfaces (instances, load balancers, RDS, Lambda in a VPC, endpoints). It contains only allow rules for inbound and outbound traffic; anything not allowed is denied. Because it is stateful, responses to allowed traffic are allowed automatically regardless of rules. Rules can reference CIDRs, prefix lists or other security groups, for example "allow 5432 from the application tier's security group", which keeps rules correct as instances change. The default outbound rule allows all traffic. Changes apply immediately, but existing tracked connections may persist until they end.

Network ACLs

A network ACL is a stateless filter applied to all traffic entering and leaving a subnet. Rules are numbered and evaluated in order from the lowest number; the first match decides, and a final * rule denies everything else. NACLs support both allow and deny rules, so they can block a specific IP range. Because they are stateless, return traffic must be allowed explicitly: an inbound HTTPS rule needs a matching outbound rule for ephemeral ports (1024-65535) to reach clients, and outbound connections need inbound ephemeral rules for replies. The default NACL allows all traffic; a newly created custom NACL denies all traffic until rules are added.

Security group
LevelNetwork interface
StateStateful (return traffic allowed)
RulesAllow only
EvaluationAll rules evaluated
ReferencesCIDRs, prefix lists, security groups
Default for newNo inbound, all outbound
Network ACL
LevelSubnet
StateStateless (allow return traffic explicitly)
RulesAllow and deny
EvaluationIn number order, first match wins
ReferencesCIDRs only
Default for newCustom NACL denies all

The following diagram shows a deny rule placed before the allow rules.

Blocking an attacking range with a network ACL. Rules are evaluated from the lowest number and the first match decides, so a deny rule numbered 90 for 203.0.113.0/24 blocks the range before rule 100 allows HTTPS. Because NACLs are stateless, return traffic needs its own rule on the ephemeral ports, and the final * rule denies everything else.
The addresses are documentation ranges. Leave gaps in rule numbers so later rules can be inserted.
Sort into groups

Security group or network ACL?

Exam skills 5.1.1

Decide which filter each statement describes.

Log in to try this activity Interactive activities are free with an account.

Designing rules

Use security groups as the primary control, chained by reference between tiers, and NACLs as a coarse subnet-level guard, for example denying a malicious IP range or isolating a data subnet. Security group VPC associations allow one security group to be used in several VPCs in the same Region, and shared security groups work in VPC sharing. Network Access Analyzer and Reachability Analyzer verify that rules produce the intended paths.

Scenario questions

Writing rules

Exam skills 5.1.1 · 5.3.1

Choose the rule that meets each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Blocking an attacking IP range

A web tier receives abusive traffic from 203.0.113.0/24. Security groups cannot express a deny, and removing the existing allow from 0.0.0.0/0 would block all users. The operator adds NACL rule 90 on the public subnets: deny all traffic from 203.0.113.0/24, numbered lower than the existing allow rule 100 for HTTPS. For HTTP-level filtering with rate limiting, an AWS WAF IP set and rate-based rule on the ALB would be the better long-term control.

Check yourself

Which is stateful: a security group or a network ACL?

Show answer

A security group. Return traffic is allowed automatically, whereas a network ACL needs explicit rules for it.

Exam Tips

Remember for the exam

  • Security groups are stateful, allow-only and attached to ENIs.
  • NACLs are stateless, ordered, allow and deny, at the subnet level.
  • NACLs need explicit ephemeral port rules for return traffic.
  • Block a specific IP with a NACL deny or WAF, not a security group.
  • Reference security groups by ID between tiers.