The OSI & TCP/IP Models
The OSI model is a 7-layer conceptual framework. The TCP/IP model is the 4-layer version networks actually run on. Knowing how they map helps you reason about where a problem lives.
| OSI Layer | Name | Examples | TCP/IP | AWS Service |
|---|---|---|---|---|
| 7 | Application | HTTP, HTTPS, FTP, DNS | Application | API Gateway, CloudFront |
| 6 | Presentation | SSL/TLS, JPEG, encoding | Application | ACM (TLS certs) |
| 5 | Session | NetBIOS, RPC, sockets | Application | - |
| 4 | Transport | TCP, UDP | Transport | NLB (Layer 4) |
| 3 | Network | IP, ICMP, routing | Internet | VPC, Route Tables, GLB |
| 2 | Data Link | Ethernet, MAC, ARP | Link | ENI, Direct Connect |
| 1 | Physical | Cables, fiber, radio | Link | Direct Connect (physical) |
ALB = Layer 7 (HTTP-aware). NLB = Layer 4 (TCP/UDP). GLB = Layer 3 (IP). This mapping is tested constantly - memorize it.
Encapsulation
As data travels down the stack, each layer wraps it with its own header. This is encapsulation; the receiver reverses it (decapsulation).
Application data
→ + TCP header = Segment (Layer 4)
→ + IP header = Packet (Layer 3)
→ + Frame header/trailer = Frame (Layer 2)
→ bits on the wire (Layer 1)
MTU (typically 1500 bytes) limits frame size. AWS supports jumbo frames (9001 MTU) within a VPC for higher throughput, but paths crossing the internet or some gateways fall back to 1500.
TCP vs UDP
TCP
- Connection-oriented (3-way handshake)
- Reliable, ordered, retransmitted delivery
- Flow control & congestion control
- Higher overhead
- Use for: HTTP(S), SSH, FTP, SMTP, database
UDP
- Connectionless - fire and forget
- No guarantee of delivery or order
- Very low latency, minimal overhead
- No congestion control
- Use for: DNS, VoIP, video streaming, gaming, QUIC
NLB supports both TCP and UDP listeners. ALB is HTTP/HTTPS only. If a scenario needs UDP (gaming, IoT, DNS), the answer is NLB, not ALB.
Handshake & Connection Lifecycle
TCP 3-way handshake (open):
Client → SYN → Server
Client ← SYN, ACK ← Server
Client → ACK → Server
[connection established]
TCP 4-way teardown (close):
Client → FIN → Server
Client ← ACK ← Server
Client ← FIN ← Server
Client → ACK → Server
A connection stuck in SYN_SENT usually means a firewall/Security Group is silently dropping the SYN. A flood of TIME_WAIT sockets is normal after many short-lived connections. Inspect with ss -tan.
IP Addressing
A 32-bit IPv4 address written as 4 octets: 192.168.1.100. Each address has a network portion and a host portion, determined by the subnet mask.
Private IP Ranges (RFC 1918)
10.0.0.0/8 → 10.0.0.0 - 10.255.255.255 (common for AWS VPCs)
172.16.0.0/12 → 172.16.0.0 - 172.31.255.255 (AWS default VPC: 172.31.0.0/16)
192.168.0.0/16 → 192.168.0.0 - 192.168.255.255 (home networks)
| Type | Example | Notes |
|---|---|---|
| Public | 54.239.28.85 | Routable on the internet |
| Private | 10.0.1.20 | RFC 1918, not internet-routable |
| Loopback | 127.0.0.1 | The local host itself |
| Link-local | 169.254.0.0/16 | Includes IMDS at 169.254.169.254 |
VPCs use private ranges. The default VPC is 172.31.0.0/16. The special address 169.254.169.254 serves EC2 instance metadata.
CIDR & Subnetting
CIDR notation pairs an IP with a prefix length: 10.0.0.0/16. The prefix says how many leading bits are the network portion. Smaller prefix = bigger network.
| CIDR | Subnet Mask | Total IPs | AWS Usable |
|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,531 |
| /20 | 255.255.240.0 | 4,096 | 4,091 |
| /24 | 255.255.255.0 | 256 | 251 |
| /25 | 255.255.255.128 | 128 | 123 |
| /26 | 255.255.255.192 | 64 | 59 |
| /27 | 255.255.255.224 | 32 | 27 |
| /28 | 255.255.255.240 | 16 | 11 |
Network address (.0), VPC router (.1), Amazon DNS (.2), future use (.3), and network broadcast (last). A /24 therefore gives 251 usable IPs, not 254. Frequently tested!
# Total IPs in a block = 2^(32 - prefix)
/28 = 2^4 = 16 IPs (11 usable in AWS)
/24 = 2^8 = 256 IPs (251 usable in AWS)
/16 = 2^16 = 65,536 IPs
# VPC CIDR can be /16 (max) to /28 (min) in AWSSubnetting: Worked Example
Split a VPC 10.0.0.0/16 into public and private subnets across two AZs:
| Subnet | CIDR | AZ | Purpose | Usable IPs |
|---|---|---|---|---|
| Public A | 10.0.0.0/24 | us-east-1a | ALB, NAT GW | 251 |
| Public B | 10.0.1.0/24 | us-east-1b | ALB, NAT GW | 251 |
| Private A | 10.0.10.0/24 | us-east-1a | App servers | 251 |
| Private B | 10.0.11.0/24 | us-east-1b | App servers | 251 |
| DB A | 10.0.20.0/24 | us-east-1a | RDS | 251 |
| DB B | 10.0.21.0/24 | us-east-1b | RDS | 251 |
Never overlap CIDR blocks between VPCs you plan to peer or connect - overlapping ranges make routing impossible. Plan address space up front.
IPv6 Basics
128-bit addresses written in hex, e.g. 2001:db8::1. Solves IPv4 exhaustion. In AWS, IPv6 addresses are globally unique and public by default - there is no NAT for IPv6.
::1 # IPv6 loopback (like 127.0.0.1)
fe80::/10 # Link-local
2001:db8::/32 # Documentation range
Because IPv6 has no NAT, AWS uses an Egress-Only Internet Gateway to allow outbound-only IPv6 traffic from private subnets - the IPv6 equivalent of a NAT Gateway.
Key Protocols & Ports
| Protocol | Port | Transport | Use |
|---|---|---|---|
| HTTP | 80 | TCP | Web (plaintext) |
| HTTPS | 443 | TCP | Web (TLS) |
| SSH | 22 | TCP | Secure shell |
| RDP | 3389 | TCP | Windows remote desktop |
| DNS | 53 | UDP/TCP | Name resolution |
| DHCP | 67/68 | UDP | Dynamic IP assignment |
| NTP | 123 | UDP | Time sync |
| SMTP | 25/587 | TCP | Email send |
| MySQL/Aurora | 3306 | TCP | Database |
| PostgreSQL | 5432 | TCP | Database |
| Redis (ElastiCache) | 6379 | TCP | Cache |
| NFS (EFS) | 2049 | TCP | Network file system |
When a Security Group question involves a database, remember the port: RDS MySQL/Aurora = 3306, PostgreSQL = 5432, EFS = 2049. The SG on the DB must allow the app tier's SG on that port.
DNS Deep Dive
Record types
| Record | Purpose | Example |
|---|---|---|
| A | Name → IPv4 | example.com → 93.184.216.34 |
| AAAA | Name → IPv6 | example.com → 2606:2800::1 |
| CNAME | Alias to another name | www → example.com |
| MX | Mail server + priority | 10 mail.example.com |
| TXT | Text (SPF, DKIM, verification) | "v=spf1 ..." |
| NS | Name servers for a zone | ns-1.awsdns.com |
| SOA | Zone authority / metadata | primary NS + serial |
| Alias (Route 53) | Map apex to AWS resource | example.com → ALB DNS |
How a lookup works
Browser → Recursive resolver → Root (.) → TLD (.com) → Authoritative NS → Answer
(cached along the way, controlled by TTL)
Route 53 routing policies
| Policy | Use |
|---|---|
| Simple | One record, no logic |
| Weighted | Split traffic by percentage (A/B, canary) |
| Latency | Route to lowest-latency region |
| Failover | Primary/secondary with health checks |
| Geolocation | Route by user's country/continent |
| Geoproximity | Route by geographic distance + bias |
| Multivalue | Return several healthy IPs |
You cannot use a CNAME at the zone apex (naked domain like example.com). Use a Route 53 Alias record instead - it maps to AWS resources (ALB, CloudFront, S3) and is free of charge.
DHCP & ARP
DHCP hands out IP configuration automatically via the DORA exchange:
Discover → Offer → Request → Acknowledge (client gets IP, mask, gateway, DNS)
ARP (Address Resolution Protocol) maps an IP address to a MAC address on the local link, so frames can be delivered at Layer 2.
In a VPC, AWS runs DHCP for you. DHCP Option Sets let you customize the DNS servers and domain name handed to instances - useful for hybrid setups pointing at on-prem DNS.
NAT Gateway vs NAT Instance
NAT Gateway (Managed)
- Fully managed, highly available within an AZ
- Private subnet → internet, outbound only
- Requires an Elastic IP, lives in a public subnet
- Scales automatically up to 100 Gbps
- No security group (it is managed)
NAT Instance (Legacy)
- An EC2 instance doing NAT manually
- Must disable Source/Destination Check
- You manage patching, sizing, and HA
- Can double as a bastion host
- Cheaper at tiny scale, more work
Deploy one NAT Gateway per AZ and point each AZ's private route table at its local NAT GW. This avoids cross-AZ data charges and survives an AZ failure.
Routing & Route Tables
A route table is a set of rules matching destination CIDRs to targets. The most specific (longest prefix) match wins.
| Destination | Target | Meaning |
|---|---|---|
| 10.0.0.0/16 | local | Traffic inside the VPC (always present) |
| 0.0.0.0/0 | igw-xxxx | Default route to internet (public subnet) |
| 0.0.0.0/0 | nat-xxxx | Default route via NAT (private subnet) |
| 172.16.0.0/12 | pcx-xxxx | Peered VPC |
| 192.168.0.0/16 | vgw-xxxx | On-prem via VPN/Direct Connect |
If both 0.0.0.0/0 and 10.0.5.0/24 could match, the /24 wins because it is more specific. This is how you steer specific traffic to a firewall appliance while everything else uses the default route.
Load Balancers
| Type | OSI Layer | Protocol | Best For |
|---|---|---|---|
| ALB | 7 | HTTP, HTTPS, gRPC | Web apps, microservices, path/host routing |
| NLB | 4 | TCP, UDP, TLS | Ultra-low latency, static IP, gaming, IoT |
| GLB | 3 | IP (GENEVE) | Inline virtual appliances (firewalls, IDS/IPS) |
Key features
- Health checks: unhealthy targets are removed from rotation automatically.
- Target groups: route to EC2, IPs, Lambda (ALB), or other resources.
- Cross-zone load balancing: spread traffic evenly across AZs (on by default for ALB).
- Sticky sessions: pin a client to one target (ALB cookies).
- ALB routing: by path (
/api/*), host header, HTTP header, or query string.
Only NLB provides a static IP per AZ (and supports Elastic IPs). ALB's IPs change, so front it with a DNS name or use NLB when a fixed IP is required.
Security Groups vs Network ACLs
Security Groups
- Operate at the instance / ENI level
- Stateful - return traffic is auto-allowed
- ALLOW rules only (no explicit deny)
- All rules evaluated together
- Default: deny all inbound, allow all outbound
Network ACLs
- Operate at the subnet level
- Stateless - must allow both directions
- ALLOW and DENY rules
- Rules evaluated in number order, lowest first
- Default NACL allows all; custom NACL denies all
Because NACLs are stateless, you must open ephemeral ports (1024-65535) for return traffic. Security Groups handle return traffic automatically. This distinction is a classic exam trap.
TLS & Certificates
TLS encrypts traffic and authenticates the server via a certificate signed by a trusted CA. The handshake negotiates keys before any application data flows.
Client Hello → Server Hello (+ certificate)
→ key exchange → Finished → encrypted application data
- ACM (AWS Certificate Manager): free public certs, auto-renewed, integrates with ALB, CloudFront, API Gateway.
- TLS termination: the load balancer decrypts, so backends can serve HTTP internally.
- End-to-end encryption: re-encrypt from LB to target when compliance requires it.
- SNI: host multiple certs/domains on one listener.
For CloudFront, the ACM certificate must be in us-east-1, regardless of where your origin lives. For a regional ALB, the cert lives in the ALB's region.
AWS VPC Overview
A VPC (Virtual Private Cloud) is your logically isolated network in AWS.
- VPC - the network boundary; a CIDR block such as
10.0.0.0/16. - Subnets - subdivide the VPC; each subnet lives in exactly one AZ.
- Internet Gateway (IGW) - enables internet access for public subnets.
- Route Tables - control where subnet traffic is directed.
- NAT Gateway - outbound-only internet for private subnets.
- Elastic Network Interface (ENI) - a virtual NIC attached to instances.
- Elastic IP (EIP) - a static public IPv4 you own.
A public subnet has a route 0.0.0.0/0 → igw-xxx. A private subnet has no direct route to an IGW. The difference lives entirely in the route table.
flowchart TB
Internet((Internet)) --- IGW[Internet Gateway]
IGW --- ALB[Application Load Balancer]
subgraph VPC["VPC 10.0.0.0/16"]
subgraph AZA["AZ us-east-1a"]
PubA[Public Subnet 10.0.0.0/24
NAT Gateway] --> WebA[EC2 Web Tier]
WebA --> AppA[EC2 App Tier
Private Subnet]
AppA --> DBA[(RDS Primary
DB Subnet)]
end
subgraph AZB["AZ us-east-1b"]
PubB[Public Subnet 10.0.1.0/24
NAT Gateway] --> WebB[EC2 Web Tier]
WebB --> AppB[EC2 App Tier
Private Subnet]
AppB --> DBB[(RDS Standby
DB Subnet)]
end
ALB --- WebA
ALB --- WebB
DBA -. Multi-AZ replication .- DBB
endVPC Connectivity Options
| Option | Connects | Notes |
|---|---|---|
| VPC Peering | Two VPCs | 1:1, non-transitive, no overlapping CIDRs |
| Transit Gateway | Many VPCs + on-prem | Hub-and-spoke, transitive, scales to thousands |
| VPC Endpoint (Gateway) | VPC → S3 / DynamoDB | Free, via route table, stays on AWS network |
| VPC Endpoint (Interface) | VPC → most AWS services | PrivateLink ENI, hourly + data cost |
| Site-to-Site VPN | VPC ↔ on-prem | Over internet, IPsec encrypted, quick to set up |
| Direct Connect (DX) | VPC ↔ on-prem | Dedicated private link, consistent low latency |
| PrivateLink | Consumer VPC → provider service | Expose a service privately without peering |
If VPC A peers with B, and B peers with C, A cannot reach C through B. For any-to-any connectivity at scale, use a Transit Gateway.
A common resilient hybrid design: primary connectivity over Direct Connect for performance, with a Site-to-Site VPN as an encrypted failover path.
Connectivity Troubleshooting Playbook
| Symptom | Check in this order |
|---|---|
| Cannot SSH/RDP to instance | Security Group inbound → NACL → route table → key/user → OS firewall |
| Instance has no internet (public) | Public IP assigned? IGW attached? Route 0.0.0.0/0 → igw? SG outbound? |
| Private instance no outbound | NAT Gateway healthy? Route 0.0.0.0/0 → nat? NAT in a public subnet? |
| Cannot reach RDS | DB Security Group allows app SG on 3306/5432? Same VPC / peered? Subnet route? |
| DNS not resolving | VPC enableDnsSupport & enableDnsHostnames? Resolver at .2? dig output |
| Peered VPC unreachable | Routes on both sides? Non-overlapping CIDRs? SG/NACL allow peer CIDR? |
| Intermittent packet loss | MTU mismatch (jumbo frames)? Check with ping -M do -s 8972 |
VPC Reachability Analyzer traces the configured path between two resources and tells you exactly which SG, NACL, or route blocks it. VPC Flow Logs show ACCEPT/REJECT per flow - invaluable for diagnosing silent drops.
📋 Study Checklist
- Map the 7 OSI layers to the 4 TCP/IP layers
- Explain encapsulation and MTU / jumbo frames
- Explain the difference between TCP and UDP
- Describe the TCP 3-way handshake and connection states
- Identify private IP ranges (RFC 1918) and special addresses
- Calculate the number of IPs in a CIDR block
- Know why AWS reserves 5 IPs per subnet
- Design a multi-AZ public/private subnet layout without overlaps
- Understand IPv6 basics and the Egress-Only Internet Gateway
- Know common ports: 22, 80, 443, 53, 3306, 5432, 2049, 3389
- Explain DNS record types: A, AAAA, CNAME, MX, TXT, NS, Alias
- Describe how a recursive DNS lookup works and the role of TTL
- Compare Route 53 routing policies (weighted, latency, failover, geo)
- Explain CNAME vs Alias and the zone apex rule
- Understand DHCP (DORA) and ARP
- Explain NAT Gateway vs NAT Instance and the per-AZ HA pattern
- Read a route table and apply longest-prefix match
- Explain ALB vs NLB vs GLB and their layers
- Explain Security Groups vs Network ACLs (stateful vs stateless)
- Understand ephemeral ports for stateless NACL return traffic
- Understand TLS handshake, ACM, and TLS termination
- Know the CloudFront us-east-1 certificate requirement
- Understand core VPC components: IGW, route tables, subnets, ENI, EIP
- Compare VPC Peering, Transit Gateway, and VPC Endpoints
- Explain Site-to-Site VPN vs Direct Connect and hybrid failover
- Know that VPC Peering is non-transitive
- Use Reachability Analyzer and VPC Flow Logs to troubleshoot