Skip to main content

πŸ”’ 04. Network Security in a VPC

In AWS, network security within a VPC (Virtual Private Cloud) is controlled primarily by two mechanisms:

  • Network ACLs (NACLs) β€” subnet-level firewalls
  • Security Groups β€” instance-level firewalls

Both play different roles in protecting resources like EC2 instances within your VPC.


1. Network ACL (NACL)​

A Network Access Control List (NACL) is a firewall that operates at the subnet level.

A network access control list (network ACL) contains a numbered list of rules and evaluates these rules in the increasing order while deciding whether to allow the traffic

It controls traffic from and to subnet. NACL is stateless i.e. return traffic must be explicitly allowed

PropertyDescription
LevelSubnet
Rules TypeALLOW and DENY
StatelessReturn traffic must be explicitly allowed
AssociationOne NACL per subnet (can be shared by multiple subnets)
Rule ScopeBased on IP addresses
Default BehaviorDefault NACL allows all inbound and outbound traffic

🧩 Example​

When a packet enters a subnet:

  1. It’s first evaluated by the NACL rules.
  2. If allowed, it proceeds to the EC2 instance’s security group.

Diagram (placeholder): Internet β†’ NACL (Subnet-level filter) β†’ Security Group β†’ EC2 Instance


2. Security Group​

A Security Group acts as a virtual firewall for EC2 instances, controlling inbound and outbound traffic. It's statefull, return traffic is auto allowed.

PropertyDescription
LevelInstance
Rules TypeALLOW only
StatefulReturn traffic is automatically allowed
Rule ScopeIP addresses and other security groups
Default BehaviorBy default, all inbound traffic is denied; all outbound traffic is allowed

Comparison: NACL vs Security Group​

FeatureNetwork ACLSecurity Group
LevelSubnetInstance
Rule TypesALLOW & DENYALLOW only
StatefulnessStatelessStateful
Return TrafficMust be explicitly allowedAutomatically allowed
ScopeApplies to all resources in the subnetApplies to specific instances
Evaluation OrderRules processed in numerical orderAll rules evaluated together

Example: Default NACL Rules​

Rule #TypeProtocolPort RangeSourceAction
100ALLALLALL0.0.0.0/0ALLOW
*ALLALLALLALLDENY

πŸ“Œ Explanation:

  • Rule 100 allows all inbound traffic.
  • The β€˜*’ rule is the implicit DENY for all other unmatched traffic.