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 LayerNameExamplesTCP/IPAWS Service
7ApplicationHTTP, HTTPS, FTP, DNSApplicationAPI Gateway, CloudFront
6PresentationSSL/TLS, JPEG, encodingApplicationACM (TLS certs)
5SessionNetBIOS, RPC, socketsApplication -
4TransportTCP, UDPTransportNLB (Layer 4)
3NetworkIP, ICMP, routingInternetVPC, Route Tables, GLB
2Data LinkEthernet, MAC, ARPLinkENI, Direct Connect
1PhysicalCables, fiber, radioLinkDirect Connect (physical)
⚠ AWS Exam Tip

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)
☁️ Why it matters

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
⚠ AWS Exam Tip

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
💡 Debugging tip

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)
TypeExampleNotes
Public54.239.28.85Routable on the internet
Private10.0.1.20RFC 1918, not internet-routable
Loopback127.0.0.1The local host itself
Link-local169.254.0.0/16Includes IMDS at 169.254.169.254
☁️ AWS Context

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.

CIDRSubnet MaskTotal IPsAWS Usable
/16255.255.0.065,53665,531
/20255.255.240.04,0964,091
/24255.255.255.0256251
/25255.255.255.128128123
/26255.255.255.1926459
/27255.255.255.2243227
/28255.255.255.2401611
⚠ AWS Reserves 5 IPs Per Subnet

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 AWS

Subnetting: Worked Example

Split a VPC 10.0.0.0/16 into public and private subnets across two AZs:

SubnetCIDRAZPurposeUsable IPs
Public A10.0.0.0/24us-east-1aALB, NAT GW251
Public B10.0.1.0/24us-east-1bALB, NAT GW251
Private A10.0.10.0/24us-east-1aApp servers251
Private B10.0.11.0/24us-east-1bApp servers251
DB A10.0.20.0/24us-east-1aRDS251
DB B10.0.21.0/24us-east-1bRDS251
💡 Design rule

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
☁️ Egress-Only Internet Gateway

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

ProtocolPortTransportUse
HTTP80TCPWeb (plaintext)
HTTPS443TCPWeb (TLS)
SSH22TCPSecure shell
RDP3389TCPWindows remote desktop
DNS53UDP/TCPName resolution
DHCP67/68UDPDynamic IP assignment
NTP123UDPTime sync
SMTP25/587TCPEmail send
MySQL/Aurora3306TCPDatabase
PostgreSQL5432TCPDatabase
Redis (ElastiCache)6379TCPCache
NFS (EFS)2049TCPNetwork file system
⚠ AWS Exam Tip

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

RecordPurposeExample
AName → IPv4example.com → 93.184.216.34
AAAAName → IPv6example.com → 2606:2800::1
CNAMEAlias to another namewww → example.com
MXMail server + priority10 mail.example.com
TXTText (SPF, DKIM, verification)"v=spf1 ..."
NSName servers for a zonens-1.awsdns.com
SOAZone authority / metadataprimary NS + serial
Alias (Route 53)Map apex to AWS resourceexample.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

PolicyUse
SimpleOne record, no logic
WeightedSplit traffic by percentage (A/B, canary)
LatencyRoute to lowest-latency region
FailoverPrimary/secondary with health checks
GeolocationRoute by user's country/continent
GeoproximityRoute by geographic distance + bias
MultivalueReturn several healthy IPs
⚠ CNAME vs Alias

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.

☁️ DHCP Option Sets

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
💡 HA pattern

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.

DestinationTargetMeaning
10.0.0.0/16localTraffic inside the VPC (always present)
0.0.0.0/0igw-xxxxDefault route to internet (public subnet)
0.0.0.0/0nat-xxxxDefault route via NAT (private subnet)
172.16.0.0/12pcx-xxxxPeered VPC
192.168.0.0/16vgw-xxxxOn-prem via VPN/Direct Connect
⚠ Longest prefix match

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

TypeOSI LayerProtocolBest For
ALB7HTTP, HTTPS, gRPCWeb apps, microservices, path/host routing
NLB4TCP, UDP, TLSUltra-low latency, static IP, gaming, IoT
GLB3IP (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.
⚠ Static IP need?

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
⚠ Stateful vs stateless

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.
💡 ACM region gotcha

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.
💡 Public vs Private Subnet

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 end
A typical multi-AZ VPC: public subnets host the ALB and NAT gateways; private subnets hold the app tier; a separate DB subnet runs RDS Multi-AZ.

VPC Connectivity Options

OptionConnectsNotes
VPC PeeringTwo VPCs1:1, non-transitive, no overlapping CIDRs
Transit GatewayMany VPCs + on-premHub-and-spoke, transitive, scales to thousands
VPC Endpoint (Gateway)VPC → S3 / DynamoDBFree, via route table, stays on AWS network
VPC Endpoint (Interface)VPC → most AWS servicesPrivateLink ENI, hourly + data cost
Site-to-Site VPNVPC ↔ on-premOver internet, IPsec encrypted, quick to set up
Direct Connect (DX)VPC ↔ on-premDedicated private link, consistent low latency
PrivateLinkConsumer VPC → provider serviceExpose a service privately without peering
⚠ Peering is not transitive

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.

☁️ VPN + DX

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

SymptomCheck in this order
Cannot SSH/RDP to instanceSecurity 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 outboundNAT Gateway healthy? Route 0.0.0.0/0 → nat? NAT in a public subnet?
Cannot reach RDSDB Security Group allows app SG on 3306/5432? Same VPC / peered? Subnet route?
DNS not resolvingVPC enableDnsSupport & enableDnsHostnames? Resolver at .2? dig output
Peered VPC unreachableRoutes on both sides? Non-overlapping CIDRs? SG/NACL allow peer CIDR?
Intermittent packet lossMTU mismatch (jumbo frames)? Check with ping -M do -s 8972
💡 Use VPC tooling

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

Progress0%
  • 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