📅 Day 14 | AWS NACL — Subnet-Level Security in AWS 🔐

Published: (December 12, 2025 at 12:56 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

Overview

  • Subnet‑level firewall – attached to a subnet, not to individual EC2 instances.
  • Stateless – inbound and outbound rules are evaluated independently; you must allow return traffic explicitly.
  • Supports ALLOW and DENY rules – rule order matters (lowest number evaluated first).
  • Default NACL – allows all traffic.
  • Custom NACL – denies all traffic unless explicitly allowed.

Key Features

FeatureDescription
Layer of protectionSecures public and private subnets (e.g., web servers, databases, EKS nodes).
Stateless filteringRequires matching inbound and outbound rules for two‑way communication.
Rule typesBoth ALLOW and DENY entries are possible.
Rule precedenceRules are processed in ascending order of rule number (e.g., 100 → 101 → 102…).
Default behaviorDefault NACL permits all traffic; custom NACLs start with a deny‑all stance.

How NACL Works

  1. Attachment – A NACL is associated with one or more subnets.
  2. Stateless nature – If you allow inbound traffic on a port, you must also create a corresponding outbound rule for the response traffic.
  3. Rule evaluation – The first rule that matches the traffic (by rule number) determines the action.
  4. Default vs. custom – The default NACL allows everything; a custom NACL must explicitly allow desired traffic and will implicitly deny the rest.

Example Scenarios

Public Subnet

ResourceAllowed Traffic
EC2 web serverHTTP (80), HTTPS (443), SSH (22)
Application Load BalancerSame as above

Private Subnet

ResourceAllowed Traffic
Application serverInternal traffic to database (3306)
DatabaseAccepts traffic from app subnet on 3306
EKS worker nodesNode‑to‑node communication within the subnet
NoteNo direct internet access; all inbound/outbound traffic is filtered.

Comparison with Security Groups

AspectSecurity GroupNACL
ScopeInstance levelSubnet level
StatefulnessStateful (return traffic automatically allowed)Stateless (return traffic must be allowed explicitly)
Rule typesOnly ALLOWALLOW and DENY
ManagementSimpler for instance‑specific rulesUseful for high‑level subnet control

Sample Rule Set

Rule NoDirectionProtocolPort RangeSource/DestinationAction
100InboundTCP800.0.0.0/0ALLOW
110InboundTCP4430.0.0.0/0ALLOW
120InboundTCP220.0.0.0/0ALLOW
1000OutboundALLALL0.0.0.0/0ALLOW
*****DENY (implicit)

Tip: Adjust vpc_id, CIDR blocks, and rule numbers to match your environment.

Terraform Example

resource "aws_network_acl" "public_nacl" {
  vpc_id = aws_vpc.main.id
  tags = {
    Name = "public-nacl"
  }
}

resource "aws_network_acl_rule" "allow_http_in" {
  network_acl_id = aws_network_acl.public_nacl.id
  rule_number    = 100
  egress         = false
  protocol       = "6"   # TCP
  rule_action    = "allow"
  cidr_block     = "0.0.0.0/0"
  from_port      = 80
  to_port        = 80
}

resource "aws_network_acl_rule" "allow_https_in" {
  network_acl_id = aws_network_acl.public_nacl.id
  rule_number    = 110
  egress         = false
  protocol       = "6"
  rule_action    = "allow"
  cidr_block     = "0.0.0.0/0"
  from_port      = 443
  to_port        = 443
}

resource "aws_network_acl_rule" "allow_ssh_in" {
  network_acl_id = aws_network_acl.public_nacl.id
  rule_number    = 120
  egress         = false
  protocol       = "6"
  rule_action    = "allow"
  cidr_block     = "0.0.0.0/0"
  from_port      = 22
  to_port        = 22
}

resource "aws_network_acl_rule" "allow_all_out" {
  network_acl_id = aws_network_acl.public_nacl.id
  rule_number    = 1000
  egress         = true
  protocol       = "-1"  # all protocols
  rule_action    = "allow"
  cidr_block     = "0.0.0.0/0"
  from_port      = 0
  to_port        = 0
}

References & Further Reading

  • GitHub repository:
  • Dev.to blog post:
  • LinkedIn article:
  • Resume (Google Drive): (optional)
Back to Blog

Related posts

Read more »

The Vibe Coding Paradox

My last PR for Nudges was +96 −312, touched 38 files, and was about 90 % vibe‑coded. I’m confident in it. While I was gliding through Hyrule, two different AI a...

Printable Flashcard Generator

Introduction Are you a visual learner? Have you ever used image‑based flashcards to memorize words or concepts more effectively? If so, you might find this pro...