INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

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.

What you will learn

Compare SGs and NACLs and explain the requirements for a forward request and its returning response.

Prerequisite

Know VPCs, subnets, ENIs and request/response directions. No real configuration is modified.

Start with the three key differences

Compare the roles of SGs and NACLs
AspectSecurity groupNetwork ACL
ScopeTraffic for associated resourcesTraffic entering or leaving a subnet
RulesAllow rules; rules from associated SGs are combinedOrdered allow/deny rules; the first matching rule applies
ResponsesStateful response handling for allowed trafficStateless; return-direction rules need review
Within one subnetSG checks still applyDoes 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

A TCP request and response across subnet boundaries
Amazon VPC One VPC, different subnets

Subnet A

ClientENI · Network interfaceSG A
NACL A Subnet boundary
TCP request and response directionsThe request travels from source to destination; the response returns to the client port used by the source.Request: TCP 443Reply: client portTCP request and response directionsThe request travels from source to destination; the response returns to the client port used by the source.RequestTCP 443ResponseClient port

Subnet B

NACL B Subnet boundary
Web serverENI · Network interfaceSG 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.
Example: destination ports differ by direction
DirectionSource portDestination port
Request: client → server50000: an illustrative client port443: the web listener
Response: server → client44350000: 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.

Because SGs are stateful, can you skip return NACL checks across subnets?
Read the answer and reason

Answer: No; review NACLs in both directions · SG response handling does not automatically satisfy NACL rules. NACLs are stateless, so request and response conditions need separate review.

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

  1. Evaluate the initial inter-subnet conditions and read both directions.
  2. Set destination NACL return egress to false and inspect the stopping point.
  3. Compare the same-subnet condition and explain how NACL scope differs from SG scope.

Check, then explain in your own words

  1. Compare scope, rules and responses.
  2. Identify the destination port in each direction.
  3. 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.