Network ACLs and Ephemeral Ports
Stateless subnet firewall rules, rule ordering, and the ephemeral port ranges you must open for return traffic.
Exam tasks: 3.3 (network controls that permit or prevent traffic: security groups, network ACLs)
The decision: when a network ACL is in the path, which return-traffic ports must you open, and which control blocks a specific address?
A network ACL (NACL) is a stateless allow and deny filter on a subnet boundary. Because it keeps no connection state, the reply to every allowed request needs its own rule on the ephemeral port the client picked.
Security group versus NACL
| Item | Security group | Network ACL |
|---|---|---|
| Level | Network interface (instance) | Subnet |
| State | Stateful. Replies to allowed traffic are allowed | Stateless. Replies need their own rule |
| Rule types | Allow only | Allow and deny |
| Evaluation | All rules together | Lowest rule number first. First match wins |
| Default end rule | Implicit deny | Final * rule denies anything unmatched and cannot be edited |
| Source can be | CIDR, prefix list, another security group | CIDR only |
IPv4 and IPv6 rules are evaluated separately, so add both when the VPC has IPv6.
Ephemeral ports
The client chooses the ephemeral source port, and the range depends on its operating system.
| Client | Range |
|---|---|
| Many Linux kernels, including Amazon Linux | 32768 to 61000 |
| Windows Server 2008 and later | 49152 to 65535 |
| Windows through Server 2003 | 1025 to 5000 |
| Elastic Load Balancing | 1024 to 65535 |
| NAT gateway | 1024 to 65535 |
| AWS Lambda | 1024 to 65535 |
When the client types are mixed or unknown, allow 1024 to 65535 for return traffic. Place any deny rules for bad ports in that range at lower rule numbers than the wide allow rule.
Direction rules.
- Remote client talks to your instance. Inbound allow on the service port, outbound allow on the ephemeral range.
- Your instance talks to a remote server (for example an update download). Outbound allow on the service port, inbound allow on the ephemeral range.
Exam signal
"Can connect out but replies never arrive" or "SSH works then hangs" on a custom NACL means a missing ephemeral port rule. "Block one abusive IP range fast" means a NACL deny rule, since security groups cannot deny.
Exam trap
Adding a deny rule for 0.0.0.0/0 or the subnet CIDR on a backend subnet can break load balancer health checks. Also, flow logs showing ACCEPT then REJECT for a ping point at the NACL on the reply path, while a single REJECT points at the security group.
Worked patterns
- For a web subnet, allow inbound 443 from
0.0.0.0/0and outbound 1024 to 65535 to0.0.0.0/0, or HTTPS replies never leave the subnet. - Instances in that subnet that call out (updates, APIs) also need inbound 1024 to 65535 for the replies.
- The Linux kernel default range is 32768 to 60999. AWS documents 32768 to 61000 for many Linux kernels.
The NACL looks right but traffic fails
A NACL with inbound 443 allowed and outbound 443 allowed still breaks HTTPS: replies go to the client's ephemeral port, not to 443. When a question shows connections timing out after a NACL change, check the return-path ephemeral range first. Reachability Analyzer names the blocking rule.
Scenarios
NACLs are stateless, so replies from the ALB to each client's high source port need an outbound allow for 1024–65535. The ALB nodes also need the matching return rules toward the targets. Security groups and NACLs always work together. TLS doesn't require port 80, and rule numbers only set order.
Related
-
Network Access Analyzer and Reachability Analyzer names the blocking rule.