Cloud Networking — VPCs, Subnets, Security Groups and Peering
Build a mental model of cloud virtual networks, route tables, stateful security groups, and private connectivity.
Prerequisites: Know IPv4/CIDR notation, routing tables, basic firewall rules, and the difference between inbound and outbound traffic.
Learning objectives: Plan non-overlapping VPC address space, trace routes between subnets, apply least-privilege security-group intent, and diagnose peering paths.
Chapter 01
A Network You Define in Software
A Virtual Private Cloud (VPC)—called a virtual network or VNet by some providers—is a logically isolated network boundary in a cloud region or equivalent scope. It has an IP address range, subnets, route tables, and attachment points to other networks. It is not automatically private from every other cloud service, and it does not replace identity and workload security.
A useful starting design is to reserve non-overlapping address space before creating resources. For example, a VPC could use 10.20.0.0/16 and allocate smaller ranges to availability zones and tiers. Leave room for growth, future peering, VPNs, and on-premises networks; overlapping CIDRs can make later connectivity difficult or impossible without translation or renumbering.
VPC: 10.20.0.0/16
Availability zone A Availability zone B
10.20.0.0/24 public edge 10.20.10.0/24 public edge
10.20.1.0/24 app workloads 10.20.11.0/24 app workloads
10.20.2.0/24 data tier 10.20.12.0/24 data tier
│ │
└──────── private service paths ──┘Chapter 02
Subnets, Route Tables, and Internet Paths
A subnet is a slice of a VPC's address range associated with a location or availability zone. A subnet alone does not make a workload public or private. Its attached route table determines where traffic can go. A subnet with a route to an internet gateway may be considered public by the provider's model; a private subnet generally has no direct inbound internet route. Workloads in a private subnet may still have controlled outbound access through a NAT service or private endpoints.
Route tables use destination prefixes and next hops. The most-specific matching route generally wins, so a route for a VPC-local prefix can remain more specific than a default route. A path requires more than one route: the sender needs a route out, the destination needs a return route, and security controls on the path must permit the flow.
Example route intent (not provider CLI syntax)
Public subnet route table:
10.20.0.0/16 -> local VPC routing
0.0.0.0/0 -> internet gateway
Private app subnet route table:
10.20.0.0/16 -> local VPC routing
0.0.0.0/0 -> managed NAT for outbound updates only
Private data subnet route table:
10.20.0.0/16 -> local VPC routing
(no default route to the public internet)An internet gateway route does not automatically assign a public IP or open a security rule. Public reachability requires an address and an allowed path in both directions. Similarly, NAT typically enables outbound-initiated connections and their return traffic; it is not a general inbound publishing mechanism. Provider behavior and route terminology differ, so validate the precise service model in the chosen cloud.
Chapter 03
Plan Address Space Before Peering
CIDR notation describes a prefix and the number of network bits. Python's standard ipaddress library can help check planned ranges before they become cloud resources. The following program reports whether proposed subnets fit inside a VPC and whether any overlap. Run it locally with Python; it makes no network calls.
from ipaddress import ip_network
vpc = ip_network("10.20.0.0/16")
subnets = [
ip_network("10.20.0.0/24"),
ip_network("10.20.1.0/24"),
ip_network("10.20.10.0/24"),
]
for index, subnet in enumerate(subnets):
if not subnet.subnet_of(vpc):
raise ValueError(f"{subnet} is outside {vpc}")
for other in subnets[:index]:
if subnet.overlaps(other):
raise ValueError(f"{subnet} overlaps {other}")
print("All subnets fit and are non-overlapping")This is a small guardrail, not a complete IPAM system. A production source of truth should also reserve ranges, track ownership, include existing VPCs and connected networks, and prevent two teams from independently allocating the same block. Review both IPv4 and IPv6 plans when dual-stack connectivity is required.
10.0.0.0/16 everywhere creates an overlap trap. Check corporate VPN ranges, acquired-company networks, partner networks, and other cloud accounts before locking in a CIDR.Chapter 04
Security Groups: Stateful Workload Rules
A security group is a virtual network policy attached to a workload or network interface in many cloud platforms. It commonly acts as a stateful filter: when an allowed connection is established, return traffic for that flow is allowed automatically. Rules usually describe protocol, port range, and source or destination. Some platforms express separate ingress and egress rules; check the provider's defaults rather than assuming either direction is unrestricted or denied.
Application tier security-group intent
Ingress:
TCP 443 from the public load-balancer security group
TCP 8080 from the internal API security group
Egress:
TCP 5432 to the database security group
TCP 443 to approved update and service endpoints
Database tier security-group intent
Ingress:
TCP 5432 from the application security group only
No public ingress ruleReferencing another security group (or an equivalent workload identity) expresses a relationship more robustly than allowing a broad IP range. It also narrows access to members that carry that identity, but it does not replace application authentication. Keep the port and direction specific, and remove temporary rules after their approved window.
Chapter 05
Network ACLs and Layered Filtering
Some clouds also offer subnet-level network access control lists (NACLs). A common distinction is that security groups are stateful and attached to workloads, while NACLs are stateless and applied at subnet boundaries. A stateless policy must allow both request and return traffic explicitly, including appropriate ephemeral port ranges. Exact evaluation order, defaults, and feature names vary by provider.
Use subnet ACLs when a coarse subnet boundary policy is useful, not as a substitute for precise workload rules. Two layers of filters can make troubleshooting harder: a flow may be rejected by a security group, an ACL, a route, a host firewall, or the application. Document each layer's intended role and test both directions.
Flow checklist: app -> database
1. Does the app have a route to the database address?
2. Does the database subnet have a return route?
3. Does the app security policy permit the database port?
4. Does the database policy allow this app identity as source?
5. Do subnet ACLs permit request AND return packets?
6. Does the host firewall and database listener accept the flow?
7. Can logs and flow records confirm the result?Chapter 06
Private Connectivity and VPC Peering
VPC peering creates private connectivity between two virtual networks, typically by adding a connection and corresponding routes on both sides. A peering link is generally non-transitive: if VPC A peers with B and B peers with C, that alone does not make A able to reach C through B. Each cloud provider has specific limits, routing rules, and support for cross-account or cross-region links.
Peering is relatively direct for a small number of networks but can become a mesh as the network count grows. A transit gateway, hub-and-spoke router, VPN, private service endpoint, or service mesh may be a better fit depending on the traffic and trust model. These options are not interchangeable: a private endpoint may expose a particular service without granting broad network reachability.
App VPC: 10.20.0.0/16 Data VPC: 10.30.0.0/16
│ │
route 10.30.0.0/16 -> peer route 10.20.0.0/16 -> peer
└──────────── peering connection ─────┘
A route on only one side is not enough.
A -> B -> C does not imply a transitive A -> C route.Before enabling peering, check for overlapping address ranges, confirm route tables on each side, scope security rules to the intended peer, and decide who owns monitoring and incident response. Review whether DNS names resolve to private addresses across the connection and whether the provider requires explicit DNS options.
Chapter 07
A Safe Design and Troubleshooting Workflow
Start with the flows, not a list of cloud products. For each flow, record source workload, destination, protocol and port, business purpose, direction, expected volume, and owner. Then draw the VPC boundaries, subnet ranges, route tables, gateways, and filters. This makes a required rule explainable and gives reviewers a way to identify unnecessary reachability.
- Allocate non-overlapping address ranges and reserve growth capacity.
- Separate public entry points from application and data tiers.
- Write explicit routes and least-privilege ingress and egress policy.
- Review connectivity with security and application owners before deployment.
- Apply changes through versioned infrastructure code and review the plan.
- Test allowed and denied flows, then retain flow logs and configuration history.
For a failed connection, test from the actual source workload, confirm DNS and destination address, inspect both route tables, evaluate all filters, and check the destination listener. Cloud flow logs can show accepted or rejected traffic, but logging may be delayed or sampled depending on the service. They do not prove that the application completed a request.
Chapter 08
Mistakes to Avoid and Practice
- Calling a subnet public because of its name: inspect its routes, addresses, and filters.
- Opening database ports broadly: use workload identity or the narrowest stable source range.
- Assuming peering is transitive: design the actual routes or choose a hub architecture.
- Forgetting return paths: routing and stateless ACLs must support both directions.
- Treating NAT as a firewall: use explicit policy to control allowed traffic.
Practice
- Plan two VPC CIDRs for a new service and a future partner connection. Check that they do not overlap.
- Draw a public load balancer, private application tier, and private database across two zones. Label each route.
- Write the minimum security-group intent for browser-to-load-balancer, load-balancer-to-app, and app-to-database flows.
- A peered application cannot connect to a database. List the route and policy checks you would make on both sides.
- Explain the stateful security-group versus stateless subnet-ACL distinction to a teammate.
🎯 Key Takeaways
- ✓A VPC is an isolated virtual network boundary; subnets and route tables define address placement and paths.
- ✓A subnet is not public merely because of its name. Public reachability requires routes, addressing, and permitted flows.
- ✓Security groups commonly provide stateful workload filtering; subnet ACLs are often stateless and require return-path rules.
- ✓Use non-overlapping CIDRs and plan for VPN, peering, and future connectivity before allocating address space.
- ✓VPC peering usually requires routes on both sides and is not automatically transitive.
- ✓Trace a failed connection through routes, filters, host policy, and the listening application rather than changing rules blindly.
HELP US IMPROVE
How was this lesson?
Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.
Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.
