AWS Builder Center
Security Groups vs NACLs: Two Firewalls, Two Jobs

Security Groups vs NACLs: Two Firewalls, Two Jobs

When you launch an EC2 instance, traffic has to pass through two layers of filtering in a VPC: the Network ACL on the subnet, and the Security Group on the instance's network interface. They look similar, but they behave very differently.

Engineering Student | Cloud DevOps & SRE Engineer
Security Groups are stateful. If you allow inbound traffic on port 443, the response traffic is automatically allowed back out. You only write "allow" rules; anything not allowed is denied. Security groups attach to network interfaces, so different instances in the same subnet can have different rules. You can even reference another security group as a source, e.g. "allow port 5432 only from the app-server SG", instead of hardcoding IPs.
Network ACLs are stateless. Return traffic is not automatically allowed, so you need matching inbound and outbound rules, including the ephemeral port range for responses. NACLs support both allow and deny rules, evaluated in order by rule number, lowest first. They apply to every resource in the subnet.
When to use which?
  • Security groups are your main, everyday control: tight, per-instance, least privilege.
  • NACLs are a coarse safety net at the subnet level, useful for explicitly blocking a known bad IP range, which security groups cannot do since they have no deny rules.
A simple web server setup:
  • Allow 80/443 from anywhere
  • Allow 22 only from your own IP (or better, close it and use SSM Session Manager)
  • Allow the database port only from the web server's security group
Default NACLs allow all traffic, so many setups never touch them. That's fine, as long as your security groups follow least privilege.
Two firewalls, two jobs: security groups decide who can talk to an instance; NACLs decide what can enter or leave a subnet at all.
#AWS #CloudSecurity #VPC #DevOps
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article