1.5.2 OSI & TCP/IP Models

Use layers to understand network communication and troubleshooting

The previous page covered network scope, topology, addressing, and device identity. The OSI and TCP/IP models give you a clean way to organize those pieces into layers, so troubleshooting and security analysis feel less random.

1. Why Networking Models?

Networking models provide a standardized framework for understanding how data moves through networks.

Purpose of Networking Models

  • Interoperability: Devices from different vendors can communicate
  • Troubleshooting: Isolate problems to specific layers
  • Design: Standardize network architecture and protocols
  • Education: Common language for networking concepts

Brief History

  • OSI Model (1984): Developed by ISO as theoretical reference
  • TCP/IP Model (1970s): Developed by DARPA/DoD for ARPANET - practical implementation

2. OSI Model (7 Layers)

The Open Systems Interconnection model divides networking into 7 distinct layers.

Layer 7 - Application
Layer 6 - Presentation
Layer 5 - Session
Layer 4 - Transport
Layer 3 - Network
Layer 2 - Data Link
Layer 1 - Physical
LayerNamePDUKey ProtocolsDevicesCommon Attacks
7ApplicationDataHTTP, FTP, SMTP, DNS, SSHN/APhishing, SQLi, XSS
6PresentationDataSSL/TLS, JPEG, ASCII, MPEGN/ASSL stripping
5SessionDataNetBIOS, RPC, PPTP, SIPN/ASession hijacking
4TransportSegmentTCP, UDPN/ASYN flood, UDP flood
3NetworkPacketIP, ICMP, ARP, OSPFRouter, L3 SwitchIP spoofing, MITM
2Data LinkFrameEthernet, PPP, MACSwitch, Bridge, NICMAC spoofing, ARP poison
1PhysicalBitsCables, Fiber, RadioHub, Repeater, CablesWiretapping, jamming

Layer 7 - Application

Function: User interface to network services (browsers, email clients)

Analogy: The person writing and reading the letter

Layer 6 - Presentation

Function: Data translation, encryption/decryption, compression

Analogy: Translator between different languages

Layer 5 - Session

Function: Establishes, manages, terminates sessions between applications

Analogy: Phone call setup - dialing, talking, hanging up

Layer 4 - Transport

Function: End-to-end delivery, flow control, error recovery

Analogy: Postal tracking system ensuring delivery

Layer 3 - Network

Function: Logical addressing (IP), routing between networks

Analogy: GPS navigation choosing the best route

Layer 2 - Data Link

Function: Physical addressing (MAC), local delivery, error detection

Analogy: Street addresses within a neighborhood

Layer 1 - Physical

Function: Transmits raw bits over physical medium

Analogy: The actual roads and highways

3. OSI Memory Aids

Layer 1 to 7 (Bottom-Up):
"Please Do Not Throw Sausage Pizza Away"
Physical -> Data Link -> Network -> Transport -> Session -> Presentation -> Application
Layer 7 to 1 (Top-Down):
"All People Seem To Need Data Processing"
Application -> Presentation -> Session -> Transport -> Network -> Data Link -> Physical

4. TCP/IP Model (4 Layers)

The TCP/IP model is the practical model used by real internet communication. It groups some OSI layers together, which makes it simpler to map to actual protocols.

Layer 4 - Application (OSI 5,6,7)
Layer 3 - Transport (OSI 4)
Layer 2 - Internet (OSI 3)
Layer 1 - Network Access (OSI 1,2)
TCP/IP LayerNameOSI EquivalentKey Protocols
4Application5, 6, 7HTTP, FTP, SMTP, DNS, SSH, TLS
3Transport4TCP, UDP
2Internet3IP, ICMP, ARP, RARP
1Network Access1, 2Ethernet, WiFi, MAC, PPP

5. OSI vs TCP/IP Comparison

Use OSI when you need a detailed troubleshooting language. Use TCP/IP when you want to match the model to the protocols that are running on real networks.

AspectOSI ModelTCP/IP Model
Layers74
Developed ByISO (1984)DARPA/DoD (1970s)
TypeTheoretical/ReferencePractical/Implementation
UsageTeaching, troubleshootingReal internet traffic
Protocol DependencyProtocol-independentProtocol-dependent
ApproachLayer-by-layer strictFlexible, merged layers

6. Data Flow Walkthrough

Scenario: You type https://www.google.com in your browser. What happens?

Step-by-step Journey

1. Application Layer

  • Browser creates HTTP GET request for "/"
  • HTTPS means TLS handshake will be initiated

2. DNS Resolution

  • Browser checks cache -> OS cache -> Router cache
  • DNS query sent (UDP port 53)
  • Returns IP: 142.250.190.46

3. Transport Layer

  • TCP 3-way handshake: SYN -> SYN-ACK -> ACK
  • Connection to port 443 (HTTPS)
  • Data segmented with sequence numbers

4. Network Layer

  • IP packet created with source/destination IPs
  • Routing table consulted for next hop
  • TTL set to prevent infinite loops

5. Data Link Layer

  • ARP resolves gateway's MAC address
  • Ethernet frame created with MAC addresses

6. Physical Layer

  • Bits transmitted as electrical/optical/radio signals

7. At Destination (Reverse)

  • Each layer removes its header (decapsulation)
  • Response travels back the same way
    ENCAPSULATION (Sending)                DECAPSULATION (Receiving)

    Sending side                              Receiving side

    Application: [DATA]                       [DATA]
    Transport:   [TCP | DATA]                 [TCP | DATA]
    Network:     [IP | TCP | DATA]            [IP | TCP | DATA]
    Data Link:   [ETH | IP | TCP | DATA]      [ETH | IP | TCP | DATA]
    Physical:    bits on the medium           bits received from the medium

7. Encapsulation & Decapsulation

Encapsulation: Each layer adds its header to the data from the layer above.

Decapsulation: Each layer removes its header when receiving.

LayerPDU NameAdded Header
Application/Presentation/SessionDataApplication-specific
TransportSegmentTCP/UDP header (ports, seq#)
NetworkPacketIP header (src/dst IP)
Data LinkFrameEthernet header + trailer (MAC)
PhysicalBitsN/A

8. Useful Commands

Linux / Windows
# Trace route (see Layer 3 hops) traceroute google.com # Linux tracert google.com # Windows # Capture packets (see all layers) sudo tcpdump -i eth0 -n # View what layer 4 connections are active netstat -an ss -tuln # Linux modern
Wireshark Filters
# Filter by protocol (Layer 7) http dns # Filter by port (Layer 4) tcp.port == 443 udp.port == 53 # Filter by IP (Layer 3) ip.addr == 192.168.1.1 # Filter by MAC (Layer 2) eth.addr == aa:bb:cc:dd:ee:ff

9. Seeing Layers in Wireshark

When you capture a packet in Wireshark, you'll see layers displayed:

  • Frame: Layer 1-2 info (timing, size)
  • Ethernet II: Layer 2 (src/dst MAC)
  • Internet Protocol: Layer 3 (src/dst IP, TTL)
  • TCP/UDP: Layer 4 (ports, flags, seq#)
  • HTTP/TLS: Layer 7 (application data)
Practice note: In Wireshark, click on each layer section to see the corresponding bytes highlighted in the hex dump. This helps you understand what each layer contributes to the packet.

10. Security Corner

Most Attacked Layers:
  • Layer 7 (Application): SQLi, XSS, phishing, and other application attacks
  • Layer 4 (Transport): SYN floods, port scanning
  • Layer 3 (Network): IP spoofing, routing attacks
  • Layer 2 (Data Link): ARP poisoning, MAC spoofing

Defense in Depth

Protect every layer. One control is rarely enough on its own:

LayerDefense Examples
7 - ApplicationWAF, input validation, secure coding
4 - TransportTLS encryption, rate limiting
3 - NetworkFirewalls, ACLs, IDS/IPS
2 - Data LinkPort security, 802.1X, VLAN segmentation
1 - PhysicalLocked server rooms, cable protection

11. Knowledge Check Quiz

Q1: How many layers does the OSI model have?
Q2: Which layer is responsible for IP addressing and routing?
Q3: What is the PDU at the Transport layer called?
Q4: Which protocol operates at Layer 4?
Q5: ARP poisoning is an attack at which layer?
Q6: True or False: The TCP/IP model has more layers than OSI.
Q7: Which device operates primarily at Layer 3?
Q8: The Presentation layer handles:
Q9: DNS operates at which OSI layer?
Q10: What process adds headers at each layer when sending?
Q11: SYN flood is an attack targeting which layer?
Q12: Which model is actually used on the Internet?
Q1: 7
Q2: Network
Q3: Segment
Q4: TCP
Q5: Data Link (Layer 2)
Q6: False, TCP/IP has 4 layers and OSI has 7
Q7: Router
Q8: Encryption and data format
Q9: Layer 7 (Application)
Q10: Encapsulation
Q11: Transport (Layer 4)
Q12: TCP/IP