Skip to content

Lesson 4 of 9 · 24m

VPC Networking: Subnets, Routes, and the Packet's Point of View

The VPC mental model that explains public versus private subnets, NAT, security groups, NACLs, and flow logs.

Most VPC confusion disappears when you stop reading diagrams as architecture art and start following one packet. An instance has an elastic network interface in exactly one subnet. That subnet has a route table. The route table decides where packets go next; security groups and network ACLs decide whether they are allowed to pass. Everything else is decoration on top of those mechanics.

The public/private distinction is routing

public subnet:  0.0.0.0/0 -> internet gateway
private subnet: 0.0.0.0/0 -> NAT gateway (or no default route)

Putting an instance in a “public subnet” does not inherently expose it. Exposure requires a public IP, a route to the internet gateway, and security-group permission. Conversely, calling a subnet private does not magically protect a service if you attach a load balancer or security group that forwards the world into it.

Security groups and NACLs are different tools

Security groups are stateful and attached to network interfaces. If you allow inbound TCP 443, return traffic is allowed automatically.

aws ec2 authorize-security-group-ingress   --group-id sg-0123456789abcdef0   --ip-permissions IpProtocol=tcp,FromPort=443,ToPort=443,IpRanges='[{CidrIp=10.20.0.0/16}]'

Network ACLs are stateless subnet-level filters. Inbound and outbound rules must both permit the flow, including ephemeral ports. Use NACLs for broad guardrails, not application micro-management; most day-to-day design belongs in security groups.

NAT is the bill and the bottleneck

Private instances often need outbound internet access for package repositories and AWS-adjacent APIs. A NAT gateway gives them that path without inbound exposure, but it charges hourly and per GB. Ten busy private subnets copying artifacts through NAT can become a real line item. Interface VPC endpoints for services such as ECR, SSM, and CloudWatch often cost less than pushing the traffic through NAT.

Debug in layers

aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-abc123
aws ec2 describe-security-groups --group-ids sg-abc123
aws ec2 describe-network-interfaces --filters Name=subnet-id,Values=subnet-abc123

Then enable VPC Flow Logs and ask whether packets were accepted or rejected. REJECT means a security layer said no. ACCEPT with no response means look at routing, application listeners, or the remote end.

Field notes

  • Route tables are subnet-level, not instance-level; two instances in different subnets can behave completely differently.
  • Security groups can reference other security groups, which is usually cleaner than pasting CIDR blocks for internal services.
  • DNS resolution is easy to overlook: private hosted zones must be associated with the VPC that needs the names.
  • Peered VPCs do not support transitive routing; a chain of peering connections is not a network backbone.

Was this lesson helpful?

Sign in to rate