Amazon VPC Operations: Subnets, Route Tables, Security Groups, NACLs, NAT, Endpoints and Day-to-Day Management
VPC Building Blocks
| Component | What it does |
| VPC | Isolated virtual network in one Region with a primary IPv4 CIDR (/16 to /28), optional secondary CIDRs and IPv6 |
| Subnet | Range inside one AZ. Public subnet = route to an Internet Gateway. Private subnet = no direct internet route |
| Route table | Rules deciding where traffic goes. Each subnet has exactly one (main table by default). Longest prefix match wins |
| Internet Gateway (IGW) | Two-way internet access for public IPs. Highly available, free |
| NAT gateway | Lets private subnets reach the internet outbound only. Lives in a public subnet, needs an Elastic IP, scales to 100 Gbps, AZ-scoped (one per AZ) |
| Egress-only IGW | Outbound-only for IPv6 |
| Security group | Stateful firewall at the ENI. Allow rules only |
| Network ACL | Stateless firewall at the subnet. Allow and deny rules, numbered, ephemeral ports needed on return |
| VPC endpoint | Private access to AWS services without internet |
| DHCP options, DNS | enableDnsSupport, enableDnsHostnames |
- AWS reserves 5 IPs per subnet (network, router, DNS, future, broadcast)
- Plan non-overlapping CIDRs for all VPCs and on-premises networks you will connect. Overlap blocks peering and Transit Gateway routing
- Reserve space for growth. Use /20 or larger subnets for EKS (pods use VPC IPs)
Typical Three-Tier Layout
text
VPC 10.0.0.0/16
├─ Public subnets 10.0.0.0/24 (AZ-a), 10.0.1.0/24 (AZ-b) → ALB, NAT gateways route 0.0.0.0/0 → IGW
├─ Private app 10.0.10.0/24, 10.0.11.0/24 → EC2/ECS route 0.0.0.0/0 → NAT in same AZ
└─ Private data 10.0.20.0/24, 10.0.21.0/24 → RDS, ElastiCache no internet route
Endpoints: S3 + DynamoDB (gateway), SSM/ECR/Logs (interface)
Route Tables
| Destination | Target | Meaning |
10.0.0.0/16 | local | Traffic inside the VPC (always present) |
0.0.0.0/0 | igw-… | Public subnet: internet |
0.0.0.0/0 | nat-… | Private subnet: outbound via NAT |
10.1.0.0/16 | pcx-… or tgw-… | Peered VPC / Transit Gateway |
192.168.0.0/16 | vgw-… or tgw-… | On-premises |
pl-… (S3 prefix list) | vpce-… | Gateway endpoint route (added automatically) |
bash
aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=prod}]'
aws ec2 modify-vpc-attribute --vpc-id vpc-0abc --enable-dns-hostnames
aws ec2 create-subnet --vpc-id vpc-0abc --cidr-block 10.0.10.0/24 --availability-zone ap-south-1a
aws ec2 create-route --route-table-id rtb-0abc --destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-0abc
aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-0abc
Security Groups vs Network ACLs
| Security group | Network ACL |
| Level | Instance/ENI | Subnet |
| State | Stateful (return traffic automatic) | Stateless (open ephemeral ports 1024-65535 for responses) |
| Rules | Allow only | Allow and Deny, evaluated in number order, first match wins |
| Default | Deny all inbound, allow all outbound | Default NACL allows all. A new custom NACL denies all |
| References | Can reference other security groups | CIDR only |
| Use | Main control | Extra layer, block specific IPs |
- Reference the security group of the app tier in the database rule instead of IP ranges
- Security group changes apply immediately to existing connections of removed rules? New connections are blocked, but tracked existing connections continue until they end
- Never open
0.0.0.0/0 for SSH/RDP. Use Session Manager or EC2 Instance Connect Endpoint
- Use managed prefix lists for repeated CIDR sets
NAT Gateway Operations
- Create one NAT gateway per AZ and route each private subnet to the NAT in its own AZ (avoids cross-AZ cost and AZ dependency)
- Costs: hourly + per GB processed. Reduce with gateway endpoints for S3 and DynamoDB (free) and interface endpoints for heavy services
- Monitor
ErrorPortAllocation (too many connections to one destination), PacketsDropCount, BytesOutToDestination
- NAT instance is a cheaper manual option (disable source/destination check). Not managed or scalable
VPC Endpoints and PrivateLink
| Type | Services | How |
| Gateway endpoint | S3 and DynamoDB only | Route table entry with prefix list, free, regional, not reachable from on-premises or peering |
| Interface endpoint (PrivateLink) | Most AWS services (SSM, ECR, CloudWatch, STS, Secrets Manager, KMS...) and your own or partner services | ENI with private IP in your subnets, hourly + data cost, security group, optional private DNS, reachable from on-premises over VPN/DX |
| Gateway Load Balancer endpoint | Inspection appliances | Route to the endpoint |
| Resource / service-network endpoints | VPC Lattice and resource sharing | Newer options |
- Endpoint policies restrict which principals, actions and resources the endpoint allows (for example only a specific S3 bucket)
- Bucket policies can require
aws:SourceVpce to force access through an endpoint
- Private subnets running SSM need
ssm, ssmmessages, ec2messages endpoints (and logs, monitoring for CloudWatch)
- Enable private DNS and VPC DNS support so default service names resolve to endpoint IPs
VPC Peering
- One-to-one private connection between two VPCs (same or different account/Region)
- No transitive routing (A↔B and B↔C does not give A↔C), no overlapping CIDRs
- Needs accepter approval, routes on both sides, and security group/NACL rules. For many VPCs use Transit Gateway
Other Operational Items
| Item | Notes |
| Elastic IP | Static public IPv4. Public IPv4 addresses are now charged, so release unused ones and prefer IPv6 or private connectivity |
| IPv6 | Dual-stack subnets, every address is public-capable, control with security groups and egress-only IGW |
| VPC sharing (RAM) | Share subnets with other accounts in the organization |
| ENIs and secondary IPs | Move failover addresses between instances |
| Tags and flow logs | Tag network resources, enable flow logs for troubleshooting |
| IPAM | VPC IP Address Manager plans and tracks CIDRs across accounts |
| Default VPC | Created per Region for quick tests. Do not use for production |
| Block Public Access (VPC BPA) | Account-level control of internet gateway traffic |
Common Connectivity Failures
| Symptom | Check in order |
| Public instance unreachable from internet | Public IP/EIP, route to IGW, security group inbound, NACL both directions, OS firewall, service listening |
| Private instance cannot reach the internet | Route 0.0.0.0/0 → NAT, NAT in a public subnet with route to IGW, NAT has EIP, SG outbound, NACL |
| Cannot reach S3 from private subnet | Gateway endpoint route present, endpoint policy, bucket policy aws:SourceVpce, DNS |
| Two VPCs cannot talk | Peering active, routes on both sides, overlapping CIDR, SG referencing peer |
| Name does not resolve | enableDnsSupport/enableDnsHostnames, Route 53 private zone association, resolver rules |
| Intermittent drops through NAT | Port allocation errors, idle timeout (350 s), too many connections |
Practice Tasks
- Build the three-tier VPC with two AZs, an IGW and one NAT per AZ
- Add S3 gateway and SSM interface endpoints and test from a private instance with no NAT
- Compare a security group rule with a NACL rule and prove statefulness
- Peer two VPCs and fix a missing return route
- Review all VPCs for unused NAT gateways and unattached Elastic IPs
Conclusion
Plan non-overlapping CIDRs, separate public, app and data subnets, one NAT per AZ, control traffic with stateful security groups plus optional NACLs, use gateway and interface endpoints to keep traffic private and cut NAT cost, and troubleshoot with the route, security group, NACL and DNS checklist.
Quick Summary: building blocks; layout; routes; SG vs NACL; NAT; endpoints; peering; other items; failures.