SkillSprout
Chapter 4 · Lesson 7
Intermediate
8 min read

NACL

Overview

A Network Access Control List (NACL) is an optional, stateless firewall at the subnet boundary. Every packet entering or leaving a subnet is checked against the NACL's numbered rules, and each rule can allow or deny traffic by protocol, port range and CIDR.

Because NACLs are stateless, they do not remember connections. If you allow inbound traffic on port 443 you must also allow the outbound reply to the client's random (ephemeral) port. This is the most common NACL mistake and a favourite exam trap.

NACLs add a second layer of defence in front of security groups. Their special strength is the explicit deny: you can block a malicious IP range for an entire subnet, something security groups cannot do. Each subnet is associated with exactly one NACL, and each NACL can protect many subnets.

Key Concepts

  • NACLs operate at the subnet level and apply to all traffic entering or leaving that subnet; they do not filter traffic between instances inside the same subnet.
  • They are stateless: inbound and outbound rules are evaluated independently, so return traffic needs its own allow rule.
  • Rules are numbered 1–32766 and evaluated lowest number first; the first match wins and processing stops.
  • Each NACL ends with an unmodifiable rule * that denies anything unmatched.
  • The default NACL (one per VPC) allows all inbound and outbound traffic; a custom NACL denies everything until you add rules.
  • A subnet can be associated with only one NACL; a NACL can cover many subnets; default limits are 200 NACLs per VPC and 20 rules per direction (adjustable to 40).
  • Clients use ephemeral ports (Linux 32768–60999, Windows 49152–65535; NAT Gateways and ELBs use 1024–65535) — allow 1024–65535 on the return path.
  • NACLs support allow and deny rules and can match IPv4 and IPv6 CIDRs, but not security groups.
  • NACLs do not filter traffic to the Amazon DNS server, DHCP, instance metadata (169.254.169.254), the Windows license server or the VPC router.

Detailed Notes

Stateless evaluation

For a web server in a subnet, an HTTPS request involves two packet flows, and each is checked separately:

DirectionPacketNeeds a rule allowing
Inboundclient:51234 -> server:443TCP 443 from the client CIDR
Outboundserver:443 -> client:51234TCP 1024–65535 to the client CIDR

If the outbound ephemeral rule is missing, the connection hangs even though the security group is perfect.

Rule evaluation and numbering

  • Rules are processed in ascending rule number; once a rule matches, no further rules are checked.
  • Leave gaps (100, 200, 300…) so you can insert rules later.
  • A DENY at a lower number than an ALLOW wins for overlapping traffic.
  • The final * rule denies everything else.
text
Inbound NACL (public subnet)
Rule#  Type     Protocol  Port        Source          Action
90     Custom   TCP       0-65535     203.0.113.0/24  DENY     <- block a bad range
100    HTTPS    TCP       443         0.0.0.0/0       ALLOW
110    HTTP     TCP       80          0.0.0.0/0       ALLOW
120    SSH      TCP       22          198.51.100.0/24 ALLOW
*      All      All       All         0.0.0.0/0       DENY

Outbound NACL
100    Custom   TCP       1024-65535  0.0.0.0/0       ALLOW    <- ephemeral replies
110    HTTPS    TCP       443         0.0.0.0/0       ALLOW    <- patches/APIs
*      All      All       All         0.0.0.0/0       DENY

Default vs. custom NACL

PropertyDefault NACLCustom NACL
CreatedAutomatically with the VPCBy you
Inbound/outboundAllow allDeny all until rules added
Used bySubnets with no explicit associationSubnets you associate
DeletableNoYes (if no subnets use it)

When you change a subnet's NACL association, the change applies immediately.

Ephemeral port ranges

Client OS / serviceEphemeral range
Linux kernels32768–60999
Windows Server 2008+49152–65535
ELB, NAT Gateway1024–65535

Safe, simple choice: allow 1024–65535.

NACL vs. security group

NACLSecurity group
Applies toSubnetENI/instance
StateStatelessStateful
Rule typesAllow and denyAllow only
EvaluationOrdered by rule number, first matchAll rules together
Source can beCIDR onlyCIDR, prefix list, SG
AssociationAutomatic for all resources in subnetMust be attached
Typical roleCoarse guardrail, block IPsFine-grained, primary control

Traffic must pass both: inbound traffic is checked by the NACL first, then the security group; outbound is checked by the security group first, then the NACL.

VPC endpoints and NACLs

  • Traffic to gateway endpoints (S3, DynamoDB) is destined for AWS prefix-list IP ranges; NACLs need an allow rule covering those public IPs on 443 and the ephemeral return path.
  • Interface endpoints are ENIs in your subnets: the subnet NACL must allow 443 to/from the subnet, and the endpoint's security group must allow 443 from clients.
  • Endpoint policies and security groups are the preferred controls; avoid over-complicating NACLs.

CLI example: block an IP range

bash
aws ec2 create-network-acl-entry --network-acl-id acl-0abc123 --ingress \
  --rule-number 90 --protocol tcp --port-range From=0,To=65535 \
  --cidr-block 203.0.113.0/24 --rule-action deny

Troubleshooting

  • Connection hangs: check NACL outbound ephemeral ports.
  • Works from one subnet but not another: compare NACL associations.
  • Use VPC Flow Logs — a REJECT record can come from either the NACL or the security group, so check both.

Real World Example

Scenario — a news site blocks a scraping botnet during a traffic spike.

A media company's public web subnet starts receiving thousands of requests per second from a /24 range that is scraping paywalled articles. The security group cannot help: security groups have no deny rules, and the attacker's addresses change within the range.

The on-call architect adds a NACL rule 50: DENY all TCP from the offending /24 to the web subnet's inbound NACL. Because rules run in numeric order, the deny is evaluated before the allow rules at 100 and 110 and the traffic is dropped at the subnet boundary, before reaching instances.

During the incident an engineer also accidentally changed the outbound rules and removed the ephemeral port range; users saw connections hang. The cause was found within minutes because NACLs are stateless — adding back TCP 1024-65535 outbound fixed it. Afterwards the team put NACL changes into CloudFormation with review, added AWS WAF rate-based rules on the ALB for longer-term bot control, and used Flow Logs to confirm drops.

Architecture Diagram

NACL at the subnet edge, security group at the instance
Architecture
AWS Cloud
Clientsephemeral port 51234
VPC
Internet Gateway
Public subnet
NACLstateless, ordered, allow + deny
Security groupstateful, allow only
Web server

Traffic crosses the stateless NACL at the subnet boundary and then the stateful security group on the instance.

  1. 1A request arrives from the internet through the Internet Gateway to the subnet boundary.
  2. 2The NACL evaluates inbound rules in numeric order — the first match (allow or deny) wins.
  3. 3The security group then checks the instance-level rules; allowed requests reach the web server.
  4. 4The reply is checked by the SG (automatically allowed) and then by the NACL outbound rules, which must explicitly allow the ephemeral port range.

Best Practices

  • ✓Leave the default NACL (allow all) in place for most subnets and rely on security groups; add custom NACLs for coarse guardrails or compliance.
  • ✓Number rules with gaps (100, 200, 300) and put deny rules at lower numbers than allows.
  • ✓Always allow ephemeral ports 1024–65535 on the return path of allowed services.
  • ✓Use NACLs to block known bad CIDRs and security groups for everything else.
  • ✓Use separate NACLs per tier (public, app, data) so changes stay scoped.
  • ✓Manage NACLs as code and test in staging — a small mistake can black-hole an entire subnet.
  • ✓Enable Flow Logs and review REJECT records to validate NACL behaviour.
  • ✓For large-scale or domain-level filtering, use AWS Network Firewall or AWS WAF instead of long NACL lists.

Common Interview Questions

Exam Tips

SAA-C03 focus

  • NACL = stateless, subnet-level, allow AND deny, rules by number. Security group = stateful, ENI-level, allow only.
  • Blocking a specific IP -> NACL deny rule. This is one of the most reliable SAA-C03 patterns.
  • Custom NACL denies everything by default; the default NACL allows everything.
  • If a connection hangs while the security group looks correct, suspect missing ephemeral port (1024–65535) rules on the NACL.
  • Lowest rule number wins and evaluation stops at first match.
  • A subnet has one NACL; a NACL can have many subnets.
  • NACLs apply to subnet boundaries only — intra-subnet traffic is not filtered.
  • S3/DynamoDB private access = gateway VPC endpoint (route-table based, with endpoint policy), other AWS services = interface endpoint (ENI with SG).

Chapter quiz

Networking · 5 questions

  1. 1.A company needs private EC2 instances in two Availability Zones to download OS patches from the internet. The solution must remain available if one AZ fails and must not allow inbound connections from the internet. What should the solutions architect do?

  2. 2.A subnet's security group allows inbound HTTPS from the internet, but clients time out. The subnet uses a custom network ACL that allows inbound TCP 443 and has no outbound rules other than the default deny. What is the fix?

  3. 3.A security engineer must immediately block traffic from a specific malicious IP range to every instance in a public subnet. Which approach is the simplest?

  4. 4.A VPC has a 10.0.0.0/16 CIDR. A subnet is created as 10.0.5.0/28. How many IP addresses are available for instances in that subnet?

  5. 5.IPv6-enabled instances in private subnets must download updates from the internet, but no host on the internet may initiate connections to them. The solution should be as inexpensive as possible. What should be used?

0 of 5 answered

Finished this lesson?

0 of 64 lessons done · 0% of the course