The OSI Model & TCP/IP Stack
Understanding the layered architecture of network communication with real-world troubleshooting scenarios
Chapter 2: The OSI Model & TCP/IP Stack
The $440 Million Misunderstanding
On August 8, 2012, Knight Capital Group, one of Americaβs largest market makers, experienced a software deployment disaster that nearly destroyed the company. A technician forgot to copy updated trading software to one of eight servers. When the markets opened, that one misconfigured server began executing trades at an algorithm designed for testingβnot live markets.
In 45 minutes, Knight Capital executed 4 million trades, buying and selling $7 billion worth of stocks they didnβt want. By the time someone noticed the anomaly, the company had lost $440 million.
What does this have to do with network layers? Everything.
The debugging process revealed a critical lesson: when troubleshooting complex systems, you need a systematic approach. Random guessing wastes precious time. Knightβs team initially suspected network issues, then application bugs, then database problemsβjumping between layers without method. The layered network model weβll explore in this chapter provides exactly this systematic approach.
When a network problem occurs, understanding whether itβs a physical cable issue (Layer 1), a switching problem (Layer 2), a routing misconfiguration (Layer 3), or an application bug (Layer 7) focuses your troubleshooting instantly. This chapter teaches you to think in layersβa skill that will make you a better network professional and a more effective security analyst.
Why Layers Matter
Imagine trying to mail a letter to someone in another country. You donβt personally carry the letter to its destination. Instead, you write your message, put it in an envelope with an address, and hand it to a postal service. The postal service handles the logisticsβsorting, transportation, international customs, local delivery. At each stage, different specialists handle different aspects of getting your letter to its destination.
Computer networks work similarly. When you send data across a network, it passes through multiple layers of processing, each handling a specific aspect of communication. This layered approach makes networks manageable: each layer can focus on its job without worrying about the details of other layers.
The Power of Abstraction
A web developer doesnβt need to understand electrical signaling on copper cables, just as a hardware engineer doesnβt need to understand HTTP. Each specialist works at their layer, trusting that other layers will do their jobs.
| Layer Focus | Specialist | Concern |
|---|---|---|
| Application protocols | Developer | βHow do I format this API request?β |
| Transport reliability | Systems engineer | βIs TCP or UDP better here?β |
| Network routing | Network engineer | βWhich path should packets take?β |
| Physical connectivity | Cabling technician | βIs this fiber splice clean?β |
The Two Dominant Models
Two models describe network layers:
- OSI Model (7 layers): A theoretical framework developed by ISO, excellent for discussion and teaching
- TCP/IP Model (4 layers): The practical implementation that powers the internet
Understanding both helps you reason about how data moves through networks and where vulnerabilities can arise.
PRO TIP
In job interviews and professional discussions, people often reference OSI layers: βThis seems like a Layer 2 problemβ or βThatβs handled at Layer 7.β Speaking in these terms demonstrates expertiseβeven though the actual protocols are TCP/IP.
The OSI Reference Model
The Open Systems Interconnection (OSI) model was developed by the International Organization for Standardization (ISO) in the late 1970s and early 1980s. It divides network communication into seven distinct layers, each with specific responsibilities.
Each layer provides services to the layer above it and relies on services from the layer below. This separation of concerns allows different technologies to be mixed and matched: you can change your physical medium from copper to fiber without affecting how your web browser works.
OSI Model The Seven Layers
OSI Model - The Seven Layers
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Layer 7 β Application β HTTP, DNS, SSH, SMTP
β β User-facing network services
ββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββ
Layer 6 β Presentation β SSL/TLS, JPEG, ASCII
β β Data formatting and encryption
ββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββ
Layer 5 β Session β NetBIOS, RPC
β β Session management
ββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββ
Layer 4 β Transport β TCP, UDP, QUIC
β β End-to-end delivery, ports
ββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββ
Layer 3 β Network β IP, ICMP, IPsec
β β Logical addressing, routing
ββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββ
Layer 2 β Data Link β Ethernet, WiFi, ARP
β β Physical addressing, framing
ββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββ
Layer 1 β Physical β Cables, signals, connectors
β β Raw bit transmission
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Layer 1: Physical Layer
The Physical layer deals with the raw transmission of bits over a physical medium. It defines electrical voltages, cable specifications, connector types, and signal timing. When your NIC sends a β1β or β0,β the Physical layer determines what that actually means in terms of electrical current, light pulses, or radio waves.
Responsibilities:
- Bit-by-bit transmission and reception
- Physical medium specifications (cables, connectors)
- Signaling methods (electrical, optical, wireless)
- Encoding schemes (how bits are represented as signals)
- Physical topology
Examples: Ethernet cables (Cat5e, Cat6, Cat6a, Cat8), fiber optic cables, wireless radio frequencies, USB, DSL
Devices: Hubs, repeaters, network cables, modems
At this layer, thereβs no concept of addressing or data organizationβjust raw bits flowing between directly connected devices.
Security Note: Physical layer attacks include cable tapping, signal interception, and jamming. Physical security (controlling who can access network cables and equipment) is the first line of defense. Wireless networks are inherently more vulnerable at this layer since anyone within range can receive signals.
** COMMON MISTAKE**
Overlooking physical problems. Before diving into complex debugging, always verify: Is the cable plugged in? Is the link light on? A surprising number of βnetwork outagesβ are caused by loose cables or failed ports.
Layer 2: Data Link Layer
The Data Link layer provides node-to-node data transfer on a local network segment. It organizes raw bits into structured units called frames, handles physical addressing using MAC addresses, detects (and sometimes corrects) transmission errors, and controls access to the shared physical medium.
This layer is often divided into two sublayers:
- LLC (Logical Link Control): Interfaces with the Network layer, provides flow control and error handling
- MAC (Media Access Control): Controls how devices gain access to the medium and permission to transmit
Responsibilities:
- Framing (organizing bits into meaningful units)
- Physical addressing (MAC addresses)
- Error detection (CRC checksums)
- Media access control (who can transmit when)
- Flow control between adjacent nodes
Examples: Ethernet (IEEE 802.3), WiFi (IEEE 802.11), PPP (Point-to-Point Protocol)
Devices: Switches, bridges, network interface cards
Ethernet Frame Structure
Ethernet Frame Structure:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββ¬ββββββββββ¬ββββββββββ¬βββββββββββ¬βββββββββββββββββββ¬ββββββ
β Preamble β Dest β Source β EtherTypeβ Payload β FCS β
β 8 bytes β MAC β MAC β 2 bytes β 46-1500 bytes β4 bytβ
β β 6 bytes β 6 bytes β β β β
ββββββββββββ΄ββββββββββ΄ββββββββββ΄βββββββββββ΄βββββββββββββββββββ΄ββββββ
Common EtherType Values:
0x0800 = IPv4 0x0806 = ARP 0x86DD = IPv6 0x8100 = VLAN Tag
Security Note: Many Layer 2 attacks exploit the trust inherent in local networks. ARP spoofing, MAC flooding, and VLAN hopping all target this layer. Weβll explore these attacks extensively in Part II, Chapter 2.
Layer 3: Network Layer
The Network layer enables data transfer between devices that may not be directly connectedβthey could be on different networks separated by many routers. This layer provides logical addressing (IP addresses) that identify devices globally, determines the path (routing) data should take through the network, and handles fragmentation when data is too large for a network segment.
While the Data Link layer gets frames from point A to point B on the same local network, the Network layer gets packets from any point to any other point, regardless of how many intermediate networks lie between them.
Responsibilities:
- Logical addressing (IP addresses)
- Routing (path determination)
- Packet forwarding
- Fragmentation and reassembly
- Handling different network technologies
Examples: IP (Internet Protocol), ICMP (Internet Control Message Protocol), IPsec
Devices: Routers, Layer 3 switches
IPv4 Packet Structure (Simplified)
IPv4 Packet Structure (Simplified):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββ¬ββββββββββ¬ββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β Version β IHL β TOS/DSCP β Total Length β
β 4 bits β 4 bits β 8 bits β 16 bits β
βββββββββββ΄ββββββββββ΄ββββββββββββββΌββββββββ¬ββββββββββββββββββββββββ€
β Identification β Flags β Fragment Offset β
β 16 bits β 3 bitsβ 13 bits β
βββββββββββ¬βββββββββββ¬βββββββββββββ΄ββββββββ΄ββββββββββββββββββββββββ€
β TTL β Protocolβ Header Checksum β
β 8 bits β 8 bits β 16 bits β
βββββββββββ΄βββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββ€
β Source IP Address (32 bits) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Destination IP Address (32 bits) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Options (if any) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Data β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Security Note: IP spoofing (forging source IP addresses), ICMP attacks, and routing manipulation occur at this layer. The lack of built-in authentication in IP makes many attacks possible. See Part II, Chapter 3.
Layer 4: Transport Layer
The Transport layer provides end-to-end communication services between applications running on different hosts. While the Network layer handles getting packets to the right computer, the Transport layer ensures they get to the right application on that computer and handles reliability and flow control.
The two primary protocols at this layer are TCP (Transmission Control Protocol), which provides reliable, ordered delivery with error checking and flow control, and UDP (User Datagram Protocol), which provides fast, connectionless delivery without guarantees.
Responsibilities:
- End-to-end message delivery
- Port numbers (identifying applications)
- Segmentation and reassembly
- Flow control (preventing overwhelming receivers)
- Error recovery (TCP)
- Congestion control (TCP)
Examples: TCP, UDP, QUIC, SCTP
Transport Layer Addressing
Transport Layer Addressing:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
IP Address + Port Number = Socket
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Computer Web Server β
β 192.168.1.100 93.184.216.34 β
β β
β βββββββββββββββ βββββββββββββββ β
β β Browser β ββββββββββΊ β Web Server β β
β β Port: 52431 β β Port: 443 β β
β βββββββββββββββ ββββββββββ βββββββββββββββ β
β β
β Socket: 192.168.1.100:52431 Socket: 93.184.216.34:443 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Security Note: TCP session hijacking, SYN floods, and port scanning are Transport layer attacks. The TCP three-way handshake, while elegant, has vulnerabilities that attackers exploit. See Part II, Chapter 4.
Layer 5: Session Layer
The Session layer manages sessionsβongoing conversations between applications. It establishes, maintains, and terminates these connections, handles synchronization and checkpointing (so long transfers can recover from interruption), and manages dialog control (full-duplex, half-duplex).
In practice, the Session layerβs functions are often incorporated into application protocols or the Transport layer. Pure Session layer protocols are rare in modern networking.
Responsibilities:
- Session establishment, maintenance, termination
- Synchronization and checkpointing
- Dialog control
Examples: NetBIOS, RPC (Remote Procedure Call), various application-specific session handling
Layer 6: Presentation Layer
The Presentation layer handles data formatting, ensuring that data from one systemβs application layer can be understood by anotherβs. It deals with translation between different data formats, encryption and decryption, and compression.
Like the Session layer, the Presentation layerβs functions are often handled within applications themselves in modern systems. TLS/SSL encryption, while sometimes conceptually placed here, actually operates between the Transport and Application layers.
Responsibilities:
- Data format translation
- Encryption/decryption
- Compression/decompression
- Character encoding (ASCII, Unicode, etc.)
Examples: SSL/TLS (though debated), JPEG, MPEG, ASCII/EBCDIC conversion, gzip compression
Layer 7: Application Layer
The Application layer is where network-aware applications and services operate. This layer provides the interface between the network and user applications. HTTP for web browsing, SMTP for email, DNS for name resolutionβthese are all Application layer protocols.
Note that the βapplicationβ here doesnβt mean software like your web browser itself. Rather, it refers to the network protocols that applications use. Your browser is software that uses the HTTP protocol (Application layer) to communicate with web servers.
Responsibilities:
- Network services for applications
- Resource sharing
- Remote access
- Network management
Examples: HTTP, HTTPS, FTP, SMTP, DNS, SSH, DHCP, SNMP
Security Note: Application layer attacks include SQL injection, cross-site scripting (XSS), and DNS poisoning. These exploit vulnerabilities in how applications handle data. Part II, Chapter 5 covers many of these attacks.
Remembering the Layers
A common mnemonic for the OSI layers (from bottom to top):
Please Do Not Throw Sausage Pizza Away
- Physical
- Data Link
- Network
- Transport
- Session
- Presentation
- Application
Or from top to bottom: All People Seem To Need Data Processing
Data Encapsulation
When you send data over a network, it doesnβt travel as-is. Each layer adds its own header (and sometimes trailer) information, wrapping the data like nested envelopes. This process is called encapsulation.
Encapsulation Process
Encapsulation Process:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Application Layer:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Transport Layer:
ββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TCP HDR β DATA β
ββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Network Layer:
ββββββββββββ¬βββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
β IP HDR β TCP HDR β DATA β
ββββββββββββ΄βββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Data Link Layer:
ββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββββββββββββββ¬ββββββββ
β ETH HDR β IP HDR β TCP HDR β DATA β FCS β
ββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββββββββββββββββ΄ββββββββ
β
βΌ
Physical Layer:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 101010001101001010101010100010101011010101010101001010101... β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
At the sending host:
- Your application creates data and passes it down
- Each layer adds its header, creating a new Protocol Data Unit (PDU)
- The Physical layer transmits the bits
At the receiving host:
- The Physical layer receives bits
- Each layer strips its header, reads its information, and passes the payload up
- The application receives the original data
Protocol Data Units (PDUs)
Each layerβs PDU has a specific name:
| Layer | PDU Name | Contains |
|---|---|---|
| Application | Data/Message | User data |
| Transport | Segment (TCP) / Datagram (UDP) | Transport header + data |
| Network | Packet | Network header + segment |
| Data Link | Frame | Data link header + packet + trailer |
| Physical | Bits | Binary representation of frame |
TRY IT YOURSELF
Capture packets with Wireshark and watch encapsulation in action:
# Install Wireshark (if not already installed) # Start capture on your interface # Visit a website # Click on a packet and expand each layerYouβll see each layer nested inside the one below itβexactly as the encapsulation diagram shows.
Security Note: Understanding encapsulation is crucial for security. Packet crafting tools like Scapy let you manually build packets layer by layer, allowing security professionals to test how systems handle malformed or unexpected packets.
The TCP/IP Model
While the OSI model is academically comprehensive, the actual internet runs on the TCP/IP model (also called the Internet Protocol Suite). Developed by the U.S. Department of Defense in the 1970s, TCP/IP predates the OSI model and has a more practical, implementation-focused design.
The TCP/IP model consolidates the seven OSI layers into four (or sometimes five) layers:
OSI Model vs TCP/IP Model
OSI Model vs TCP/IP Model:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
OSI Model TCP/IP Model
βββββββββ ββββββββββββ
βββββββββββββββββββββ βββββββββββββββββββββ
β Application β β β
βββββββββββββββββββββ€ β Application β
β Presentation β βββββββββΊ β β
βββββββββββββββββββββ€ β β
β Session β βββββββββββββββββββββ
βββββββββββββββββββββ
βββββββββββββββββββββ βββββββββββββββββββββ
β Transport β βββββββββΊ β Transport β
βββββββββββββββββββββ βββββββββββββββββββββ
βββββββββββββββββββββ βββββββββββββββββββββ
β Network β βββββββββΊ β Internet β
βββββββββββββββββββββ βββββββββββββββββββββ
βββββββββββββββββββββ βββββββββββββββββββββ
β Data Link β β Network Access β
βββββββββββββββββββββ€ βββββββββΊ β (Link Layer) β
β Physical β β β
βββββββββββββββββββββ βββββββββββββββββββββ
TCP/IP Layer Overview
Network Access Layer (Link Layer): Combines OSI Layers 1 and 2. Handles physical connectivity and local network frame delivery. TCP/IP is largely agnostic about what happens hereβit works over Ethernet, WiFi, PPP, or any other link technology.
Internet Layer: Corresponds to OSI Layer 3. IP (Internet Protocol) is the cornerstone, handling logical addressing and routing. ICMP and routing protocols also operate here.
Transport Layer: Corresponds to OSI Layer 4. TCP, UDP, and the newer QUIC provide end-to-end communication. TCP offers reliability; UDP offers speed; QUIC offers both (weβll explore QUIC in Chapter 5).
Application Layer: Combines OSI Layers 5, 6, and 7. All high-level protocols (HTTP, DNS, SSH, etc.) operate here. Session management, data formatting, and encryption are handled by individual protocols rather than separate layers.
Why TCP/IP βWonβ
The TCP/IP model became dominant for several reasons:
- Practical origin: It was developed as a working implementation, not a theoretical framework
- Simple design: Fewer layers mean less complexity
- Flexibility: The Application layer consolidation allows protocols to implement exactly the features they need
- Government adoption: Its use in ARPANET (the internetβs predecessor) gave it an early advantage
- Open specifications: RFCs made the standards freely available
The OSI model remains valuable as a teaching and discussion frameworkβitβs more detailed and helps isolate specific functions. When troubleshooting, people often reference OSI layers: βThis seems like a Layer 2 problemβ is meaningful even though the actual protocols are TCP/IP.
THINK ABOUT IT
Why might a simpler 4-layer model be preferable for implementation, while a more detailed 7-layer model is better for education and discussion? Consider the trade-offs between specificity and practical usability.
Key Protocols by Layer
Hereβs a quick reference mapping common protocols to both models:
| Protocol | OSI Layer(s) | TCP/IP Layer | Function |
|---|---|---|---|
| Ethernet | 1, 2 | Network Access | LAN connectivity |
| WiFi (802.11) | 1, 2 | Network Access | Wireless LAN |
| ARP | 2 | Network Access | IP to MAC resolution |
| IP (v4, v6) | 3 | Internet | Logical addressing, routing |
| ICMP | 3 | Internet | Diagnostics, error messages |
| TCP | 4 | Transport | Reliable connections |
| UDP | 4 | Transport | Fast, connectionless |
| QUIC | 4 | Transport | Encrypted, multiplexed |
| HTTP/HTTPS | 5, 6, 7 | Application | Web communication |
| HTTP/2 | 5, 6, 7 | Application | Multiplexed web |
| HTTP/3 | 5, 6, 7 | Application | QUIC-based web |
| DNS | 7 | Application | Name resolution |
| TLS/SSL | 5, 6 | Application (typically) | Encryption |
| SMTP | 7 | Application | Email transfer |
| SSH | 7 | Application | Secure shell access |
| DHCP | 7 | Application | Dynamic IP assignment |
Practical Troubleshooting with Layers
The Layer-by-Layer Approach
When something doesnβt work, start at Layer 1 and work your way up:
Systematic Troubleshooting Flowchart
Systematic Troubleshooting Flowchart:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Layer 1: Physical
βββ Is the cable connected?
βββ Are the link lights on?
βββ Is the wireless adapter enabled?
βββ Try a different port/cable
β
βΌ Physical OK
Layer 2: Data Link
βββ Is the NIC enabled? (ip link show)
βββ Do you see traffic? (tcpdump)
βββ Is the MAC address correct?
βββ Try different switch port
β
βΌ Data Link OK
Layer 3: Network
βββ Do you have an IP address? (ip addr)
βββ Can you ping your gateway?
βββ Can you ping external IPs (8.8.8.8)?
βββ Check routing table (ip route)
β
βΌ Network OK
Layer 4: Transport
βββ Is the service listening? (ss -tuln)
βββ Is the port reachable? (nc -zv host port)
βββ Are firewalls blocking traffic?
βββ Check connection states
β
βΌ Transport OK
Layer 7: Application
βββ Is DNS working? (dig example.com)
βββ Does HTTP work? (curl http://...)
βββ Check application logs
βββ Test with known-working client
Real-World Troubleshooting Scenarios
Scenario 1: βThe Internet is Downβ
User reports they canβt access websites.
# Step 1: Layer 1 - Physical
$ ip link show
eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> ...
# No carrier = cable problem or switch issue
# After reconnecting cable:
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
# Link is up, move to Layer 3
# Step 2: Layer 3 - Network
$ ip addr show eth0
inet 192.168.1.100/24 ... # Good, we have an IP
$ ping 192.168.1.1 # Gateway
PING 192.168.1.1: 64 bytes from 192.168.1.1 # Gateway works
$ ping 8.8.8.8 # External IP
Request timeout # Problem is beyond gateway
# Check ISP connectivity, modem, etc.
Scenario 2: βI Canβt Reach the Web Serverβ
Application reports connection failures to api.example.com.
# Step 1: Layer 3 - Can we reach the network?
$ ping api.example.com
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 # Reachable
# Step 2: Layer 4 - Is the port open?
$ nc -zv api.example.com 443
Connection to api.example.com 443 port [tcp/https] succeeded!
# Step 3: Layer 7 - Does the application protocol work?
$ curl -v https://api.example.com
* TLS handshake failed
* error:certificate has expired
# Problem found: SSL certificate expired (Layer 6/7 issue)
Scenario 3: βSome Packets Are Being Droppedβ
Intermittent connectivity issues.
# Layer 2: Check for errors
$ ip -s link show eth0
RX: bytes packets errors dropped overrun mcast
123456 1000 15 3 0 0
TX: bytes packets errors dropped carrier collsns
78901 800 0 0 0 0
# 15 RX errors suggests physical/cable issues
# Could be bad cable, EMI interference, failing NIC
# Also check switch interface:
# show interface errors (on switch CLI)
PRO TIP
Document your troubleshooting steps as you go. This creates a log you can reference and shows others (or your future self) what youβve already ruled out. Many organizations require this for change management.
Practical Example: Web Request Journey
Letβs trace what happens when you type βhttps://example.comβ in your browser:
Complete Web Request Journey
Complete Web Request Journey:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Your Computer example.com Server
βββββββββββββββ ββββββββββββββββββ
1. APPLICATION LAYER β
Browser creates HTTP GET request β
"GET / HTTP/1.1" β
β
2. DNS RESOLUTION (Application) β
Browser asks: "What IP is β
example.com?" β
DNS returns: 93.184.216.34 β
β
3. TRANSPORT LAYER β
TCP 3-way handshake: β
βββββββββββββββββββββββββββΊ SYN
βββββββββββββββββββββββββββ SYN-ACK
βββββββββββββββββββββββββββΊ ACK
β
4. TLS HANDSHAKE (Transport/App) β
Key exchange, certificate β
verification, cipher selection β
β
5. HTTP REQUEST (encrypted) β
βββββββββββββββββββββββββββΊ β
β
6. At each router hop: β
NETWORK LAYER β
βββββββββββββββββββββββββββ β
β Read destination IP β β
β Consult routing table β β
β Decrement TTL β β
β Forward to next hop β β
βββββββββββββββββββββββββββ β
β
7. At each hop's link: β
DATA LINK LAYER β
βββββββββββββββββββββββββββ β
β Reframe with new β β
β source/dest MAC for β β
β next segment β β
βββββββββββββββββββββββββββ β
β
8. PHYSICAL LAYER β
βββββββββββββββββββββββββββ β
β Electrical signals, β β
β light pulses, or β β
β radio waves β β
βββββββββββββββββββββββββββ β
βΌ
Server receives
Process reverses
Response sent back
The Journey in Detail
-
Application Layer: Your browser initiates an HTTPS request. First, DNS resolves βexample.comβ to an IP address (e.g., 93.184.216.34).
-
Transport Layer: TCP establishes a connection to port 443 (HTTPS) via the three-way handshake. TLS then performs its handshake for encryption.
-
Network Layer: IP addresses your packetsβsource is your IP, destination is 93.184.216.34. Your local routing table determines the first hop (your default gateway).
-
Data Link Layer: Your NIC creates Ethernet frames. ARP resolves your gatewayβs IP to its MAC address. Frames are addressed MAC-to-MAC.
-
Physical Layer: Your NIC converts frames to electrical signals (if wired) or radio waves (if WiFi).
-
En route: Each router along the path reads the IP header (Layer 3), makes a routing decision, re-encapsulates the packet in a new frame (Layer 2) appropriate for the next hop, and transmits.
-
At the server: The process reverses. The serverβs NIC receives the bits, reassembles the frame, extracts the packet, delivers the segment to the TCP stack, decrypts the TLS data, and hands the HTTP request to the web server application.
-
Response: The web server creates an HTTP response, and the entire process happens in reverse to deliver the webpage to your browser.
TRY IT YOURSELF
Trace a requestβs path across the internet:
# See the routers between you and a destination traceroute example.com # Linux/macOS tracert example.com # Windows # Each line is a router that processed your packet at Layer 3 # Notice how many hops it takes to reach common websites!
Modern Additions: Beyond the Classic Models
Where Does TLS Fit?
TLS/SSL is famously difficult to place in the OSI model. It provides:
- Encryption (Presentation layer function)
- Session management (Session layer function)
- But operates on top of TCP (above Transport layer)
In practice, TLS sits between Layer 4 and Layer 7, creating a secure channel that application protocols use. This is sometimes called βLayer 6.5β or just acknowledged as a cross-layer protocol.
QUIC: Blurring the Lines
QUIC (Quick UDP Internet Connections), used by HTTP/3, challenges traditional layer boundaries:
Traditional Stack QUIC Stack
Traditional Stack: QUIC Stack:
βββββββββββββββββ ββββββββββββ
βββββββββββββββββ βββββββββββββββββ
β HTTP/2 β β HTTP/3 β
βββββββββββββββββ€ βββββββββββββββββ€
β TLS β β QUIC β β Combines transport
βββββββββββββββββ€ β (encryption β + encryption
β TCP β β + transport) β in one layer
βββββββββββββββββ€ βββββββββββββββββ€
β IP β β UDP β
βββββββββββββββββ βββββββββββββββββ€
β IP β
βββββββββββββββββ
QUIC includes:
- Transport functions: Reliability, congestion control, multiplexing
- Security functions: Built-in TLS 1.3 encryption
- Session functions: Connection migration, 0-RTT resumption
This integration improves performance but complicates the clean layer separation. Weβll explore QUIC in depth in Chapter 5.
Service Mesh and Overlay Networks
Modern cloud architectures add additional layers:
Modern Cloud Network Stack
Modern Cloud Network Stack:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Service Mesh (Istio, Linkerd) β
β - Service discovery, load balancing, mTLS β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Container Network (CNI) β
β - Pod networking, network policies β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Overlay Network (VXLAN, Geneve) β
β - Virtual networks over physical infrastructure β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Traditional TCP/IP Stack β
β - IP, TCP/UDP, Ethernet β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
These concepts are explored in Chapters 9 (Cloud Networking) and 10 (Container Networking).
Security Implications by Layer
| Layer | Attack Examples | Security Controls |
|---|---|---|
| 1 - Physical | Cable tapping, jamming, theft | Physical security, locked rooms |
| 2 - Data Link | ARP spoofing, MAC flooding, VLAN hopping | Port security, DAI, 802.1X |
| 3 - Network | IP spoofing, ICMP attacks, route hijacking | Firewalls, ACLs, RPKI |
| 4 - Transport | SYN floods, session hijacking, port scanning | Stateful firewalls, SYN cookies |
| 5 - Session | Session fixation, replay attacks | Secure session management |
| 6 - Presentation | SSL stripping, encoding attacks | HSTS, proper TLS config |
| 7 - Application | SQL injection, XSS, DNS poisoning | WAF, input validation, DNSSEC |
When analyzing security, thinking in layers helps isolate vulnerabilities and design defense in depth.
THINK ABOUT IT
Why is βdefense in depthβ (security controls at multiple layers) important? What happens if you only secure one layer?
Key Takeaways
-
The OSI model provides a seven-layer theoretical framework for understanding network communication
-
The TCP/IP model is the practical four-layer model that powers the internet
-
Encapsulation wraps data in successive headers as it descends through layers
-
Each layer has specific responsibilities and vulnerabilities
-
Protocols at each layer work together to enable end-to-end communication
-
Troubleshooting with layers provides a systematic approach: start at Layer 1, work up
-
Modern protocols like QUIC blur traditional layer boundaries for performance
Self-Assessment
-
Comprehension: A packet reaches a router. The router reads the IP header but ignores the TCP header. Why?
-
Application: You can ping a serverβs IP (8.8.8.8) but cannot access google.com. At which layer is the problem likely occurring?
-
What if: If the Transport layer suddenly stopped working but the Network layer continued functioning, what would users experience?
Review Questions
- What problem does the layered network architecture solve?
- How does the OSI model differ from the TCP/IP model?
- What is encapsulation, and why is it important?
- At which layer does a router primarily operate? What about a switch?
- Why might a security professional need to understand all layers of the network stack?
- Where does TLS fit in the OSI model, and why is this question difficult to answer?
Key RFCs
- RFC 1122 - Requirements for Internet Hosts: Communication Layers
- RFC 1123 - Requirements for Internet Hosts: Application and Support
- RFC 9000 - QUIC: A UDP-Based Multiplexed and Secure Transport