Showing raw Markdown: the renderer could not load.
## Why this matters
A start-up moves its shop to the cloud. A developer launches the web servers and the database in the provider's default network, gives every machine a public address "to make it work" and opens the database port to `0.0.0.0/0` while testing. Nobody closes it. Months later, the database is full of strangers' queries. The servers were never the problem: the **network design** was.
The opposite failure is just as common. A team builds a tidy private network, but the application servers can't download a security patch, because nobody gave them a route out. Or two teams each create a network with the range `10.0.0.0/16`, and later find they can never be connected, because their addresses overlap. In the cloud you never touch a cable, but you still design address ranges, subnets, routes and firewalls, and a wrong route or an over-open rule is behind most networking incidents. This lesson maps the networking you already know (subnetting and routing) onto cloud virtual networks.
## Learning objectives
- Design a virtual network (VPC) with public and private subnets across availability zones, choosing non-overlapping address ranges.
- Explain how route tables, the Internet gateway and the NAT gateway decide where traffic goes.
- Compare stateful security groups with stateless network access control lists (ACLs), and write rules for a two-tier application.
- Explain how virtual networks are connected (peering, transit hubs, VPN) and why peering is not transitive.
- Troubleshoot reachability problems caused by routes, NAT or filtering rules.
## Key concepts
### A virtual network is a private address space in software
Think of renting a floor in a large office building. The building is shared, but your floor has its own walls, its own door and its own internal phone numbers. A **virtual network** is that floor: a private, isolated network that you define inside the provider's shared infrastructure. Providers call it a **virtual private cloud (VPC)** or a **virtual network (VNet)**. This lesson uses "VPC" as the generic word.
You define the VPC by giving it one or more **Classless Inter-Domain Routing (CIDR)** blocks, for example `10.20.0.0/16`. Everything you launch inside it (virtual machines, containers, databases, load balancers) gets a private address from that range. Nothing outside can reach those addresses unless you build a path on purpose. Underneath, the provider's **software-defined network (SDN)** carries your packets over its physical network, and keeps your traffic separate from other customers' traffic. You can't see or change that layer. What you control is the logical layer: ranges, subnets, routes, gateways and filters.
Everything you learned in [Networking 06 — Subnetting](../../networking/06-subnetting/README.md) and [Networking 10 — Routing Fundamentals](../../networking/10-routing-fundamentals/README.md) still applies: addresses, prefixes, longest prefix match, default routes and Network Address Translation (NAT). The cloud gives you the same ideas as API objects instead of devices.
> [!NOTE]
> Terms differ by provider. The table below maps the generic words used in this lesson to three well-known providers. Names and features change over time, so check the provider's documentation before you rely on one. Many OpenStack-based clouds use the plain words network, subnet, router and security group for the same ideas.
| Generic term | AWS | Microsoft Azure | Google Cloud |
|---|---|---|---|
| Virtual network | VPC | Virtual Network (VNet) | VPC network |
| Route table | Route table | Route table (user-defined routes) | Routes (per VPC network) |
| Internet gateway | Internet gateway | No separate object: system routes and public IP addresses | No separate object: default route to the default Internet gateway |
| NAT gateway | NAT gateway | NAT Gateway | Cloud NAT |
| Instance-level filter (stateful) | Security group | Network security group (NSG) | VPC firewall rules |
| Subnet-level filter (stateless) | Network ACL | No stateless equivalent | No stateless equivalent |
| Peering | VPC peering | Virtual network peering | VPC Network Peering |
| Transit hub | Transit gateway | Virtual WAN, or a hub VNet | Network Connectivity Center |
| Site-to-site VPN | Site-to-Site VPN | VPN Gateway | Cloud VPN |
> [!CHECK]
> What does a VPC give you that "a set of virtual machines" does not?
>
> - [ ] A faster physical network that only your machines use
> - [x] A private, logically isolated address space that you design: ranges, subnets, routes and filters
> - [ ] Automatic encryption of all traffic between your machines
> - [ ] A public address for every machine inside it
>
> A VPC is a software-defined, isolated network built on shared hardware. It doesn't change the speed of the underlying network, and encryption and public addresses are things you choose separately.
### Choosing address ranges (CIDR blocks)
The CIDR block is the one decision that is painful to change later, so choose it first and with care. Use the **private** ranges from RFC 1918 (the same ones as at home or in an office):
| Range | Size | Typical use |
|---|---|---|
| `10.0.0.0/8` | 16.8 million addresses | Large organizations: plenty of room to carve out many VPCs |
| `172.16.0.0/12` | 1 million addresses | Medium networks (`172.16.0.0` to `172.31.255.255`) |
| `192.168.0.0/16` | 65,536 addresses | Small networks and home routers: easy to overlap with a laptop's home network |
Your VPC range must **not overlap** with anything you might ever connect to: other VPCs (to peer them), your on-premises network (to join them with a VPN) and your partners. Two networks that use the same range can't be joined, because a router can't tell which `10.20.5.7` you mean. So keep one address plan for the whole organization, and give each VPC its own slice, for example `10.20.0.0/16` for production in one region, `10.21.0.0/16` for staging, and so on. Leave unused space between them.
How big should a VPC be? A `/16` has 65,536 addresses, which is the same as 256 subnets of `/24`. Most teams pick a `/16` because subnets can't be resized in place, and a VPC that is too small forces a painful migration. Providers limit the prefix sizes you may use, and some let you add more CIDR blocks later. Check their documentation.
> [!NOTE]
> Each subnet loses a few addresses to the provider. Besides the network and broadcast addresses, a provider typically reserves addresses for its virtual router, DNS and future use. The number differs by provider (commonly four or five), so don't assume that a `/24` gives you 254 usable addresses, and don't create subnets so small that the reservations matter. The ranges `100.64.0.0/10` (RFC 6598, shared address space for carrier-grade NAT) are not private addresses in the RFC 1918 sense: use them in a VPC only if the provider's documentation says you can.
> [!CHECK]
> Team A built a VPC with `10.20.0.0/16`. Team B wants to peer its own network with it, but already uses `10.20.64.0/18`. What is the problem?
>
> - [ ] `/18` is too small to be peered
> - [ ] Peering only works between networks in the same region
> - [x] The ranges overlap, so a router can't tell which `10.20.64.x` host a packet is for
> - [ ] Only networks that use `192.168.0.0/16` can be peered
>
> `10.20.64.0/18` lies inside `10.20.0.0/16`. Overlapping ranges can't be routed between: you must re-address one network before connecting them.
### Subnets, availability zones, public and private
A VPC is divided into **subnets**, each with its own CIDR block carved from the VPC range. You place every resource in a subnet. Subnets matter for two reasons:
- **Availability.** A region has several **availability zones (AZs)**: separate data centres that fail independently. To survive the loss of one, you spread the application over at least two AZs, with one set of subnets per AZ.
- **Exposure.** Subnets are the unit to which you attach a route table and, optionally, a network ACL. Putting things that must face the Internet in one kind of subnet and things that must not in another is the simplest way to limit the damage of a mistake.
The two kinds of subnet are defined by their routes, not by a checkbox:
- A **public subnet** has a route to an **Internet gateway**. Its resources can be reached from the Internet if they also have a public address and the filters allow it. Typical residents: load balancers and NAT gateways.
- A **private subnet** has no route from the Internet to its resources, and no direct route out. Its resources can still start connections to the Internet through a **NAT gateway**. Typical residents: application servers and databases.
<figure class="diagram" style="--dg-w: 1100px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1100 604" width="1100" height="604" role="img" aria-labelledby="vnet-vpc-overview-title vnet-vpc-overview-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="vnet-vpc-overview-title">A virtual network with public and private subnets in two availability zones</title>
<desc id="vnet-vpc-overview-desc">A VPC with the range 10.20.0.0/16 spans two availability zones, A and B. An Internet gateway connects the VPC to the Internet and feeds the two public subnets. Public subnet 10.20.1.0/24 in zone A and public subnet 10.20.2.0/24 in zone B each hold a NAT gateway and a load balancer. Private subnet 10.20.11.0/24 in zone A and 10.20.12.0/24 in zone B each hold an app server and a database. In each zone, the app server's default route 0.0.0.0/0 points to the NAT gateway in the public subnet of the same zone, so private servers can start connections to the Internet but the Internet cannot start connections to them.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1099" height="603" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="480" y="6" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(535 16) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g></g>
<text x="550" y="66" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Internet</text>
<g class="dg-l1"><path class="dg-stroke" d="M550 80V104" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><rect class="dg-tint" x="20" y="134" width="1060" height="456" rx="16" fill="#f0f6f9" stroke="#9ac3d9" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(36 147) scale(0.7500)" fill="none" stroke="#0369a1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g>
<text x="62" y="161" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700">Virtual network (VPC) 10.20.0.0/16</text></g>
<rect class="dg-card" x="465" y="100" width="170" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(535 110) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g></g>
<text x="550" y="160" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Internet gateway</text>
<g class="dg-l1"><path class="dg-stroke" d="M550 174V190" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M290 190H810" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M290 190V240" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M284 231l6 8 6-8" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M810 190V240" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M804 231l6 8 6-8" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l4"><rect class="dg-tint" x="40" y="198" width="500" height="376" rx="16" fill="#fbf4f0" stroke="#e7b39e" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(56 211) scale(0.7500)" fill="none" stroke="#c2410c" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></g>
<text x="82" y="225" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Availability zone A</text></g>
<g class="dg-l2"><rect class="dg-tint" x="60" y="242" width="460" height="150" rx="16" fill="#f1f7f3" stroke="#a1ccb1" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(76 255) scale(0.7500)" fill="none" stroke="#15803d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="102" y="269" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Public subnet 10.20.1.0/24</text></g>
<rect class="dg-card" x="105" y="288" width="150" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(165 298) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g></g>
<text x="180" y="348" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">NAT gateway</text>
<text x="180" y="367" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">nat-a</text>
<rect class="dg-card" x="325" y="288" width="150" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(385 298) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="400" y="348" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Load balancer</text>
<g class="dg-l7"><rect class="dg-tint" x="60" y="414" width="460" height="144" rx="16" fill="#f6f2fd" stroke="#c5a9f0" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(76 427) scale(0.7500)" fill="none" stroke="#6d28d9" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></g>
<text x="102" y="441" font-size="13" class="dg-ink" fill="#6d28d9" font-weight="700">Private subnet 10.20.11.0/24</text></g>
<rect class="dg-card" x="105" y="456" width="150" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(165 466) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="180" y="516" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">App server</text>
<rect class="dg-card" x="325" y="456" width="150" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(385 466) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/></g></g>
<text x="400" y="516" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Database</text>
<g class="dg-l7"><path class="dg-stroke" d="M130 456V366" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><path class="dg-stroke" d="M124 371l6-8 6 8" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><rect class="dg-bg-plain" x="70.675" y="398" width="118.65" height="24" rx="12" fill="#ffffff"/><text x="130" y="414.5" font-size="11" class="dg-ink" fill="#6d28d9" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0.0.0.0/0 → NAT</text></g>
<path class="dg-line" d="M255 493H325" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l4"><rect class="dg-tint" x="560" y="198" width="500" height="376" rx="16" fill="#fbf4f0" stroke="#e7b39e" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(576 211) scale(0.7500)" fill="none" stroke="#c2410c" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></g>
<text x="602" y="225" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Availability zone B</text></g>
<g class="dg-l2"><rect class="dg-tint" x="580" y="242" width="460" height="150" rx="16" fill="#f1f7f3" stroke="#a1ccb1" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(596 255) scale(0.7500)" fill="none" stroke="#15803d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="622" y="269" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Public subnet 10.20.2.0/24</text></g>
<rect class="dg-card" x="625" y="288" width="150" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(685 298) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g></g>
<text x="700" y="348" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">NAT gateway</text>
<text x="700" y="367" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">nat-b</text>
<rect class="dg-card" x="845" y="288" width="150" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(905 298) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="920" y="348" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Load balancer</text>
<g class="dg-l7"><rect class="dg-tint" x="580" y="414" width="460" height="144" rx="16" fill="#f6f2fd" stroke="#c5a9f0" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(596 427) scale(0.7500)" fill="none" stroke="#6d28d9" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></g>
<text x="622" y="441" font-size="13" class="dg-ink" fill="#6d28d9" font-weight="700">Private subnet 10.20.12.0/24</text></g>
<rect class="dg-card" x="625" y="456" width="150" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(685 466) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="700" y="516" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">App server</text>
<rect class="dg-card" x="845" y="456" width="150" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(905 466) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/></g></g>
<text x="920" y="516" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Database</text>
<g class="dg-l7"><path class="dg-stroke" d="M650 456V366" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><path class="dg-stroke" d="M644 371l6-8 6 8" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><rect class="dg-bg-plain" x="590.675" y="398" width="118.65" height="24" rx="12" fill="#ffffff"/><text x="650" y="414.5" font-size="11" class="dg-ink" fill="#6d28d9" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0.0.0.0/0 → NAT</text></g>
<path class="dg-line" d="M775 493H845" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
</svg></figure>
*Figure 1. Two availability zones, each with a public and a private subnet. The Internet gateway feeds the public subnets; the private subnets reach the Internet only through the NAT gateway in their own zone.*
A habit that pays off is a regular numbering scheme. In Figure 1, `10.20.1.0/24` and `10.20.2.0/24` are public, `10.20.11.0/24` and `10.20.12.0/24` are private: the third octet tells you the kind of subnet and the zone at a glance. Leave gaps for future subnets (for example a third AZ, or a separate tier for databases).
> [!NOTE]
> How subnets map to zones differs. In some providers (AWS) a subnet lives in exactly one AZ, so you create one subnet per zone, as in Figure 1. In others (Google Cloud, Azure) a subnet isn't tied to a single zone, and you spread resources over zones inside it. The design goal is the same: no single zone failure should take the application down.
> [!CHECK]
> What makes a subnet "public"?
>
> - [ ] Its CIDR block is a public (non-RFC 1918) range
> - [ ] It was created in the first availability zone
> - [x] Its route table has a route to an Internet gateway
> - [ ] It contains at least one server with a firewall rule open to everyone
>
> Public and private are properties of the subnet's routes. A private-range subnet becomes public the moment its route table points to the Internet gateway.
### Route tables and gateways
Inside the VPC you don't run routing protocols. You attach a **route table** to each subnet: a list of `destination prefix → target` entries. As in [Networking 10](../../networking/10-routing-fundamentals/lesson.md), the **longest prefix match** wins. Every route table has an implicit **local route** for the VPC's own range: it covers every address in the VPC, you can't delete it, and it is why all subnets can reach each other by default.
The target of the default route `0.0.0.0/0` is what makes a subnet public or private:
| Gateway | What it does | Direction |
|---|---|---|
| **Internet gateway** | Connects the VPC to the Internet. For resources with a public address, it translates between the public and the private address (1:1 NAT), in both directions. | Inbound and outbound |
| **NAT gateway** | Lets resources with only private addresses start connections to the Internet. It translates many private addresses to one public address (the many-to-one NAT you know as PAT) and sends replies back. | Outbound only |
<figure class="diagram" style="--dg-w: 1060px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1060 352" width="1060" height="352" role="img" aria-labelledby="vnet-route-tables-title vnet-route-tables-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="vnet-route-tables-title">Route tables: local route plus a default route</title>
<desc id="vnet-route-tables-desc">Two route tables. The route table of the public subnets has 10.20.0.0/16 to local and 0.0.0.0/0 to igw-1, the Internet gateway. The route table of the private subnets has 10.20.0.0/16 to local and 0.0.0.0/0 to nat-a, the NAT gateway. For each table, a packet to 10.20.11.5 matches both routes and the longer prefix, the /16 local route, wins, so it stays inside the VPC. A packet to 203.0.113.7 matches only 0.0.0.0/0, so it goes to the default route's target.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1059" height="351" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="30" y="24" width="485" height="134" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><text x="46" y="49" font-size="13.5" class="dg-ink" fill="#15803d" font-weight="700">Route table of the public subnets</text></g>
<text x="46" y="76" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="700">Destination</text>
<text x="190" y="76" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="700">Target</text>
<rect class="dg-panel" x="40" y="90" width="465" height="24" rx="6" fill="#f0f0ec" stroke="#cfcfc8"/>
<text x="46" y="107" font-size="12.5" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.0.0/16</text>
<text x="190" y="107" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">local</text>
<rect class="dg-panel" x="40" y="118" width="465" height="24" rx="6" fill="#f0f0ec" stroke="#cfcfc8"/>
<text x="46" y="135" font-size="12.5" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0.0.0.0/0</text>
<text x="190" y="135" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">igw-1 (Internet gateway)</text>
<rect class="dg-card" x="30" y="180" width="485" height="62" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-ok"><g class="dg-icon" transform="translate(44 200) scale(0.9167)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="76" y="206" font-size="13" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.11.5</text>
<text x="76" y="226" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">matches /16 and /0, the /16 is longer: stays inside the VPC</text>
<rect class="dg-card" x="30" y="254" width="485" height="62" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-ok"><g class="dg-icon" transform="translate(44 274) scale(0.9167)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="76" y="280" font-size="13" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.7</text>
<text x="76" y="300" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">only /0 matches: sent to igw-1</text>
<rect class="dg-card" x="545" y="24" width="485" height="134" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><text x="561" y="49" font-size="13.5" class="dg-ink" fill="#6d28d9" font-weight="700">Route table of the private subnets</text></g>
<text x="561" y="76" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="700">Destination</text>
<text x="705" y="76" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="700">Target</text>
<rect class="dg-panel" x="555" y="90" width="465" height="24" rx="6" fill="#f0f0ec" stroke="#cfcfc8"/>
<text x="561" y="107" font-size="12.5" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.0.0/16</text>
<text x="705" y="107" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">local</text>
<rect class="dg-panel" x="555" y="118" width="465" height="24" rx="6" fill="#f0f0ec" stroke="#cfcfc8"/>
<text x="561" y="135" font-size="12.5" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0.0.0.0/0</text>
<text x="705" y="135" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">nat-a (NAT gateway)</text>
<rect class="dg-card" x="545" y="180" width="485" height="62" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-ok"><g class="dg-icon" transform="translate(559 200) scale(0.9167)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="591" y="206" font-size="13" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.11.5</text>
<text x="591" y="226" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">matches /16 and /0, the /16 is longer: stays inside the VPC</text>
<rect class="dg-card" x="545" y="254" width="485" height="62" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-ok"><g class="dg-icon" transform="translate(559 274) scale(0.9167)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="591" y="280" font-size="13" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.7</text>
<text x="591" y="300" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">only /0 matches: sent to nat-a</text>
</svg></figure>
*Figure 2. The same longest prefix match you know from routers. The local route keeps VPC traffic inside; the default route sends everything else to the gateway.*
Two details trip people up:
- **A public address is not enough.** A resource in a private subnet that has a public address still can't be reached from the Internet, because the subnet's route table doesn't send replies and requests through an Internet gateway. Both the route *and* the public address are needed.
- **Public addresses are mapped, not configured.** Inside the instance you usually see only its private address. The provider's gateway swaps it for the public one on the way out and back. An **elastic IP** (the name varies: static public IP, reserved IP) is a public address that you keep and can move from one resource to another, instead of getting a new random one every time the resource restarts. It is a billable resource: release it when you no longer need it.
A NAT gateway is **outbound only** by design. It remembers the connections started from inside, and returns only their replies. A connection started from the Internet has no entry, so it's dropped. That is exactly what you want for application servers: they can fetch updates, but nobody can connect to them.
> [!NOTE]
> How a NAT gateway is built differs. In some providers it sits in a public subnet and each AZ needs its own (as in Figure 1); in others it is a regional managed service attached to subnets. Either way it has a public address, and it can be a cost and a single point of failure if you share one across zones. Check the provider's pricing and resilience documentation.
> [!CHECK]
> A server in a private subnet runs `apt update` successfully, but a user on the Internet can't open a connection to the server. Which component explains both facts?
>
> - [ ] The Internet gateway, which blocks all outbound connections from private subnets
> - [x] The NAT gateway, which translates outbound connections and returns their replies but has no entry for new inbound ones
> - [ ] The local route, which only allows traffic inside the VPC
> - [ ] The elastic IP, which was released
>
> A NAT gateway is outbound only: it forwards what was started from inside and drops what has no matching connection entry.
### Filtering: security groups and network ACLs
Routes decide *where* a packet can go. Filters decide *whether* it may. Cloud networks offer two layers, security groups and **network access control lists (ACLs)**, and you should know the difference:
| | **Security group** | **Network ACL** |
|---|---|---|
| Attached to | A network interface (so, a resource) | A subnet |
| State | **Stateful**: replies to allowed traffic are allowed automatically | **Stateless**: every packet is checked, in both directions |
| Rule type | Allow only | Allow **and** deny |
| Evaluation | All rules together; any match allows | Numbered rules, lowest number first; the first match wins |
| Default (typical) | Deny all inbound, allow all outbound | Varies: the default ACL often allows everything |
| Use it for | The main control: who may talk to this resource | A coarse extra layer: block a hostile range for the whole subnet |
**Stateful** means the filter keeps a connection table (the same connection tracking that makes NAT work). When a request is allowed, the reply is matched to the entry and allowed, whatever the rules say about the reverse direction. So with a security group you write one rule per service: "allow TCP 443 in".
**Stateless** means no memory: each packet is judged on its own. A web request in on TCP 443 is one packet to check. The reply goes out from port 443 to the client's **ephemeral port**: a high port the client's operating system picked for this connection (Linux uses 32768 to 60999 by default; the IANA suggestion is 49152 to 65535; other systems differ). A network ACL therefore needs a second rule for the replies, such as "allow outbound TCP 1024-65535", or the connection hangs. Teams forget this and lose hours.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 440" width="1180" height="440" role="img" aria-labelledby="vnet-sg-vs-nacl-title vnet-sg-vs-nacl-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="vnet-sg-vs-nacl-title">Security group versus network ACL</title>
<desc id="vnet-sg-vs-nacl-desc">A request for TCP port 443 from 203.0.113.7 travels from the Internet through a network ACL at the subnet edge and then a security group at the instance's network interface, to a web server. The network ACL is stateless and has numbered rules, lowest number first: inbound rule 100 allows TCP 443 from 0.0.0.0/0, inbound rule * denies all, outbound rule 100 allows TCP 1024-65535 and outbound rule * denies all. The security group is stateful and allow-only: it allows inbound TCP 443 from 0.0.0.0/0 and all outbound traffic. On the way back, the reply is checked again by the network ACL, which needs the outbound rule for ports 1024-65535, but is allowed automatically by the security group because it records the connection.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="439" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l4"><rect class="dg-tint" x="180" y="80" width="420" height="240" rx="16" fill="#fbf4f0" stroke="#e7b39e" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(196 93) scale(0.7500)" fill="none" stroke="#c2410c" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M3 6h.01"/><path d="M3 12h.01"/><path d="M3 18h.01"/></g>
<text x="222" y="107" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Network ACL · at the subnet edge</text></g>
<g class="dg-l2"><rect class="dg-tint" x="620" y="80" width="540" height="240" rx="16" fill="#f1f7f3" stroke="#a1ccb1" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(636 93) scale(0.7500)" fill="none" stroke="#15803d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/></g>
<text x="662" y="107" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Security group · at the instance interface</text></g>
<rect class="dg-card" x="200" y="128" width="380" height="126" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><text x="214" y="153" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Rules, lowest number first</text></g>
<g class="dg-ok"><text x="214" y="176" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">in 100 allow tcp 443 from 0.0.0.0/0</text></g>
<g class="dg-warn"><text x="214" y="195" font-size="12" class="dg-ink" fill="#b91c1c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">in * deny all</text></g>
<g class="dg-ok"><text x="214" y="214" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">out 100 allow tcp 1024-65535</text></g>
<g class="dg-warn"><text x="214" y="233" font-size="12" class="dg-ink" fill="#b91c1c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">out * deny all</text></g>
<rect class="dg-card" x="640" y="128" width="330" height="88" rx="10" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><text x="654" y="153" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Rules (allow only)</text></g>
<g class="dg-ok"><text x="654" y="176" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">in allow tcp 443 from 0.0.0.0/0</text></g>
<g class="dg-ok"><text x="654" y="195" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">out allow all</text></g>
<rect class="dg-card" x="995" y="150" width="130" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(1045 160) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="1060" y="210" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">web-1</text>
<text x="1060" y="229" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.1.10</text>
<rect class="dg-card" x="12" y="150" width="116" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(55 160) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g></g>
<text x="70" y="210" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Internet</text>
<text x="70" y="229" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.7</text>
<g class="dg-ok"><path class="dg-stroke" d="M70 150V42H1060V142" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-ok"><path class="dg-stroke" d="M1054 135l6 8 6-8" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-ok"><rect class="dg-solid" x="429" y="29" width="262" height="26" rx="13" fill="#15803d"/><text x="560" y="46.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Request: TCP 443 from 203.0.113.7</text></g>
<g class="dg-l4"><rect class="dg-bg-plain" x="239.32" y="50" width="301.36" height="24" rx="12" fill="#ffffff"/><text x="390" y="66.5" font-size="11.5" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle">stateless: checked against the inbound rules</text></g>
<g class="dg-l2"><rect class="dg-bg-plain" x="777.62" y="50" width="204.76" height="24" rx="12" fill="#ffffff"/><text x="880" y="66.5" font-size="11.5" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">stateful: connection recorded</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M1060 242V366H70V248" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M64 259l6-8 6 8" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><rect class="dg-tint" x="476" y="353" width="168" height="26" rx="13" fill="#e6f0f6" stroke="#8ebcd5" stroke-width="1.2"/><text x="560" y="370.5" font-size="12" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Reply to 203.0.113.7</text></g>
<g class="dg-warn"><rect class="dg-bg-plain" x="194.24" y="382" width="391.52" height="24" rx="12" fill="#ffffff"/><text x="390" y="398.5" font-size="11.5" class="dg-ink" fill="#b91c1c" font-weight="600" text-anchor="middle">checked again: the out rule for ports 1024-65535 is needed</text></g>
<g class="dg-ok"><rect class="dg-bg-plain" x="751.86" y="382" width="256.28" height="24" rx="12" fill="#ffffff"/><text x="880" y="398.5" font-size="11.5" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">allowed automatically: no rule needed</text></g>
</svg></figure>
*Figure 3. The same connection crosses two filters. The stateless ACL needs rules for both directions; the stateful security group needs only the rule for the direction that starts the connection.*
A packet inside the VPC must be allowed by **both** layers (the ACL of the subnet it crosses, and the security groups of the interfaces). Traffic between two resources in the same subnet doesn't cross the subnet's ACL, but does cross the security groups.
A strong pattern is to let security groups refer to each other instead of to address ranges: "the database accepts TCP 5432 from the app tier's security group". When you add an app server, it joins the group and gets access, with no CIDR to update.
> [!CHECK]
> A stateless ACL has "in 100: allow TCP 443" and "out *: deny all". A client connects to the web server in that subnet. What happens?
>
> - [ ] It works, because replies to allowed requests are always allowed
> - [ ] The request is dropped, because the ACL has no "allow all" rule
> - [x] The request arrives, but the reply is dropped, so the connection times out
> - [ ] The security group opens the port automatically
>
> The inbound rule lets the request in. With no state, the reply is a new packet to check, and the outbound deny drops it. Add "out 100: allow TCP 1024-65535".
### Connecting networks
Sooner or later one VPC isn't enough: you split production and staging, join the networks of two business units, or connect to the office. There are three common ways.
- **VPC peering** is a direct, private link between two VPCs, with the traffic staying on the provider's network. It is simple and cheap, but needs non-overlapping ranges and a route in **each** VPC pointing to the peer. Filters still apply. Peering is **not transitive**: if A is peered with B, and B with C, then A can't reach C through B. A and C need their own peering. With *n* networks, a full mesh needs *n*(*n*−1)/2 peerings (45 for ten networks), which is why peering doesn't scale.
- **Transit hub** (a transit gateway or hub network) is a central router that many VPCs and VPNs attach to. Each network has one attachment, and the hub's route tables decide which networks can talk, so you can allow or block pairs centrally. It scales to many networks and is the usual choice beyond a handful, at a higher cost.
- **Site-to-site virtual private network (VPN)** joins a VPC to an on-premises network over the Internet inside encrypted tunnels that use **Internet Protocol Security (IPsec)**, RFC 4301. A VPN gateway on the cloud side and a router or firewall on the office side build the tunnel; routes are static or exchanged with the Border Gateway Protocol (BGP). It is fast to set up and encrypted, but its speed and latency depend on the Internet path. For steady, high-volume traffic, providers also sell dedicated private links.
<figure class="diagram" style="--dg-w: 1100px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1100 440" width="1100" height="440" role="img" aria-labelledby="vnet-peering-vs-hub-title vnet-peering-vs-hub-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="vnet-peering-vs-hub-title">Peering versus a transit hub</title>
<desc id="vnet-peering-vs-hub-desc">Left: three virtual networks, A (10.20.0.0/16), B (10.21.0.0/16) and C (10.22.0.0/16). A is peered with B and B is peered with C, so A and B can talk and B and C can talk. A and C have no peering, and traffic from A does not pass through B to reach C, so peering is not transitive. Right: a transit hub with A, B, C and the on-premises network 172.16.0.0/16 each attached once. The on-premises network connects over a site-to-site IPsec VPN. Every attached network can reach every other through the hub's route tables.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1099" height="439" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l4"><rect class="dg-tint" x="20" y="20" width="500" height="400" rx="16" fill="#fbf4f0" stroke="#e7b39e" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(36 33) scale(0.7500)" fill="none" stroke="#c2410c" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a1 1 0 0 1-1-1v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1a1 1 0 0 1-1 1"/><path d="M19 15V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V9"/><path d="M21 21v-2h-4"/><path d="M3 5h4V3"/><path d="M7 5a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1V3"/></g>
<text x="62" y="47" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Peering: not transitive</text></g>
<g class="dg-l1"><rect class="dg-tint" x="540" y="20" width="540" height="400" rx="16" fill="#f0f6f9" stroke="#9ac3d9" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(556 33) scale(0.7500)" fill="none" stroke="#0369a1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></g>
<text x="582" y="47" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700">Transit hub: one attachment each</text></g>
<g class="dg-ok"><path class="dg-stroke" d="M154 216H206" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-ok"><path class="dg-stroke" d="M334 216H386" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M90 166V122H450V166" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-warn"><circle class="dg-solid" cx="270" cy="122" r="11" fill="#b91c1c"/><text x="270" y="126.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">✕</text></g>
<text x="270" y="108" font-size="12.5" class="dg-ink" fill="#b91c1c" font-weight="700" text-anchor="middle">A cannot reach C through B</text>
<rect class="dg-card" x="26" y="170" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(75 180) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="90" y="230" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">VPC A</text>
<text x="90" y="249" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.0.0/16</text>
<rect class="dg-card" x="206" y="170" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(255 180) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="270" y="230" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">VPC B</text>
<text x="270" y="249" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.21.0.0/16</text>
<rect class="dg-card" x="386" y="170" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(435 180) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="450" y="230" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">VPC C</text>
<text x="450" y="249" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.22.0.0/16</text>
<g class="dg-ok"><g class="dg-icon" transform="translate(60 310) scale(0.8333)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="90" y="325" font-size="13.5" class="dg-text" fill="#17171c" font-weight="500">A ↔ B: peered, works</text>
<g class="dg-ok"><g class="dg-icon" transform="translate(60 342) scale(0.8333)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="90" y="357" font-size="13.5" class="dg-text" fill="#17171c" font-weight="500">B ↔ C: peered, works</text>
<g class="dg-warn"><g class="dg-icon" transform="translate(60 374) scale(0.8333)" fill="none" stroke="#b91c1c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></g></g>
<text x="90" y="389" font-size="13.5" class="dg-text" fill="#17171c" font-weight="500">A ↔ C: no peering, no path</text>
<g class="dg-l1"><path class="dg-stroke" d="M810 214L650 126" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M810 214L970 126" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M810 214L650 316" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l3"><path class="dg-stroke" d="M810 214L970 316" stroke="#b45309" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<rect class="dg-card" x="745" y="168" width="130" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(795 178) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g></g>
<text x="810" y="228" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Transit hub</text>
<rect class="dg-card" x="586" y="80" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(635 90) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="650" y="140" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">VPC A</text>
<text x="650" y="159" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.0.0/16</text>
<rect class="dg-card" x="906" y="80" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(955 90) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="970" y="140" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">VPC B</text>
<text x="970" y="159" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.21.0.0/16</text>
<rect class="dg-card" x="586" y="270" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(635 280) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="650" y="330" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">VPC C</text>
<text x="650" y="349" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.22.0.0/16</text>
<rect class="dg-card" x="906" y="270" width="128" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(955 280) scale(1.2500)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6 22V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v18Z"/><path d="M6 12H4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/><path d="M18 9h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2"/><path d="M10 6h4"/><path d="M10 10h4"/><path d="M10 14h4"/><path d="M10 18h4"/></g></g>
<text x="970" y="330" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">On-premises</text>
<text x="970" y="349" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">172.16.0.0/16</text>
<g class="dg-l3"><rect class="dg-tint" x="871.5" y="372" width="197" height="26" rx="13" fill="#f8eee6" stroke="#ddb290" stroke-width="1.2"/><text x="970" y="389.5" font-size="12" class="dg-ink" fill="#b45309" font-weight="700" text-anchor="middle">Site-to-site VPN · IPsec</text></g>
<text x="810" y="410" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle">Spokes reach each other and on-premises through the hub's route tables</text>
</svg></figure>
*Figure 4. Peering links two networks and stops there. A transit hub connects every attached network through one attachment each.*
Why is peering non-transitive? Because a peering is a route entry, not a router. B's VPC has no forwarding function for packets that neither start nor end in B, and the provider deliberately doesn't let one peer use another's connections: that would let A reach networks that C's owner never agreed to share with A. If you need A to reach C, peer them, or use a hub.
> [!CHECK]
> VPC A is peered with VPC B, and B is peered with VPC C. Why can a server in A not reach a server in C?
>
> - [ ] The peering between B and C only works in one direction
> - [ ] Security groups always block traffic that crosses a peering
> - [ ] A and C have overlapping address ranges
> - [x] Peering is not transitive: traffic from A is not forwarded through B to C
>
> Each peering connects exactly two networks. To connect A and C, create a peering between them, or attach all the networks to a transit hub.
## How it works
Follow two journeys through the network of Figure 1. The app tier runs in the private subnet `10.20.11.0/24`. The load balancer is in the public subnet `10.20.1.0/24`. Addresses outside the VPC come from the documentation ranges (RFC 5737).
**An outbound request: an app server downloads a patch.** The app server `10.20.11.5` connects to `203.0.113.7` on TCP 443.
1. **Route table of the private subnet.** `203.0.113.7` doesn't match the local route `10.20.0.0/16`, so the default route `0.0.0.0/0` wins: next hop `nat-a`.
2. **Filters, outbound.** The security group of the app server allows outbound traffic. The network ACL of the private subnet must allow `tcp 443` out (rule "out 110" in the worked example below).
3. **NAT gateway.** `nat-a` replaces the source `10.20.11.5` with its own public address, say `198.51.100.20`, and records the connection. It forwards the packet towards its subnet's route table, whose default route points to the Internet gateway.
4. **Internet gateway.** It sends the packet to the Internet.
5. **The reply.** `203.0.113.7` answers to `198.51.100.20`. The Internet gateway delivers it to `nat-a`, which finds the connection entry and rewrites the destination back to `10.20.11.5`. The network ACL must now allow the reply in: TCP to the ephemeral port range ("in 110"). The security group allows it as a reply (stateful).
**An inbound request: a user opens the website.** A user at `203.0.113.7` connects to the load balancer's public address on TCP 443. The Internet gateway translates it to the load balancer's private address `10.20.1.10`. The network ACL of the public subnet allows TCP 443 in, the load balancer's security group allows TCP 443 from `0.0.0.0/0`, and the load balancer opens a **new** connection to an app server `10.20.11.5` on TCP 8080 inside the VPC. That second connection follows the local route and crosses the private subnet's ACL and the app server's security group. The Internet never has a path to the app server.
> [!CHECK]
> In the outbound journey, why does the network ACL of the private subnet need an inbound rule for ephemeral ports?
>
> - [ ] Because the NAT gateway opens new connections towards the app server
> - [ ] Because the Internet gateway uses ephemeral ports to build tunnels
> - [x] Because the reply from the Internet is a separate packet to a high port, and a stateless ACL has no memory of the outbound request
> - [ ] Because the security group needs it to track the connection
>
> The client's source port is high and random, so the reply comes back to that port. A stateless filter must allow that port range explicitly.
## Worked example
You design the network for a two-tier web application, in two zones, for the organization plan `10.20.0.0/16`.
**Address plan.**
| Subnet | Zone | CIDR | Kind | Route table: default route |
|---|---|---|---|---|
| `public-a` | A | `10.20.1.0/24` | Public | Internet gateway |
| `public-b` | B | `10.20.2.0/24` | Public | Internet gateway |
| `private-a` | A | `10.20.11.0/24` | Private | NAT gateway in `public-a` |
| `private-b` | B | `10.20.12.0/24` | Private | NAT gateway in `public-b` |
All four `/24` blocks lie inside `10.20.0.0/16`, don't overlap, and leave `10.20.3.0` to `10.20.10.255` and everything above `10.20.12.255` free for growth. The on-premises network uses `172.16.0.0/16` and staging uses `10.21.0.0/16`, so nothing overlaps and both can be connected later.
**Security groups** (allow rules only; replies are automatic).
| Group | Attached to | Inbound rule | Outbound |
|---|---|---|---|
| `lb-sg` | Load balancer | TCP 443 from `0.0.0.0/0` | TCP 8080 to `app-sg` |
| `app-sg` | App servers | TCP 8080 from `lb-sg` | TCP 5432 to `db-sg`; TCP 443 to `0.0.0.0/0` (via NAT) |
| `db-sg` | Database | TCP 5432 from `app-sg` | None needed |
The database is in a private subnet, has no public address and accepts only the app tier. Even if someone opens the database port in a test, the lack of a route from the Internet still protects it: two independent layers.
**Network ACL for the private subnets** (stateless, so both directions are listed).
| Rule | Direction | Action | Protocol and ports | Peer |
|---|---|---|---|---|
| 100 | Inbound | Allow | TCP 8080 | `10.20.1.0/24`, `10.20.2.0/24` (load balancers) |
| 110 | Inbound | Allow | TCP 1024-65535 | `0.0.0.0/0` (replies from the Internet) |
| `*` | Inbound | Deny | All | Any |
| 100 | Outbound | Allow | TCP 1024-65535 | `10.20.1.0/24`, `10.20.2.0/24` (replies to the load balancers) |
| 110 | Outbound | Allow | TCP 443 | `0.0.0.0/0` (patches, through NAT) |
| `*` | Outbound | Deny | All | Any |
Rule 110 inbound is wide because the replies come from any Internet address. Rule 100 outbound is the one that people forget. In the lab you will remove it on purpose and watch the connection hang.
> [!NOTE]
> Here the database runs in the same private subnets as the app servers. Traffic between two resources in the same subnet doesn't cross that subnet's ACL in most providers, so the ACL needs no rule for port 5432. If the database were in a separate subnet, or an app server in zone A talked to a database in zone B, that traffic would cross the ACLs and need rules on both subnets, in both directions.
## Common pitfalls
- **Overlapping CIDR blocks.** Two networks both use `10.0.0.0/16` because it was the console's default. They can never be peered or joined with a VPN without re-addressing. Keep one organization-wide address plan and check it before you create a VPC.
- **A public address without a route.** The resource has a public IP but sits in a subnet whose route table has no Internet gateway route: it's still unreachable. Check the route first.
- **A private subnet with no way out.** No NAT gateway or a missing default route: servers can't fetch updates or reach cloud APIs, and "it works on my laptop" turns into a timeout.
- **Forgetting the return path of a stateless ACL.** The request arrives, the reply is dropped, and the connection hangs. Always allow the ephemeral port range in the opposite direction.
- **Expecting peering to be transitive.** A reaches B, B reaches C, but A can't reach C. Peer A and C directly, or move to a hub.
- **One NAT gateway for every zone.** If its zone fails, all private subnets lose Internet access, and cross-zone traffic can add cost. Use one per zone for production.
- **Routes only on one side.** A peering or VPN works only if **both** VPCs (or both ends) have a route for the other's range, and the filters on both sides allow the traffic.
- **Confusing "refused" with "timed out".** They point to different layers: see the troubleshooting method below.
## Troubleshooting method
Reachability problems are almost always one of three things: **route**, **NAT**, or **filter**. Walk the path in order, in both directions, and stop at the first thing that is wrong.
1. **Name and address.** Does the name resolve to the address you expect? Are source and destination in ranges that don't overlap?
2. **Source side.** The source's security group must allow the traffic outbound. The route table of the source's subnet must have a route for the destination. The ACL of the source subnet must allow it out.
3. **Destination side.** The destination subnet's ACL must allow it in. The destination's security group must allow it in. A service must be listening on that port.
4. **Return path.** The destination subnet's route table must have a route back to the source (or to its NAT gateway's address). A stateless ACL must allow the replies. NAT must rewrite them.
The error you see narrows it down:
| What you see | What it usually means | Look at |
|---|---|---|
| "Network is unreachable" or "No route to host" immediately | No matching route in the sender's table | Route tables, gateways, peering routes |
| Connection **times out** | A packet was dropped silently: a filter, a missing return route or missing NAT | Security groups, ACLs (both directions), return routes, NAT |
| Connection **refused** immediately | The packet reached the host, and nothing listens on that port (or the host firewall rejects it) | The service, the host firewall |
| Works to some addresses, not others | A more specific route or an ACL rule applies only to some ranges | Route specificity, ACL rule numbers |
Providers offer tools that make this faster: **flow logs** record accepted and rejected packets per interface, and reachability analyzers check a path against routes and filters without sending packets. Use them, but understand the method first: the tools only report what the rules say.
> [!CHECK]
> A client gets "Connection timed out" when it connects to a server in the same VPC. The route tables are correct and the server is running. What is the best next check?
>
> - [ ] Restart the NAT gateway
> - [ ] Check that the server has an elastic IP
> - [x] Check the security group and the network ACLs of both subnets, in both directions, for a drop
> - [ ] Check whether the server returns "connection refused"
>
> A silent drop (timeout) with correct routes points to a filter. "Refused" would mean the packet arrived, so it's the opposite symptom, and a public address is not needed inside the VPC.
## Security considerations
Cloud networks are open to the Internet by a mouse click, so the risk is mostly misconfiguration.
- **Default to private.** Put only what must face the Internet (load balancers, gateways) in public subnets. Servers, databases and caches go in private subnets with no public address.
- **Least privilege in rules.** Avoid `0.0.0.0/0` on any port except the ones a public service needs (usually 443, and 80 to redirect). Never leave `0.0.0.0/0` open for SSH (TCP 22), RDP (TCP 3389) or database ports (such as 5432 or 3306), even "for a minute". Use a bastion, a VPN, or the provider's managed access service, and restrict the source to known ranges.
- **Reference groups, not ranges.** Rules such as "from `app-sg`" follow the resources and don't go stale.
- **Layer your defences.** Security groups are the main control. Add ACLs as a coarse safety net (for example to deny a known hostile range), but don't depend on them alone: they are easy to get wrong and stateless.
- **Mind the egress.** An outbound `allow all` lets malware phone home and data leave. For sensitive tiers, restrict outbound rules, or force traffic through a proxy or firewall.
- **Watch for blast radius.** Flat, wide networks let an attacker move sideways. Separate production from staging in different VPCs, and keep peering and hub route tables as narrow as the application needs.
- **Log and alert.** Enable flow logs and alert on changes to security groups, ACLs and route tables. A change that opens a database port is an incident in the making.
- **Encrypt in transit.** The provider's network separates customers, but it's still shared infrastructure: use Transport Layer Security (TLS) between tiers, and IPsec or an equivalent for links to the office.
> [!IMPORTANT]
> Only change networks you own or are explicitly authorized to change, and test rules in a non-production network first. The lab in this module builds everything on your machine with private and documentation addresses.
## Summary
- A VPC is a software-defined private network. Pick its CIDR block from RFC 1918, make it big enough (often a `/16`), and plan one organization-wide address scheme so networks never overlap.
- Subnets are made per availability zone. A subnet is public if its route table has a route to an Internet gateway, and private otherwise. The kind is set by routes, not by the address range.
- Every route table has an implicit local route. The default route's target (Internet gateway or NAT gateway) decides who can reach what: a NAT gateway is outbound only.
- Security groups are stateful, allow-only and attached to interfaces: they are your main control. Network ACLs are stateless, ordered, allow-and-deny and attached to subnets: they need rules for return traffic and ephemeral ports.
- Peering joins two networks and is not transitive; a transit hub attaches many networks once each; a site-to-site VPN joins a VPC to on-premises over encrypted IPsec tunnels. All need non-overlapping ranges and routes on both sides.
- Troubleshoot in order: name, source filters and routes, destination filters, return path. Unreachable means route, timeout means a silent drop, refused means the host answered.
## Glossary
| Term | Definition |
|---|---|
| **Virtual network** | A private, isolated network defined in software inside a provider's shared infrastructure. Also called VPC or VNet. |
| **Virtual private cloud (VPC)** | The AWS and Google Cloud name for a virtual network; used here as the generic term. |
| **Classless Inter-Domain Routing (CIDR) block** | An address range written as a prefix and a length, such as `10.20.0.0/16`. |
| **Software-defined network (SDN)** | A network whose paths and rules are defined by software and APIs rather than by configuring individual devices. |
| **Subnet** | A part of the VPC range with its own CIDR block, placed in one or more availability zones, and with its own route table. |
| **Availability zone (AZ)** | One of several separate data centres in a region that fail independently. |
| **Public subnet** | A subnet whose route table has a route to an Internet gateway. |
| **Private subnet** | A subnet with no route from the Internet to its resources. It reaches the Internet, if at all, through a NAT gateway. |
| **Route table** | A list of destination prefix to target entries that decides where a subnet's traffic goes. |
| **Local route** | The implicit route for the VPC's own CIDR block, present in every route table, that keeps VPC traffic inside the VPC. |
| **Internet gateway** | A gateway that connects a VPC to the Internet and translates between public and private addresses. |
| **NAT gateway** | A gateway that lets private resources start connections to the Internet by translating their addresses, and that blocks connections started from outside. |
| **Elastic IP** | A static public address that you reserve and can move between resources; the name is used by AWS, other providers say static or reserved IP. |
| **Security group** | A stateful, allow-only filter attached to a network interface. |
| **Network ACL** | A stateless, ordered allow-and-deny filter attached to a subnet. |
| **Stateful** | Keeping a connection table, so replies to allowed traffic are allowed automatically. |
| **Stateless** | Judging each packet alone, with no memory of earlier packets. |
| **Ephemeral port** | The high, temporary source port a client picks for a connection; replies come back to it. |
| **VPC peering** | A direct private link between two virtual networks. It is not transitive. |
| **Transit hub** | A central router (for example a transit gateway) to which many networks and VPNs attach. |
| **Site-to-site VPN** | An encrypted tunnel (IPsec) between a VPC and an on-premises network over the Internet. |
| **Flow logs** | Records of accepted and rejected packets per interface or subnet, used to troubleshoot filters. |
## Check your understanding
1. Your company already uses `10.0.0.0/8` on premises, with `10.1.0.0/16` for offices and `10.2.0.0/16` for data centres. Propose a CIDR for a first production VPC, and explain two things you should check before you create it.
2. A teammate says: "the database is private because it is in `10.20.12.0/24`." Explain what really makes a subnet private, and describe two checks that would prove it.
3. Write the security group rules for a three-tier application (load balancer, app, database). Which rules would you need in a stateless network ACL that you don't need in the security groups?
4. A private server can ping other servers in the VPC but `curl https://example.com` times out. List the components you would check, in order.
5. You have six VPCs that must all reach each other. How many peerings would a full mesh need, and why might a transit hub be a better choice?
## References
- [RFC 1918](https://www.rfc-editor.org/rfc/rfc1918) — Address Allocation for Private Internets.
- [RFC 6598](https://www.rfc-editor.org/rfc/rfc6598) — IANA-Reserved IPv4 Prefix for Shared Address Space.
- [RFC 4301](https://www.rfc-editor.org/rfc/rfc4301) — Security Architecture for the Internet Protocol (IPsec).
- [RFC 3022](https://www.rfc-editor.org/rfc/rfc3022) — Traditional IP Network Address Translator (Traditional NAT).
- [RFC 5737](https://www.rfc-editor.org/rfc/rfc5737) — IPv4 Address Blocks Reserved for Documentation.
- Your provider's documentation for its virtual network, route tables, security groups and gateways: the exact limits, defaults and prices differ.