Core lesson 17 of 18Topic: VPC: routing and traffic controls
Security groups vs network ACLs: scope, rules and return traffic
Security groups (SGs) and network ACLs (NACLs) differ in where they apply, how rules work and how responses are handled. Follow a web request between subnets to understand why an SG allow does not eliminate NACL checks.
Compare SGs and NACLs and explain the requirements for a forward request and its returning response.
Know VPCs, subnets, ENIs and request/response directions. No real configuration is modified.
Start with the three key differences
| Aspect | Security group | Network ACL |
|---|---|---|
| Scope | Traffic for associated resources | Traffic entering or leaving a subnet |
| Rules | Allow rules; rules from associated SGs are combined | Ordered allow/deny rules; the first matching rule applies |
| Responses | Stateful response handling for allowed traffic | Stateless; return-direction rules need review |
| Within one subnet | SG checks still apply | Does not evaluate traffic routed within that subnet |
Stateful handling considers connection state. Stateless handling does not automatically permit a response just because a request was allowed. SG state does not make a NACL stateful; inspect each control independently.
A web exchange needs the response path too
Subnet A
Subnet B
Arrows show request and response directions. SGs apply at the resource; NACLs apply at subnet boundaries.
- Client
- Starts the request; inspect source SG egress.
- Web server
- Receives the request; inspect destination SG ingress.
- Review NACLs both ways
- Review source egress and destination ingress for the request, then the reverse pair for the response.
| Direction | Source port | Destination port |
|---|---|---|
| Request: client → server | 50000: an illustrative client port | 443: the web listener |
| Response: server → client | 443 | 50000: the client port |
50000 is illustrative, not a universal client port. Real NACL review includes protocol, direction, peer addresses, the required port range and rule number. Checking the server’s port 443 alone does not establish the return direction.
SG allow rules and NACL order work differently
When several SGs are associated with a resource, their rules are combined. Narrowing one SG may not impose the intended restriction if another still grants broad access. Inspect actual associations rather than names or tags.
NACLs apply the first matching rule in ascending number order. A later Allow cannot override an earlier matching Deny. Review every associated subnet affected by a rule change.
Choose an option to see the result and explanation.
The NACL scope changes within one subnet
Traffic routed within a single subnet does not traverse the same NACL boundary checks as the inter-subnet example. SG and host requirements still matter. Shared placement does not imply unrestricted communication.
Change one directional condition in the lab
- Evaluate the initial inter-subnet conditions and read both directions.
- Set destination NACL return egress to false and inspect the stopping point.
- Compare the same-subnet condition and explain how NACL scope differs from SG scope.
Check, then explain in your own words
- Compare scope, rules and responses.
- Identify the destination port in each direction.
- Distinguish omitted same-subnet NACL checks from remaining requirements.
Check your understanding: A lower-numbered NACL Deny and a later Allow both match. Which applies?
The first matching, lower-numbered Deny.
NACLs apply the first match in rule order, unlike a combined set of SG allow rules. Finding a later Allow is insufficient.
Sources and conditions checked
The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.
- VPC security groupsChecked:
Scope and conditionsStateful resource traffic controls
Used in this lessonStart with the three key differences A web exchange needs the response path too SG allow rules and NACL order work differently The NACL scope changes within one subnet
- VPC network ACLsChecked:
Scope and conditionsStateless subnet boundary controls; rule order and return traffic
Used in this lessonStart with the three key differences A web exchange needs the response path too SG allow rules and NACL order work differently The NACL scope changes within one subnet
- Security group rulesChecked:
Scope and conditionsAllow-rule fields, associated-rule aggregation and effects of changes; not universal application reachability.
Used in this lessonStart with the three key differences SG allow rules and NACL order work differently
- Network ACL rulesChecked:
Scope and conditionsDirection, protocol, port, peer CIDR and first matching rule in ascending order.
Used in this lessonStart with the three key differences A web exchange needs the response path too SG allow rules and NACL order work differently
Scope and conditionsConnection mode, network, host and authentication must be separated
Used in this lessonA web exchange needs the response path too