Skip to Content
Cloud Engineering Academy
2. AWS Networking & Infrastructure

Networking refresher for developers

Refresh IP addresses, CIDR notation, ports, DNS and TLS — the five ideas every AWS networking decision is built on — and test them from Windows and C#.

beginner⏱ 45 min🟢 FreeSAA-C03SOA-C03

Assumes: .NET 10 LTS · AWS CLI v2 · PowerShell 5.1+ · Region us-east-1. Verified against official sources on 2026-11-17.

Learning objectives

By the end of this lesson you can:

  • Read an IPv4 address and a CIDR block such as 10.20.64.0/20 and say how many addresses it holds, where it starts and where it ends.
  • Name the private address ranges (RFC 1918) and explain why banks use them for every internal system.
  • Explain ports, TCP vs UDP, and ephemeral ports — the detail that later breaks network ACLs.
  • Follow a DNS lookup and a TLS handshake step by step, and say which layer (3, 4 or 7) a device works at.
  • Test name resolution and TCP reachability from PowerShell and from C#.

Prerequisites

  • Module 1: AWS fundamentals — Regions, Availability Zones, CLI with SSO.
  • Tools: Windows PowerShell, .NET 10 SDK, AWS CLI v2 with the learn-sandbox profile.

Why this matters in banking

A payments engineer at a bank once spent two days on a "the API is down" incident. The API was fine. A firewall change had blocked the return traffic on ephemeral ports, so connections opened and then hung. Nobody on the call could read the firewall rule and connect it to how TCP works.

In AWS you own the network design that, on-premises, a separate network team owned. Every later lesson in this module — subnets, route tables, security groups, NACLs, load balancers, Route 53, VPN — assumes the five ideas in this lesson. If you can reason about addresses, ports and DNS, you can answer the question every bank auditor asks: "show me exactly which systems can talk to the customer database, and how you know."

The idea in plain language

Five ideas, each one sentence first:

  1. IP address — the postal address of a network interface. IPv4 is 32 bits written as four numbers (10.20.64.15); IPv6 is 128 bits written in hex (2001:db8::15).
  2. CIDR block — a range of addresses written as start/prefix. The prefix says how many leading bits are fixed. 10.20.0.0/16 fixes 16 bits, leaving 16 bits (65,536 addresses) free.
  3. Port — the door number on a host. The address gets the packet to the building; the port gets it to the right application (443 for HTTPS, 5432 for PostgreSQL, 1433 for SQL Server).
  4. DNS — the phone book that turns api.harbourline.example into an IP address.
  5. TLS — the sealed envelope: it encrypts the conversation and proves the server is who it claims to be.

Analogy: a bank branch. The street address is the IP address. The branch's postcode area is the CIDR block (every building whose address starts with "EC2A" is in the same area). The counter number inside is the port. Directory enquiries is DNS. The sealed, signed envelope you hand over the counter is TLS.

IPv4 and CIDR, worked in binary

10.20.64.0/20 means: the first 20 bits are the network, the last 12 bits number the hosts.

Octet1020640
Binary00001010000101000100 000000000000
Fixed by /20?all 8all 8first 4none
  • Host bits: 32 − 20 = 12, so 2¹² = 4,096 addresses.
  • First address: 10.20.64.0. Last address: the third octet's free 4 bits all set to 1 → 0100 1111 = 79 → 10.20.79.255.
  • So 10.20.64.0/20 covers 10.20.64.0 to 10.20.79.255. The next /20 starts at 10.20.80.0.

Quick rules you will use daily:

PrefixAddressesTypical AWS use
/1665,536A whole VPC (the largest AWS allows)
/1816,384One tier across four AZs
/204,096A subnet for containers or Lambda ENIs
/24256A small subnet
/2816The smallest subnet AWS allows
/321One host (common in firewall rules)
/0everything"Anywhere" — 0.0.0.0/0

AWS reserves five addresses in every subnet (the network address, the VPC router, DNS, one for future use, and the last address), so a /20 gives you 4,091 usable addresses and a /28 only 11.

Private and special ranges

RFC 1918 reserves three ranges that are never routed on the public internet:

RangeSizeHarbourline use
10.0.0.0/816.7 millionData centres and every AWS VPC
172.16.0.0/121 millionStaff remote-access VPN (172.16.0.0/16)
192.168.0.0/1665,536Home routers — avoid in corporate plans

Two more ranges matter: 100.64.0.0/10 is carrier-grade NAT space (some ISPs and container platforms use it; never put workloads there without checking), and 169.254.0.0/16 is link-local — in AWS, 169.254.169.254 is the instance metadata service and 169.254.169.253 is the Amazon DNS resolver.

IPv6 in one paragraph

IPv6 addresses are 128 bits, so there is no shortage and no need for NAT. AWS gives a VPC a /56 and each subnet a /64. Every IPv6 address AWS assigns is globally unique and publicly routable — "private" in IPv6 comes from routing and firewalls, not from the address range. Most bank workloads today are IPv4-first with dual-stack where a partner or regulator requires it.

Ports, TCP and UDP

  • TCP opens a connection with a three-way handshake (SYN, SYN-ACK, ACK), then guarantees ordered delivery. HTTP, TLS, PostgreSQL and SQL Server use TCP.
  • UDP sends independent datagrams with no handshake. DNS queries (usually), NTP and many VPN protocols use UDP.
  • ICMP is for control messages (ping, "destination unreachable"). It has no ports.

When your HttpClient connects to 10.20.128.10:5432, the destination port is 5432. The source port is picked by the operating system from the ephemeral range — Linux uses 32768–60999, Windows 49152–65535, and AWS documentation recommends allowing 1024–65535 for return traffic. Remember this: a stateless firewall (a network ACL) must allow the reply back to that random high port.

The layers that matter

LayerNameWhat it seesAWS example
3NetworkIP addressesRoute tables, NACLs
4TransportPorts, TCP/UDPSecurity groups, Network Load Balancer
7ApplicationHTTP paths, headers, hostnamesApplication Load Balancer, AWS WAF, API Gateway

DNS resolution, step by step

The TTL (time to live) is how long resolvers may cache the answer. Low TTLs make failover faster but increase query volume.

TLS in four steps

  1. The client says hello and lists the cipher suites it supports.
  2. The server sends its certificate chain; the client checks the name matches and the chain leads to a trusted root.
  3. Both sides agree keys (ECDHE in TLS 1.3) — nobody watching can derive them.
  4. Application data flows encrypted. In AWS, TLS can end at the load balancer, at your container, or both ("re-encryption").

NAT in one paragraph

Network Address Translation rewrites addresses as packets pass. Your home router does it: many private addresses share one public address. AWS uses it in two places you will meet soon: the Internet Gateway maps a public IPv4 address one-to-one onto an instance's private address, and the NAT Gateway lets many private instances share one public address for outbound-only traffic.

What problem this knowledge solves

AWS gives you building blocks, not a finished network. The VPC wizard will happily create overlapping ranges, open ports to 0.0.0.0/0, or put a database in a subnet with an internet route. The console will not stop you. These fundamentals are how you spot mistakes before an attacker or an auditor does.

The honest limits: this lesson covers IPv4 deeply and IPv6 briefly. BGP (the routing protocol between networks) appears only in the hybrid connectivity lesson, and only conceptually.

Microsoft / Azure comparison

You know (Microsoft/Azure)AWS equivalentWhat's different
Test-NetConnection -PortSame tool, or Reachability AnalyzerReachability Analyzer proves a path without sending packets
Resolve-DnsName, nslookupSame tools; Route 53 Resolver inside a VPCThe VPC resolver lives at VPC base address + 2
Azure VNet address spaceVPC CIDR block(s)VPC is /16 to /28; you can add secondary CIDRs
Azure reserves 5 IPs per subnetAWS reserves 5 IPs per subnetSame count, slightly different positions
Kestrel ListenAnyIP(8080)Container/instance port + security group ruleOpening a port in code is not enough; the SG must allow it
Windows FirewallSecurity groups (stateful) and NACLs (stateless)Both live outside the guest OS

Architecture

The rest of the module builds this shape; each label uses an idea from this lesson.

Step-by-step implementation

Find your own addresses

Run ipconfig /all in PowerShell. Note your IPv4 address, subnet mask (255.255.255.0 is the same as /24), default gateway and DNS servers. Convert the mask to a prefix length: count the 1 bits.

Resolve a name and inspect the TTL

Resolve-DnsName aws.amazon.com -Type A shows the answer and TTL. Run it twice; caching changes what you see.

Test TCP reachability

Test-NetConnection sts.us-east-1.amazonaws.com -Port 443 — TcpTestSucceeded : True means the three-way handshake completed. Try port 5432 on the same host and watch it fail (nothing listens there).

Calculate a CIDR by hand, then in code

Work out the first and last address of 10.20.144.0/20 on paper, then run the C# program below to check yourself.

Connect it to AWS

List the Availability Zones in us-east-1 with the CLI. Each subnet you create later lives in exactly one of them.

AWS Console instructions

Nothing to create. To see where these ideas appear, open Console → VPC → Your VPCs in us-east-1 and look at the IPv4 CIDR column of the default VPC (usually 172.31.0.0/16). Then VPC → Subnets shows each default subnet's /20 and its Available IPv4 addresses — 4,091, because of the five reserved addresses.

AWS CLI

# Which identity and account am I using? (sanity check before any AWS command)
aws sts get-caller-identity --profile learn-sandbox

# The Availability Zones you can place subnets in (names like us-east-1a, IDs like use1-az1)
aws ec2 describe-availability-zones --region us-east-1 --profile learn-sandbox `
  --query "AvailabilityZones[].[ZoneName,ZoneId,State]" --output table

# The default VPC's CIDR and its subnets' CIDRs and free addresses
aws ec2 describe-subnets --region us-east-1 --profile learn-sandbox `
  --filters Name=default-for-az,Values=true `
  --query "Subnets[].[AvailabilityZone,CidrBlock,AvailableIpAddressCount]" --output table

# Windows tools: DNS answer with TTL, then a TCP handshake test on 443
Resolve-DnsName sts.us-east-1.amazonaws.com -Type A
Test-NetConnection sts.us-east-1.amazonaws.com -Port 443

AZ names (us-east-1a) are mapped differently in each account; AZ IDs (use1-az1) are the same physical location everywhere. Use IDs when coordinating with another account, such as a partner's PrivateLink endpoint.

Infrastructure as Code

Nothing to deploy yet. Both IaC tools have CIDR helpers you will use from the next lessons:

// CDK computes subnet ranges from a VPC CIDR and a mask
var vpc = new Vpc(this, "Vpc", new VpcProps
{
    IpAddresses = IpAddresses.Cidr("10.20.0.0/16"),
    SubnetConfiguration = [ new SubnetConfiguration { Name = "app", SubnetType = SubnetType.PRIVATE_ISOLATED, CidrMask = 20 } ],
});

Complete code

A pure .NET console app (no AWS packages): it parses a CIDR, prints the range, resolves a name and tests a TCP port.

NetCheck.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
</Project>
Program.cs
using System.Net;
using System.Net.Sockets;

// Usage: dotnet run -- 10.20.64.0/20 sts.us-east-1.amazonaws.com 443
var cidrText = args.Length > 0 ? args[0] : "10.20.64.0/20";
var host = args.Length > 1 ? args[1] : "sts.us-east-1.amazonaws.com";
var port = args.Length > 2 ? int.Parse(args[2]) : 443;

// 1. CIDR maths with System.Net.IPNetwork (built into .NET 8+)
var network = IPNetwork.Parse(cidrText);
var hostBits = 32 - network.PrefixLength;
var total = 1UL << hostBits;
var first = ToUInt32(network.BaseAddress);
var last = first + (uint)(total - 1);
Console.WriteLine($"{network}: {total:N0} addresses, {FromUInt32(first)} - {FromUInt32(last)}");
Console.WriteLine($"Usable in an AWS subnet: {(network.PrefixLength is >= 16 and <= 28 ? (total - 5).ToString("N0") : "n/a (AWS allows /16 to /28)")}");
Console.WriteLine($"Contains 10.20.70.12? {network.Contains(IPAddress.Parse("10.20.70.12"))}");

// 2. DNS: what does this name resolve to from here?
var addresses = await Dns.GetHostAddressesAsync(host);
foreach (var a in addresses)
{
    Console.WriteLine($"{host} -> {a} ({a.AddressFamily})");
}

// 3. TCP: can we complete a handshake within 3 seconds?
using var client = new TcpClient();
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(3));
try
{
    await client.ConnectAsync(host, port, timeout.Token);
    var local = (IPEndPoint)client.Client.LocalEndPoint!;
    Console.WriteLine($"TCP {host}:{port} OK from local port {local.Port} (an ephemeral port)");
}
catch (Exception ex) when (ex is SocketException or OperationCanceledException)
{
    Console.WriteLine($"TCP {host}:{port} FAILED: {ex.Message}");
}

static uint ToUInt32(IPAddress ip)
{
    var b = ip.GetAddressBytes();
    return ((uint)b[0] << 24) | ((uint)b[1] << 16) | ((uint)b[2] << 8) | b[3];
}

static IPAddress FromUInt32(uint value) =>
    new([(byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value]);

Expected output (addresses vary):

10.20.64.0/20: 4,096 addresses, 10.20.64.0 - 10.20.79.255
Usable in an AWS subnet: 4,091
Contains 10.20.70.12? True
sts.us-east-1.amazonaws.com -> 203.0.113.24 (InterNetwork)   <- yours will be a real AWS address
TCP sts.us-east-1.amazonaws.com:443 OK from local port 53122 (an ephemeral port)

Code explained line by line

  1. IPNetwork.Parse(cidrText) — System.Net.IPNetwork (added in .NET 8) parses CIDR text and rejects host bits that are set, like 10.20.65.0/20.
  2. hostBits = 32 - network.PrefixLength — the free bits; 1UL << hostBits is 2 to that power. ulong because a /0 has 2³² addresses, more than a uint holds.
  3. ToUInt32(network.BaseAddress) — turns the four bytes into one number so "last address" is simple addition. Network byte order is big-endian, hence the shifts.
  4. total - 5 — the AWS reservation, only meaningful for /16 to /28.
  5. network.Contains(...) — the same "is this address in this range" test a route table performs.
  6. Dns.GetHostAddressesAsync(host) — uses the operating system resolver, exactly like HttpClient does. Inside a VPC, that is the Amazon resolver.
  7. new CancellationTokenSource(TimeSpan.FromSeconds(3)) — never wait forever on a network call; a dropped SYN (typical of a security group) otherwise hangs for about 20 seconds.
  8. client.ConnectAsync(host, port, timeout.Token) — performs the TCP three-way handshake only; no data is sent.
  9. LocalEndPoint — shows the ephemeral source port the OS picked, the port a NACL must let back in.
  10. catch (...) when (...) — a refused connection (SocketException, something answered "no") and a timeout (OperationCanceledException, nothing answered) mean different things: refused usually means "nothing listening", silence usually means "a firewall dropped it".

Security considerations

  • Private addresses are not a security control on their own. They stop direct routing from the internet, but anything that can reach your network (a VPN user, a peered VPC, a compromised host) can reach them. Security groups and route design are the controls.
  • Never put certificates' private keys or connection strings with passwords in code or config files. Module 5 covers Secrets Manager and KMS.
  • DNS answers can leak internal structure. Keep internal names in private hosted zones.
  • In GDPR terms, IP addresses can be personal data (a customer's home IP). Logs that hold them need a retention period and an access policy — your data-protection team decides these.

⚠ Learning shortcut — not for production

The test program connects without TLS validation details and prints raw addresses to the console. Production code uses HttpClient with the default certificate validation (never ServerCertificateCustomValidationCallback = (...) => true), structured logging with a correlation ID, and redacts client IPs where your data-protection policy requires it.

Banking use case

Harbourline Bank's Accounts API calls the core banking system in the London data centre (10.0.0.0/14) over a private link. During a release, calls start timing out. The on-call engineer runs Test-NetConnection from a test host to the core banking load balancer on 443: the TCP handshake succeeds. She then checks DNS: the new release used a config value with the public name of a test system, which resolved to an internet address the VPC has no route to. Knowing the difference between "DNS returned the wrong address" and "the port is blocked" turned a two-day incident into a ten-minute fix.

Common mistakes

  • Writing 10.20.1.0/16 → host bits are set; AWS and .NET reject it → use the true network address 10.20.0.0/16.
  • Assuming a /24 gives 256 usable addresses in AWS → it gives 251 → subtract 5 per subnet in every sizing calculation.
  • Opening only the server port on a stateless firewall → replies on ephemeral ports are dropped → allow 1024–65535 back out (see security groups vs NACLs).
  • Using 192.168.x.x for corporate networks → collides with staff home routers over VPN → keep corporate plans in 10.0.0.0/8.
  • Very long DNS TTLs on records you may fail over → clients keep the old address for hours → use 60–300 seconds on failover records.

Troubleshooting

SymptomLikely causeFix
Connection times out (no error for about 20 s)A firewall or security group silently dropped the SYNCheck SG inbound rules, NACLs and routes; use Reachability Analyzer
"Connection refused" immediatelyThe host is reachable but nothing listens on that portCheck the app is running and bound to 0.0.0.0, not 127.0.0.1
Name resolves to a public IP from inside the VPCMissing private hosted zone, or the wrong name in configUse the private DNS name; see Route 53
The remote certificate is invalidHostname does not match the certificate, or the chain is untrustedCall the name on the certificate; never disable validation
Works from your laptop, fails from AWSDifferent DNS (corporate vs VPC resolver) or different egress pathCompare Resolve-DnsName output in both places

Cost and cleanup

Cost: USD 0. The CLI calls are read-only describe operations, which are free. Nothing is created, so there is nothing to tear down. As a habit, confirm nothing from labs is running:

aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=cea-lab `
  --region us-east-1 --profile learn-sandbox --query "ResourceTagMappingList[].ResourceARN"

Exercises

  • 🟢 Guided: For each of 10.20.0.0/20, 10.20.16.0/20, 10.20.128.0/20 and 10.16.0.0/12, write the first address, last address, total and AWS-usable count. Check with the program.
  • 🟡 Challenge: Extend the program to accept a second CIDR and print whether the two overlap. (Hint: two CIDR blocks overlap only if one contains the other's first address.)
  • 🔴 Live problem: A colleague says "the database port is open but my .NET service still can't connect; it hangs for 21 seconds and then fails". List, in order, the four things you would check and the command or tool for each.

Assignment

Add a docs/networking-cheatsheet.md to your learning repository with: the prefix table, the private ranges, the five AWS-reserved addresses, the ephemeral port range, and one diagram of a DNS lookup. You will reuse it in every lesson of this module.

Solutions

Knowledge check

Interview questions

  • "Explain what 10.20.0.0/16 means." — A block whose first 16 bits are fixed: 65,536 addresses from 10.20.0.0 to 10.20.255.255. It is the largest block AWS allows for one VPC CIDR.
  • "What's the difference between a timeout and a connection refused?" — Refused: something at the address answered with a reset, usually nothing listening. Timeout: no answer at all, usually a firewall dropping packets or a missing route.
  • "Why do banks avoid overlapping private ranges?" — Overlapping networks cannot be routed to each other, so peering, VPN and Transit Gateway designs fail; fixing it later means re-addressing live systems.

Certification practice

Completion checklist

  • I can convert a prefix length to an address count and a range without a calculator
  • I know the three RFC 1918 ranges and why 100.64.0.0/10 and 169.254.0.0/16 are special
  • I ran the C# program and the PowerShell commands
  • I can explain why stateless firewalls need ephemeral port rules
  • I confirmed nothing tagged Project=cea-lab is running

Key takeaways

  • A CIDR prefix tells you how many bits are fixed; 32 minus the prefix gives the host bits.
  • AWS subnets lose five addresses each; VPCs are /16 to /28.
  • Ports pick the application; replies return to an ephemeral port.
  • Timeouts mean "dropped", refusals mean "nothing listening".
  • DNS mistakes look like network outages — check name resolution first.

Further reading

Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.

On this page