Security groups and network ACLs

Beginner · 15 min

AWS's two packet filters: stateful security groups on interfaces, stateless ACLs on subnets, referencing groups, ephemeral ports and common mistakes.

Before thisRoute tables, internet gateways and NAT

Digital Cloud Training · 15 min

Security groups and network ACLs

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Digital Cloud TrainingReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A security group is attached to a network interface, holds only allow rules and is stateful: replies are allowed automatically.
  • A network ACL is attached to a subnet, has numbered allow and deny rules evaluated lowest first, and is stateless.
  • Rules can name another security group as the source, so access follows membership instead of IP addresses.
  • With a stateless ACL you must also allow the return traffic, which usually means a range of ephemeral ports.
  • Do most filtering with security groups and use ACLs for coarse subnet-wide rules such as blocking an address range.
  • Removing a rule does not necessarily cut connections that are already established.

Two filters, two places

Routing says a packet can get somewhere. You still want to say whether it should. A VPC gives you two filters, at different points.

A security group wraps a network interface: an instance, load balancer, database or endpoint. A network ACL wraps a subnet: everything crossing its edge. Think of an office building. The ACL is the barrier at the car park, checking every vehicle in and out against a numbered list. The security group is the lock on your own office door, and it remembers whom you invited.

The general ideas of ports and firewalls are in firewalls and network troubleshooting.

Security group Network ACL
Attached to network interface subnet
Rules allow only allow and deny
Evaluation all rules together by number, first match wins
State stateful stateless
A new custom one no inbound, all outbound denies everything
The default one members can reach each other allows everything

Stateful and stateless

A stateful filter tracks connections. Allow a request in and the reply goes out, whatever the outbound rules say.

A stateless filter judges every packet alone. A client connects from a temporary ephemeral port to your port 443. Your reply goes to that high port. So an ACL needs inbound 443 and outbound to the ephemeral range, and for connections your servers open, the mirror image. AWS’s examples use ranges such as 32768 to 65535 or 1024 to 65535, depending on the clients.

This asymmetry is the classic cause of a connection that hangs rather than being refused.

Referencing groups

The most useful feature of security groups is that a rule’s source can be another security group:

alb   inbound 443   from 0.0.0.0/0
app   inbound 8080  from sg alb
db    inbound 5432  from sg app
aws ec2 authorize-security-group-ingress --group-id $APP \
    --protocol tcp --port 8080 --source-group $ALB

No IP addresses anywhere. Instances come and go during scaling and the rules stay true. Each tier can be reached only by the tier in front of it. Describing the app group shows that one inbound rule and the default allow-all outbound rule, which you can tighten.

For long lists of external addresses use a prefix list, so you update one object, not twenty rules.

Rules of thumb and limits

  • Default quotas: 60 inbound and 60 outbound rules per group, 5 groups per interface. A custom ACL allows 20 rules each way by default.
  • Never open SSH or RDP to 0.0.0.0/0. Session Manager needs no inbound rule at all.
  • Give each role its own group, named for the role, with a description on every rule.
  • Leave ACLs at their default unless you have a specific subnet-wide need. Two overlapping rule sets double the places to look.
  • Number ACL rules with gaps (100, 200) so you can insert later.

Things that surprise people

Existing connections survive. Removing a security group rule does not necessarily cut a tracked connection; it can continue until it times out. If you must sever traffic now, a deny in the ACL does it, because nothing is remembered. Some flows (fully open in both directions) are untracked and do stop at once. Idle tracking timeouts vary by instance generation, so long-lived quiet connections should send keepalives.

Not everything is filtered. Traffic to the VPC’s own DNS resolver, DHCP and the instance metadata address is not subject to these rules.

ACLs act at the edge only. Two instances in the same subnet talk without the ACL being consulted. Their security groups still apply.

Debugging

A timeout usually means a filter or route dropped the packet. Connection refused means it arrived and nothing was listening. Check in order: route tables both ways, the destination’s security group, the source’s outbound rules, both ACLs in both directions, then the process itself. Flow logs show what was rejected.

About the video

The embed is Digital Cloud Training’s “Security Groups and Network Access Control Lists”, July 2024, 15 minutes. Its chapters cover stateful against stateless firewalls, the two filters and a comparison, then demos of configuring security groups, chaining them and configuring network ACLs. I judged it from chapters and description, since transcripts couldn’t be fetched. The short video in deeper goes further on NACL rules and ephemeral ports.

What was run: the group references were created on moto, a local emulator, which passes no traffic, so nothing here shows a packet being allowed or dropped. Behaviour and quotas are from AWS documentation, checked in November 2026.

Where this fits

Your servers reach AWS services over the internet path unless you give them a private one: VPC endpoints and PrivateLink.

Check yourself

  1. 01An app's security group allows inbound 8080 and you remove every outbound rule. Do responses to incoming requests still leave?

    Yes. Security groups are stateful, so replies to allowed inbound traffic are permitted regardless of outbound rules. The instance just cannot start new outbound connections.

  2. 02You write an ACL allowing inbound 443 and outbound 443 only, and HTTPS to your web subnet hangs. Why?

    The reply goes to the client's ephemeral port, not to 443. A stateless ACL needs an outbound rule for that port range.

  3. 03Why is 'allow 5432 from the app security group' better than allowing the app subnet's CIDR?

    It admits only interfaces that carry the group, however their addresses change, and not other things that happen to share the subnet.

  4. 04You must block one abusive IP address that your public web server's security group admits along with everyone else. Can a security group do it?

    No. Security groups have no deny rules. Use a lower-numbered deny entry in the network ACL, or filter with AWS WAF in front.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark