Free tech learning for everyone, from basics to pro

AWS SecurityCloud SecurityIntermediate

AWS VPC security: security groups, network ACLs, subnets and NAT

In short: An Amazon VPC is secured in layers. Security groups are stateful allow-lists on each network interface, network ACLs are stateless subnet filters, private subnets keep servers off the internet, NAT gateways allow outbound-only access, and flow logs record what actually happened.

Layers of VPC defence

A Virtual Private Cloud (VPC) gives you a private network in AWS; the basics are in cloud networking basics. Securing it means controlling which subnets are reachable, which ports are open on each resource, and how traffic leaves. AWS gives you two packet filters that work at different points.

Security groups versus network ACLsSecurity groupAttached to an ENIStatefulAllow rules onlyAll rules evaluatedNetwork ACLAttached to a subnetStatelessAllow and deny rulesRules in number order
Figure 1. Security groups act like host firewalls on each interface; network ACLs filter at the subnet edge.

Security groups and network ACLs

A security group (SG) is attached to an elastic network interface (ENI), so it protects an EC2 instance, database or load balancer directly. It is stateful: if inbound traffic is allowed, the reply is automatically allowed. It has only allow rules, and by default allows all outbound traffic.

A network ACL (NACL) is attached to a subnet. It is stateless, so you must allow return traffic explicitly, usually on ephemeral ports 1024-65535. Rules are checked in number order and the first match wins, so you can write explicit deny rules, for example to block a known bad address range.

A powerful SG feature is referencing another security group instead of an IP range. The database SG can say "allow TCP 5432 from the app SG", so any app server gets access and nothing else does, even as IPs change.

aws ec2 authorize-security-group-ingress --group-id <db-sg-id> --protocol tcp --port 5432 --source-group <app-sg-id>

Tip: use SGs as your main control and keep NACLs simple. Complex NACLs are a common cause of hard-to-find outages because people forget they are stateless.

Public and private subnet design

Three-tier VPC layoutPublic subnetsALB, NAT gatewayApp subnetsprivate, EC2 or containersData subnetsprivate, RDS, no internet
Figure 2. A classic layout: only the load balancer is public, and each tier accepts traffic only from the tier above.
  • Only the Application Load Balancer (ALB) sits in public subnets and accepts HTTPS from the internet.
  • App servers in private subnets accept traffic only from the ALB's security group.
  • Databases accept traffic only from the app SG and have no route to the internet.
  • A NAT gateway in each zone lets private servers fetch updates without being reachable. One per zone avoids a single point of failure.
  • Avoid open SSH or RDP. Use AWS Systems Manager Session Manager for admin access, so no inbound port is needed.

Private access and visibility

FeatureSecurity benefit
Gateway endpoints (S3, DynamoDB)Reach these services without the internet; endpoint policies limit which buckets
Interface endpoints (PrivateLink)Private IPs for many AWS and partner services
VPC Flow LogsRecord accepted and rejected connections for investigation
AWS Network FirewallStateful inspection, domain filtering and IPS for whole VPCs
Route 53 Resolver DNS FirewallBlock lookups of known malicious domains

Common mistakes include security groups open to 0.0.0.0/0 on port 22 or 3389, databases with public IPs, a single NAT gateway for all zones, and flow logs never turned on. GuardDuty and AWS Config rules can flag many of these automatically.

Practice

You allow inbound HTTPS in a NACL, but replies never reach clients. Why?
NACLs are stateless; you must also allow outbound return traffic on ephemeral ports.
How can a database security group allow only the app servers, even when their IPs change?
Reference the app servers' security group as the source instead of an IP range.
How can admins reach private EC2 instances without opening port 22?
Use AWS Systems Manager Session Manager, which works through the SSM agent and IAM, with no inbound ports.

Key takeaways

  • Security groups are stateful, allow-only and attached to interfaces.
  • NACLs are stateless, ordered, subnet-level and can deny.
  • Keep only load balancers public; app and data tiers stay private.
  • Use one NAT gateway per zone and VPC endpoints for AWS services.
  • Turn on flow logs and avoid open SSH or RDP.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.