skip to content

Search

Syspirit
EN

AWS VPC

AWS networking: addressing, routing, filtering and interconnection of a VPC!

AWS
Published on
Karl Certa

Amazon VPC (Virtual Private Cloud) is an isolated virtual network in an AWS Region: you choose its address range, how it is split into subnets, its routing and its filtering.

🧭 Which component for which need

📌 Need☁️ Service to use
🌍 Expose a server on the InternetPublic subnet + Internet Gateway + public IP
🔄 Give a private subnet outbound Internet accessNAT Gateway
🌐 IPv6 outbound without inbound connectionsEgress-only Internet Gateway
🪣 Reach S3 or DynamoDB without the InternetGateway Endpoint
🔌 Reach another AWS service without the InternetInterface Endpoint
🤝 Connect a few VPCs togetherVPC Peering
🚉 Connect many VPCs, VPNs and Direct ConnectTransit Gateway
🏢 Connect a remote site quicklySite-to-Site VPN
📡 High throughput and stable latency to the datacenterDirect Connect (VPN as backup)
⛔ Block a specific IPDeny rule in a NACL
🔍 Understand why a flow is rejectedVPC Flow Logs

📐 Addressing and sizes

CIDR (Classless Inter-Domain Routing) notation describes an address range: the longer the prefix, the smaller the range.

📌 Item📊 Value💡 Consequence
📏 VPC size (IPv4)From /16 (65,536 IPs) to /28 (16 IPs)An existing block cannot be resized: add a secondary block instead
➕ IPv4 CIDR blocks per VPC5 by default, adjustable up to 50The primary block counts toward the quota and cannot be removed
🏠 Private ranges (RFC 1918)10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16RFC 1918 defines the private ranges, not routed on the Internet
🚫 Range to avoid172.17.0.0/16Used by some AWS services (Cloud9, SageMaker AI): address conflicts
🔲 Subnet size (IPv4)From /16 to /28A subnet lives in a single AZ (Availability Zone, isolated datacenter within the Region)
🔢 Subnets per VPC200 by default, adjustablePlan at least one subnet per AZ and per tier (public, private)
🌍 VPCs per Region5 by default, adjustableRaising this quota raises the Internet Gateway quota by the same amount
🎁 Default VPC172.31.0.0/16, one /20 subnet per AZAll its subnets are public: handy for testing, avoid in production

🔢 Reserved IPs per subnet

AWS reserves 5 addresses in every subnet: the first 4 and the last one. Example with 10.0.0.0/24:

📌 Address📊 Role
10.0.0.0Network address
10.0.0.1VPC router
10.0.0.2Reserved by AWS (Amazon DNS answers on the VPC base address + 2)
10.0.0.3Reserved by AWS for future use
10.0.0.255Broadcast: not supported in a VPC, reserved anyway

Consequence: a /28 only offers 11 usable addresses and a /24 offers 251. Interface endpoints and Transit Gateway attachments also take an IP in the subnet: an undersized subnet quickly blocks deployments.

🌐 Public or private subnet

A subnet’s type depends only on its route table.

📌 Type🛣️ Routes to📊 Typical use
🌍 PublicIGW (Internet Gateway)Internet-facing load balancer, bastion, zonal NAT Gateway
🔒 PrivateNAT Gateway, or no direct Internet exitApplication servers, databases
🏢 VPN-onlyVGW (Virtual Private Gateway) to the remote siteResources reachable only from the internal network
🧊 IsolatedNo destination outside the VPCResources that only talk to the VPC
📌 Requirement to reach the Internet📊 Detail
🚪 IGW attached to the VPCOne IGW per VPC; free, redundant, no bandwidth constraint
🛣️ Route to the IGW0.0.0.0/0 (IPv4) or ::/0 (IPv6) in the subnet’s route table
🏷️ Public addressPublic IP or EIP (Elastic IP, fixed public address): without it, no Internet even in a public subnet
🛡️ FilteringThe Security Group and the NACL must allow the flow
💶 Public IPv4 costBilled hourly, whether attached or idle

🛣️ Route tables

📌 Item📊 Behavior
🗺️ Main route tableCreated with the VPC, applies to any subnet without an explicit association
🔗 AssociationA subnet has a single table; one table can serve several subnets
🏠 local routeCovers the VPC CIDR: all subnets reach each other without any added route
🎯 PriorityThe most specific route wins (longest prefix match): /32 beats /24
⚖️ Identical destinationA static route takes priority over a route propagated by VPN or Direct Connect
📏 Routes per table500 by default (excluding propagated routes), adjustable up to 1,000

Consequence: a subnet created without an association inherits the main route table. If that table routes to the IGW, the subnet becomes public without anyone deciding it.

🚪 NAT Gateway

NAT (Network Address Translation) lets private resources open outbound connections without being reachable from outside.

📌 Item📊 Value
🏗️ Zonal NAT GatewayCreated in a public subnet with an EIP, redundant within its AZ only
🌐 Regional NAT GatewayNo public subnet required, expands on its own to AZs that have resources (up to 60 min)
🚀 Bandwidth5 Gbps, scales automatically up to 100 Gbps
🔌 Connections55,000 simultaneous per IP to a single destination (IP, port, protocol)
🛡️ Security GroupCannot be attached: filter on the instances and in the NACL
🔁 Source ports1024-65535, to allow in the NACL
🚫 From a peered VPCA peered VPC cannot exit through another VPC’s NAT Gateway
🌐 IPv6 equivalentEgress-only Internet Gateway: free, stateful, blocks inbound connections
🧓 NAT instanceSelf-managed EC2, source/destination check must be disabled, AWS NAT AMI no longer maintained

High availability rule in zonal mode: one NAT Gateway per AZ, and each private subnet routes to the one in its own AZ. With a single NAT Gateway, an outage of its AZ cuts Internet access for all the others. Regional mode solves this but does not handle private NAT and is billed for each AZ it covers.

🛡️ Security Group or NACL

The SG (Security Group) filters at the ENI level (Elastic Network Interface, virtual network card); the NACL (Network Access Control List) filters what enters and leaves the subnet.

📌 Criterion🛡️ Security Group🧱 NACL
📍 LevelResource (ENI)Subnet
✅ Rule typesAllow onlyAllow and Deny
🔄 StateStateful: the response is allowed automaticallyStateless: the response needs its own rule
🔢 EvaluationAll rules before decidingBy ascending number, stops at the first match
🎁 Defaultdefault SG: inbound from the same SG, all outboundDefault NACL: all allowed; new NACL: all denied
🎯 Possible sourceCIDR, prefix list or another SGCIDR only
📏 Default quotas60 inbound and 60 outbound rules; 5 SGs per ENI (up to 16)20 rules per direction, adjustable up to 40
🔗 AssociationSeveral SGs per resourceOne NACL per subnet, shareable across subnets

Neither the SG nor the NACL filters Amazon DNS, DHCP, instance metadata or the Time Sync Service. AWS recommends the SG as the primary control and the NACL as a subnet-level guardrail.

🔌 VPC Endpoints

An endpoint gives access to AWS services without an IGW or NAT: traffic stays on the AWS network.

📌 Criterion🚪 Gateway Endpoint🔌 Interface Endpoint
🎯 ServicesS3 and DynamoDB onlyMost AWS services through PrivateLink, including S3 and DynamoDB
⚙️ MechanismRoute to a prefix list added to the route tableENI with a private IP, one subnet per AZ
💶 CostFreeBilled per hour per AZ and per GB processed
🏢 Access from the site (VPN, Direct Connect)NoYes
🔗 Access from another VPCNo (a peered VPC cannot use it)Yes, through peering or Transit Gateway

Rule for S3: Gateway Endpoint for traffic inside the VPC, Interface Endpoint for traffic coming from the remote site. Both can coexist in the same VPC.

🔗 VPC Peering or Transit Gateway

📌 Criterion🤝 VPC Peering🚉 Transit Gateway (TGW)
🧩 Model1-to-1 link between two VPCsCentral regional virtual router
🔁 TransitivityNone: A-B and B-C do not give A-CYes, according to the TGW route tables
🧮 Links for n fully meshed VPCsn(n-1)/2 (10 VPCs = 45 peerings)One attachment per VPC
🌍 ScopeSame Region, inter-Region, cross-accountRegional, TGW peering across Regions, sharing through RAM (Resource Access Manager)
🔌 Other attachmentsNone: no access to the peer’s IGW, NAT, VPN or Direct ConnectVPN, Direct Connect gateway, other TGWs
🧱 SegmentationThrough the choice of links createdSeveral route tables (isolate DEV and PROD)
🚀 ThroughputNo bottleneck and no single point of failureUp to 100 Gbps per VPC attachment per AZ
💶 CostFree to create; free traffic within an AZ, charged across AZs and RegionsPer attachment hour and per GB processed
📏 Default quota50 active peerings per VPC, adjustable up to 1255,000 attachments per TGW, adjustable

Peering rule: CIDRs must not overlap, even partially (hence the value of a shared addressing plan). After acceptance, add the route to the remote CIDR on both sides, otherwise nothing gets through. Within the same Region, an SG can reference an SG from the peer VPC.

🏢 Hybrid connectivity

📌 Criterion🔐 Site-to-Site VPN📡 Direct Connect (DX)
🛤️ TransportIPsec tunnels over the InternetPrivate physical link from a Direct Connect location
🔒 EncryptionYes (IPsec)Not by default: MACsec on 10, 100 or 400 Gbps dedicated ports (selected sites), or VPN on top
🚀 Throughput2 tunnels per connection, up to 1.25 Gbps per tunnel (5 Gbps with Large Bandwidth Tunnel on TGW)Dedicated: 1, 10, 100 or 400 Gbps; hosted by a partner: 50 Mbps to 25 Gbps
⏱️ SetupA few minutesPhysical circuit to order (AWS port, cross-connect, carrier)
📉 LatencyDepends on the InternetStable
🧱 AWS sideVGW (one VPC) or TGW (several VPCs, ECMP to add up tunnels)Private, public or transit VIF (Virtual Interface)

ECMP (Equal-Cost Multi-Path) spreads traffic over several active tunnels, provided dynamic BGP (Border Gateway Protocol) routing is used. The Direct Connect gateway, a global resource, connects one DX connection to VPCs in several Regions without allowing traffic between those VPCs. Robust design: DX as the primary link, VPN as backup, with AWS always preferring the DX path when it is up.

📜 VPC Flow Logs

📌 Item📊 Detail
🎯 LevelVPC, subnet or ENI (including those of a load balancer, a NAT Gateway or a TGW)
🔎 FilterAccepted traffic, rejected traffic, or both
📦 DestinationsCloudWatch Logs, S3 (SQL queries with Athena), Data Firehose
⏱️ DelayNot real time: several minutes before the first records
⚡ Network impactNone: collection happens outside the traffic path
✏️ ChangesNot possible after creation: delete and recreate
🙈 Not capturedAmazon DNS, DHCP, 169.254.169.254 metadata, 169.254.169.123 Time Sync, ARP
💶 CostCloudWatch “vended logs” pricing (ingestion and archival)

Typical use: a flow marked REJECT points to an overly restrictive SG or NACL; enabling the “rejected” filter on the subnet in question gives the answer without a packet capture.

Related posts