Skip to Content
Asterrr's Handbook
1 · Organizational complexity

VPC fundamentals

Subnets, route tables, internet and NAT gateways, security groups versus network ACLs, flow logs, IPv6, DNS settings and the tools that troubleshoot reachability.

Exam tasks: 1.1 (network design), 2.3 (network security controls), 3.3, 2.4

The decision: which packets may reach which resource, and by which path? Almost every networking question reduces to a route table, a security group, a network ACL, or a gateway that is missing.

A VPC is a private network in one Region that spans its Availability Zones. A subnet lives in exactly one AZ.

AWS RegionVPC 10.0.0.0/16Public subnet, AZ aPrivate subnet, AZ ainboundoutboundLoad balancerNAT gateway,Elastic IPApp instancesInternet gatewayInternet
A VPC across two AZs. Public subnets route to the internet gateway, and private subnets route outbound traffic through a NAT gateway in the same AZ.
/16 to /28
Allowed CIDR block size for a VPC or subnet
5
Addresses AWS reserves in every subnet
Stateful
Security groups return replies automatically. Network ACLs are stateless
1 AZ
A subnet never spans AZs, and a NAT gateway lives in one AZ
/56 and /64
IPv6 block sizes for a VPC and for a subnet

Subnets and routing

  • A subnet is public only because its route table has a route to an internet gateway. A private subnet has no such route.
  • Each subnet uses one route table. The local route covers the VPC CIDR and cannot be removed. The most specific route wins, and for equal prefixes a static route beats a propagated one.
  • AWS reserves the first four addresses and the last address of each subnet, so a /28 has 11 usable addresses.
  • You can add secondary CIDR blocks to a VPC. You cannot resize the primary one.
  • Gateway route tables let you steer inbound traffic through a security appliance by attaching a route table to an internet gateway or virtual private gateway.
  • Managed prefix lists group CIDRs into one named object for route tables and security groups, and can be shared with AWS RAM.

Getting traffic out

GatewayForRemember
Internet gatewayTwo-way internet access for resources with a public or Elastic IPHorizontally scaled and not a single point of failure
NAT gatewayOutbound IPv4 from private subnetsLives in a public subnet with an Elastic IP, scoped to one AZ. Create one per AZ and route each AZ's private subnets to its own
Egress-only internet gatewayOutbound-only IPv6The IPv6 equivalent of NAT, with no inbound connections
Gateway endpointS3 and DynamoDBRoute-table based and free
Interface endpoint (PrivateLink)Most other AWS services and your own servicesAn ENI with private IPs, charged per hour and GB

One NAT gateway for every AZ

A single NAT gateway makes every private subnet depend on one AZ, and it adds cross-AZ data charges. For resilience, deploy a NAT gateway in each AZ that has private subnets.

Security groups versus network ACLs

Security groupNetwork ACL
Applies toAn ENI, so an instance or resourceA subnet
StateStatefulStateless: allow the return traffic yourself
RulesAllow onlyAllow and deny
EvaluationAll rules togetherIn number order, first match wins
DefaultDeny inbound, allow outbound. The default group allows traffic from itselfThe default NACL allows all. A custom NACL denies all until you add rules
ReferencesCan reference another security groupCIDR ranges only
  • A network ACL needs ephemeral port rules (1024 to 65535) for return traffic, because it does not track connections.
  • To block one abusive IP address, use a network ACL deny or AWS WAF. A security group cannot deny.
  • Reference a security group ID instead of CIDR blocks between tiers, so rules follow instances as they scale.

Exam signal

"Block a specific IP range" means network ACL (or WAF). "Allow the web tier to talk to the app tier and nothing else" means security groups that reference each other.

Seeing and testing the network

  • VPC Flow Logs record metadata for accepted and rejected traffic at a VPC, subnet or interface, and publish to CloudWatch Logs, S3 or Data Firehose. They do not record traffic to the Amazon DNS server, the instance metadata address, DHCP, or the Windows license server.
  • Reachability Analyzer analyzes the configuration between two points and shows which component blocks the path, without sending packets.
  • Network Access Analyzer finds unintended access paths, for example resources reachable from the internet.
  • Traffic Mirroring copies packets from a Nitro instance's interface to an appliance, for inspection and forensics.
  • VPC IPAM plans, tracks and allocates CIDR blocks across accounts and Regions, and finds overlaps.

DNS and IP settings

  • enableDnsSupport turns on the Amazon-provided resolver. enableDnsHostnames gives instances DNS names. Both are needed for private hosted zones and for private DNS on interface endpoints.
  • DHCP option sets set the domain name and DNS servers handed to instances, such as on-premises resolvers.
  • An Elastic IP is a static public IPv4 address you can move between instances, and AWS charges for public IPv4 addresses.
  • An ENI can hold several private IPs, move between instances in the same AZ, and keeps its MAC address and security groups.
  • Dual-stack subnets add IPv6, and IPv6 addresses are public, so security groups and ACLs must allow only what you intend.

Scenarios

Scenario
Instances in a private subnet cannot download patches from the internet. A NAT gateway exists in the same VPC and the private route table sends 0.0.0.0/0 to it. Reachability Analyzer shows the path stops at the NAT gateway. What is the most likely cause?
Scenario
A web server accepts HTTPS from the internet. The security group allows inbound 443. Clients still cannot connect. The subnet uses a custom network ACL that allows inbound 443 from anywhere and has no outbound rules except the default deny. What is wrong?
Scenario
A security team must block a single abusive IPv4 address range from reaching a public web tier in a subnet, immediately and without touching each instance. Which control fits?

Further reading

On this page