β Day 12 of My Cloud Journey β β Mastering AWS Security Groups vs. Network ACLs π

Todayβs focus was on one of the most critical parts of AWS networking and cloud security: understanding Security Groups (SGs) and Network ACLs (NACLs) in an AWS VPC.
Security is the backbone of the cloud, and today I took a deep dive into how AWS provides multiple layers of network protection β starting from the instance level (Security Groups) to the subnet level (NACLs).
π What Are Security Groups?
A Security Group in AWS is like a virtual firewall for your EC2 instances. It controls inbound and outbound traffic and is associated with instances, not subnets.
π Key Properties of Security Groups:
Stateful: This means if you allow an inbound rule, the response is automatically allowed outbound.
Applied at the instance level (not subnet).
Rules are configured based on:
Protocol (TCP, UDP, ICMP)
Port range (22, 80, 443, etc.)
Source/Destination (IP address, CIDR block, SG ID)
Default behavior:
All inbound traffic is denied
All outbound traffic is allowed
π What Are Network ACLs (NACLs)?
A Network ACL is an optional firewall for your subnets, providing stateless filtering. You need to define both inbound and outbound rules, as return traffic is not automatically allowed.
π Key Characteristics:
Stateless: Responses must be explicitly allowed.
Works at the subnet level
Rules evaluated in order, from lowest to highest number
Allows both allow and deny rules
Default NACL allows all traffic (inbound/outbound)
ποΈ Architectural Scenario
Letβs say you have:
One Public Subnet with a web server (Apache)
One Private Subnet hosting a database (MySQL)
Security Group attached to EC2 instances
Custom NACL applied to subnets
β Hands-On: Security Groups
π Task: Allow HTTP and SSH access to EC2 instance
Security Group Inbound Rules:
Type: SSH | Protocol: TCP | Port: 22 | Source:
My IP
Type: HTTP | Protocol: TCP | Port: 80 | Source:
0.0.0.0/0
Outbound Rules:
- Leave default (All traffic allowed)
π§ͺ Test:
SSH into EC2 β
Open
http://<ec2-public-ip>
in browser β
β Hands-On: Network ACLs
π Task: Restrict HTTP to EC2 only and block pings (ICMP)
Inbound NACL Rules:
| Rule # | Type | Protocol | Port | Source | Allow/Deny | | --- | --- | --- | --- | --- | --- | | 100 | HTTP | TCP | 80 | 0.0.0.0/0 | ALLOW | | 101 | SSH | TCP | 22 | My IP | ALLOW | | 102 | ICMP | ICMP | ALL | 0.0.0.0/0 | DENY | | * | ALL | ALL | ALL | 0.0.0.0/0 | DENY |
Outbound NACL Rules (Keep default or adjust similarly)
π§ͺ Test:
Can SSH and browse HTTP β
Canβt ping the instance β
βοΈ Security Groups vs. NACLs: Comparison Table
Feature | Security Groups | NACLs |
Level | Instance | Subnet |
Stateful/Stateless | Stateful | Stateless |
Allow/Deny | Only allow | Allow & Deny |
Evaluation | All rules | Rule number order (lowest β) |
Use Case | App/service-level filtering | Broad subnet-level filtering |
π― Best Practices
Use Security Groups to control traffic to/from instances
Use NACLs for blacklisting IPs, subnet-wide restrictions
Monitor with VPC Flow Logs
Document your rules
Follow least privilege principle: only allow required ports/protocols
π§ What I Learned:
Security Groups are simpler and more intuitive for most cases
NACLs provide additional layer of protection and control
Real-world cloud security means using both together
AWS CLI can be used to manage SGs & NACLs via
aws ec2
commands
π§ͺ Bonus CLI Commands:
bashCopyEdit# List all security groups
aws ec2 describe-security-groups
# Add a rule to SG
aws ec2 authorize-security-group-ingress \
--group-id sg-xxxxxxxx \
--protocol tcp --port 80 \
--cidr 0.0.0.0/0
# Create custom NACL
aws ec2 create-network-acl --vpc-id vpc-xxxxxxxx
π Whatβs Next?
Tomorrow (Day 13), Iβll explore VPC Peering β how to connect two separate VPCs together to allow internal communication across accounts or regions!
Subscribe to my newsletter
Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
