Virtual networks

Your own private address space in the cloud

Region: IrelandYour virtual network10.0.0.0/16Zone a10.0.1.0/24Zone b10.0.2.0/24Zone c10.0.3.0/2465,536private addresses in the network10.0.0.0 to 10.0.255.255256addresses in each subnetone slice of the range per zoneA virtual network is your own private address space inside a region, cut into subnets.Nothing gets in or out unless you say so. You choose the range of private addresses, split it into subnets,and place machines in them. It is free to create, takes seconds, and is isolated from every other customer’s network.It is called a VPC on AWS and Google Cloud, and a virtual network (VNet) on Azure.

A virtual network is a private range of addresses inside a region, divided into subnets.

Virtual networks · Going deeper · 1 of 2

Reading 10.0.0.0/16: the slash counts fixed bits

the 32 bits of an address:fixed: names the networkfree: one value per machine10.0.0.0/16a whole network65,536 addresses(2 to the power 16)10.0.0.0/24a subnet256 addresses(2 to the power 8)10.0.0.0/28the smallest AWS allows16 addresses(2 to the power 4)In every subnet the provider keeps a few addresses for itself: 5 on AWS and Azure, 4 on Google Cloud. A /24 on AWS leaves you 251.The number after the slash says how many bits are fixed. Fewer fixed bits, more addresses.This notation is called CIDR. Plan it before you build: ranges of two networks that will ever be connected, to each otheror to your office, must not overlap, and a subnet’s size is awkward to change later. The private ranges set asidefor this are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.

CIDR notation gives a starting address and the number of fixed bits. A /16 has 65,536 addresses, a /24 has 256, and the provider reserves a few in every subnet.

Virtual networks · Going deeper · 2 of 2

VPC, VNet and VPC: what differs between providers

AWSAzureGoogle CloudThe networkVPCVirtual Network (VNet)VPCA network spansone regionone regionevery region: it is globalA subnet spansone zoneall zones of the regionall zones of one regionFirewall on a machinesecurity groupnetwork security groupfirewall rulesJoin two networksVPC peeringVNet peeringVPC peeringJoin many networksTransit GatewayVirtual WANNetwork Connectivity CenterThe same idea on all three, with one real difference: how far a network and a subnet stretch.On AWS a subnet lives in one zone, so spreading across zones means one subnet per zone, as on the previous page.On Azure and Google Cloud a subnet covers the whole region and each machine picks its zone. A Google VPC is global:one network can hold subnets in Ireland and in Tokyo, and they reach each other privately.

An AWS subnet lives in one zone; Azure and Google subnets cover a region; a Google VPC is global.

Public and private subnets

A route to the internet decides what can be reached from outside

Virtual network10.0.0.0/16InternetInternet gatewayPublic subnet10.0.1.0/24Web serverprivate 10.0.1.25public 54.220.10.8✓has a route to the internet gatewayPrivate subnet10.0.2.0/24Databaseprivate 10.0.2.40no public address✗no route to the internet gatewayA public subnet has a route to the internet. A private subnet has none, so nothing outside can reach it.Only what must face the public goes in a public subnet: usually just a load balancer. Application servers and databasessit in private subnets, reachable only from inside the network. Every machine has a private address; only those thatneed one get a public address as well.

A public subnet has a route to an internet gateway; a private subnet does not.

Public and private subnets · Going deeper · 1 of 2

Route tables: what makes a subnet public

Route table of the public subnetTraffic going tois sent to10.0.0.0/16anything inside the networklocal: deliver it directly0.0.0.0/0everything elsethe internet gatewayRoute table of the private subnetTraffic going tois sent to10.0.0.0/16anything inside the networklocal: deliver it directly0.0.0.0/0everything elsea NAT gateway, or nowhereThe most specific matching row wins. 0.0.0.0/0 matches every address, so it is the fallback: the default route.“Public” and “private” are not settings. They are one row in a subnet’s route table.Every subnet has a route table that says where to send traffic by its destination. A subnet is public because itsdefault route points at an internet gateway. Remove that row and the same subnet is private. When a machine cannotbe reached, the route table is the first place to look, and the firewall rules are the second.

A route table sends traffic by destination. A default route to an internet gateway is the only thing that makes a subnet public.

Public and private subnets · Going deeper · 2 of 2

A NAT gateway: out, but not in

Virtual networkPublic subnetPrivate subnetInternetan update serverInternet gatewayNAT gatewayone public addressApplication serverprivate address onlyout: allowedin, uninvited: dropped ✗A NAT gateway lets private machines call out, and lets nobody call in.Private servers still need to fetch updates and call outside APIs. The NAT gateway sits in a public subnet and makesthose calls on their behalf under its own public address; replies come back, uninvited traffic does not. It is a paidservice: on AWS about $0.045 an hour plus $0.045 per GB passed. Azure NAT Gateway and Google Cloud NAT do the same.

A NAT gateway lets private machines start connections to the internet while refusing connections from it.

Security groups

Every port is closed until a rule opens it

The internetSecurity group: webWeb serversport 443, HTTPS ✓allow 443 from anywhereport 22, SSH ✗Security group: dbDatabaseport 5432 ✓allow 5432 from group webstraight to the database: no rule allows it, so it is dropped ✗A security group is a firewall around each machine. Everything is blocked until a rule allows it.A rule names a port and who may use it. The source can be another security group, so “only the web servers mayreach the database” stays true as servers come and go. Security groups are stateful: a reply to an allowed requestis let back automatically. Leaving port 22 or 3389 open to the whole internet is the classic mistake.

A security group is a firewall around a machine. It blocks everything except what its rules allow.

Security groups · Going deeper · 1 of 2

Four firewalls compared: stateful and stateless

AWS security groupAWS network ACLAzure NSGGoogle firewall ruleGuardsone machine’s network carda whole subneta subnet or a cardmachines chosen by tagRules canallow onlyallow and denyallow and denyallow and denyReplieslet back automaticallyneed their own rulelet back automaticallylet back automaticallyOrderall rules are combinedlowest number firstby priority numberby priority numberBy defaultnothing in, all outeverything allowedin from the internet deniedin denied, out allowedTwo words to know: stateful firewalls remember a conversation, stateless ones judge every packet alone.Stateful means that if a request was allowed, its reply is too, with no extra rule. Only the AWS network ACL is stateless:it needs a rule for each direction. In practice security groups do the daily work, and a network ACL is added whena whole subnet must refuse something outright, such as one hostile address range. NSG is a network security group.

Security groups, Azure NSGs and Google firewall rules are stateful. The AWS network ACL guards a whole subnet and is stateless.

Security groups · Going deeper · 2 of 2

Before the firewall: DDoS protection and the web application firewall

InternetDDoS protectionat the provider’s edgefloods of junk trafficAWS Shield · Azure DDoS ProtectionGoogle Cloud ArmorWeb application firewallreads each web requestinjected code, bad botsAWS WAF · Azure Web ApplicationFirewall · Google Cloud ArmorSecurity grouparound each machineevery port you did not opensecurity group · NSGfirewall rulesYour appThree filters stand between the internet and your application, each removing a different kind of harm.A DDoS attack tries to drown a site in traffic; the provider absorbs it at the edge, and the basic tier is free andalways on. A web application firewall (WAF) inspects web requests for known attacks such as SQL injection andcross-site scripting. What is left meets the security group. You configure the second and third.

DDoS protection absorbs floods at the edge and a WAF filters malicious web requests before the security group sees them.

Load balancers

One address in front of many servers

UsersLoad balancerone address for everyoneZone aZone b✓10.0.1.25 · healthy · a third of requests✓10.0.2.14 · healthy · a third of requests✓10.0.2.20 · healthy · a third of requests✗10.0.1.31 · failed its health check · noneA load balancer gives many servers one address, and sends each request only to a healthy one.It checks every server every few seconds. One that stops answering is taken out within moments and put back whenit recovers, and users never see the failure. Servers can be added or removed behind it at any time, across zones,which is what makes both scaling out and surviving a failure possible.

A load balancer spreads requests across servers in several zones and uses health checks to skip any that fail.

Load balancers · Going deeper

Layer 4 and layer 7: two kinds of load balancer

Network load balancer (layer 4)Application load balancer (layer 7)It seesan IP address and a portthe web request: host name, path, headersIt can route byportcontent: /api to one group, /images to anotherGood forany protocol, millions of connections, least delaywebsites and APIs, HTTPS certificates, redirectsAWSNetwork Load BalancerApplication Load BalancerAzureAzure Load BalancerApplication Gateway; Front Door across regionsGoogle CloudNetwork Load BalancerApplication Load Balancer, one global addressTwo kinds: one forwards connections without reading them, the other reads each web request.The layer numbers come from the standard model of networking: layer 4 is transport (TCP and UDP), layer 7 is theapplication (HTTP). A layer 7 balancer can also hold the HTTPS certificate, so servers behind it need none.Across regions, Azure Front Door, AWS Global Accelerator and Google’s global balancer send users to the nearest healthy region.

A network load balancer forwards connections by port; an application load balancer reads each web request and can route by its path.

DNS

The name decides where the user lands

A user in ParisManaged DNSshop.example.comrule: answer with the nearesthealthy region1 where is it?Ireland54.220.10.818 ms from ParisN. Virginia3.80.14.295 ms from Parishealth checks2 at 54.220.10.83 connects to IrelandDNS turns a name into an address, and a managed DNS service chooses which address to give.Because every visit starts with a DNS question, the answer can steer traffic: to the nearest region, away from a failed one,or 10% to a new version. The services are Amazon Route 53, Azure DNS with Traffic Manager, and Google Cloud DNS.Route 53 is named after port 53, the port DNS uses, and carries a 100% availability promise.

Managed DNS answers a name with an address, and can pick the nearest or the healthiest region.

DNS · Going deeper · 1 of 2

Routing rules: weighted, latency, failover and geolocation

Routing ruleWhat the DNS service answersUsed forSimplealways the same addressa site in one placeWeightedaddress A 90% of the time, address B 10%trying a new version on a few users firstLatencythe region that responds fastest for this useran application in several regionsFailoverthe standby, once the primary fails its health checkdisaster recoveryGeolocationan address chosen by the user’s countrylegal rules, language, local contentOne name, several possible answers. The routing rule decides which one each user gets.These are the Route 53 names. Azure Traffic Manager calls them priority (failover), weighted, performance (latency)and geographic. Answers are remembered by the asker for a set time, the TTL, so a change does not reach everyoneat once: with a TTL of 60 seconds, failover completes within about a minute.

Routing rules let one name return different addresses: by percentage, by speed, by health or by country.

DNS · Going deeper · 2 of 2

Domains, zones and records

A managed DNS service does three jobs: it registers the domain, hosts its records and checks the health of what they point to.

The parts

  • Domain the name you register and renew each year, such as example.com. Route 53 and Google Cloud Domains can register it; Azure DNS hosts names registered elsewhere.
  • Zone the container for all the records of one domain. On Route 53 it is called a hosted zone. A private zone answers only inside your virtual network.
  • Record one line that maps a name to an answer.

Records you will meet

Aa name to an IPv4 address
AAAAa name to an IPv6 address
CNAMEa name to another name
MXwhere the domain’s email goes
Every record has a TTL, the number of seconds an answer may be remembered. A long TTL means fewer questions and slower changes; a short one the reverse. Lower it a day before a planned move.

Connecting your own building

Two ways in: a VPN over the internet, or a dedicated line

Your buildingOffice or data centre192.168.0.0/16Your virtual networkIn the cloud10.0.0.0/16VPN: an encrypted tunnel across the public internetready in hours · up to 1.25 gigabits a second per tunnel · speed variesDedicated line: private fibre that never touches the internetweeks to install · 1 to 100 gigabits a second · steady speed and delayTwo ways to join your own building to your cloud network: a VPN over the internet, or a private line.Both make the two networks behave as one, using private addresses on each side. A VPN is cheap and quick:AWS Site-to-Site VPN, Azure VPN Gateway, Google Cloud VPN. A dedicated line costs more and gives steady, highcapacity: AWS Direct Connect, Azure ExpressRoute, Google Cloud Interconnect. Many companies run both, the VPN as backup.

A VPN is an encrypted tunnel over the internet; a dedicated line is private fibre with steady, high capacity.

Connecting your own building · Going deeper · 1 of 2

Joining networks to each other: peering and hubs

Peering: a link for every pair15links for6 networksA hub: one link each6links for6 networksPeering joins two networks privately. Past a handful, a hub is simpler: 15 links become 6.Peered networks talk over the provider’s backbone using private addresses. Peering does not pass traffic on to a thirdnetwork, so every pair that must talk needs its own link: 20 networks would need 190. A hub connects each network once, andthe VPN or dedicated line to your building plugs into the same hub: AWS Transit Gateway, Azure Virtual WAN.

Peering links two virtual networks privately. A hub such as Transit Gateway or Virtual WAN replaces a mesh of peerings.

Connecting your own building · Going deeper · 2 of 2

Private endpoints: reaching a service without the internet

Your virtual network: private subnetApplication serverObject storagethe provider’s serviceNAT gatewayout over the public internetPrivate endpointan address inside your subnetstays on the provider’s private networkA private endpoint puts a provider’s service inside your network, so traffic to it never crosses the internet.Object storage, managed databases and other services have public addresses by default. A private endpoint givesone of them a private address in your subnet. You can then block the public route entirely, which many regulatorsexpect. The names: AWS PrivateLink and VPC endpoints, Azure Private Link, Google Private Service Connect.

A private endpoint gives a provider’s service a private address in your subnet, so the traffic stays off the public internet.

The whole path

One request passes six steps, and only one faces the internet

Virtual networkPublicPrivate subnets1 Usertypes the name2 DNSname to address,nearest region3 Edgecached files inabout 10 ms4 Balancerpicks a healthyserver5 Web serverruns the code6 Databaseport 5432, fromweb onlyOne request passes six steps, and only one of them, the load balancer, faces the internet.The name is resolved, static files come from the edge, the load balancer accepts the connection in a public subnet,and the servers that do the work sit in private subnets behind security groups. This is the standard shape of a webapplication on any cloud. Lessons 3, 4 and 5 supplied the edge, the servers and the storage; the next supplies the database.

DNS, the edge, a load balancer in a public subnet, then servers and a database in private subnets: the standard shape.

The whole path · Going deeper

What moving data costs

Moving 1,000 GBprice per GBIn from the internetfree$0$0Between zones in a regionin each direction$0.01$10Between regionsN. Virginia to Ohio$0.02$20Out to the internetafter the first 100 GB a month$0.09$90Data coming in is free. Data going out, and data moving between zones and regions, is charged by the gigabyte.This is the bill that surprises people. A busy site sending video to the world pays for every gigabyte out; a chattysystem spread across zones pays a little for every call. A CDN, private endpoints and keeping talkative parts inone zone all reduce it. Example AWS list prices, 2025; Azure and Google Cloud charge in the same pattern.

Data in is free. Data transfer out to the internet, and traffic between zones and regions, is billed per gigabyte.

Lesson complete

You finished “Networking”

Nicely done.

Open in a new tab