OSI Model

The OSI (Open Systems Interconnection) Model is a conceptual framework that describes how data moves across a network. It breaks communication into seven layers, each with a distinct role—from physical signals up to human-facing applications.

By separating responsibilities, the OSI model makes it easier to design, troubleshoot, and scale networks. Each higher layer builds on the services of the one below, while remaining logically independent.


1. The 7 Layers

Layer Example Protocols Data Unit What It Adds / Handles Notes
L7 Application HTTP, DNS, SMTP, FTP Data User-facing services Browser → HTTP, Mail → SMTP.
L6 Presentation TLS/SSL, JPEG, JSON Record Data format, encryption, compression Often merged into L7.
L5 Session NetBIOS, RPC Session setup & teardown Rarely explicit today.
L4 Transport TCP, UDP Segment Reliable (TCP) vs fast (UDP) TCP = handshake, ports, seq/ack. UDP = stateless.
L3 Network IP, ICMP Packet Logical addressing & routing Routers forward packets. Uses ARP for MAC resolution.
L2 Data Link Ethernet, Wi-Fi, PPP Frame Local delivery Frames = MAC headers + payload + CRC.
L1 Physical Copper, Fiber, Wi-Fi PHY Bits Transmission of raw signals Voltage, RF, or optical light.

🔁 Encapsulation order:
Application Data → Segment → Packet → Frame → Bits


2. Devices at Each Layer

Device Layer What It Does Protocols Authentication
Load Balancer L4–L7 Distributes traffic TCP, HTTP/S, gRPC TLS certs, tokens
Firewall L3–L4 (sometimes L7) Filters packets/flows IP, TCP/UDP, HTTP Rules, TLS interception, VPN
Router L3 Routes IP packets IP, ICMP, BGP, OSPF BGP MD5, IPsec
Switch L2 Forwards frames by MAC Ethernet, VLAN, ARP 802.1X, MAC binding
Hub L1 Repeats bits blindly None

3. Layer Interactions

3.1 Layer 2 – ARP

Maps IP → MAC via broadcast request and unicast reply.

L2 ARP Example
🖼️ ARP – Address Resolution Protocol Sequence

3.2 Layer 2 – VLANs & Trunks

VLANs, trunks, and QinQ are needed to segment traffic, reduce broadcast domains, and efficiently carry multiple logical networks over the same physical infrastructure.

👉 All three work at Layer 2 (Frames) to logically separate traffic over shared physical networks.

3.3 Layer 3 – Routing

Routers strip old frames, keep IP header, attach new MAC header for next hop.

L3 Routing Example
🖼️ L3 Routing – Packet Routing Sequence

3.4 Layer 3 & 5–6 - IPsec

IPsec = encrypted network tunnels.

IPsec Example
🖼️ IPsec – IKE Handshake Sequence

Elliptic Curve Diffie–Hellman Ephemeral provides Perfect Forward Secrecy (PFS) by using a fresh, temporary key pair per session. Even if a server’s long-term private key is later compromised, past sessions remain confidential. Both TLS and IPsec commonly prefer ECDHE for key exchange.

3.5 Layer 5–6 - TLS

TLS = encrypted application sessions.

TLS Example
🖼️ TLS – Secure Handshake Sequence

3.6 Traffic Addressing Modes (Unicast, Broadcast, Multicast, Anycast, Geocast)

How frames/packets are addressed determines who receives them and how the network treats them.

Mode Who Receives OSI Context Typical Uses Key Notes
Unicast Exactly one host L2 (MAC→MAC), L3 (IP→IP) Web browsing, API calls, SSH Most traffic is unicast. Switched at L2, routed at L3.
Broadcast All hosts in the L2 broadcast domain L2 (FF:FF:FF:FF:FF:FF) ARP, DHCP DISCOVER Routers block broadcasts by default.
Multicast Members of a subscribed group L3 (224.0.0.0/4 IPv4; ff00::/8 IPv6) IPTV, conferencing, OSPF Uses IGMP/MLD (hosts), PIM (routers).
Anycast “Nearest” one of many identical endpoints L3 (same IP announced in multiple sites) CDNs, DNS resolvers Routing selects the closest service.
Geocast Hosts in a geographic region L3 concept Vehicular alerts, ITS Conceptual; app-layer in practice.

4. Commands by OSI Layer

Layer Command Purpose Example
L2 arp Show ARP cache arp -a
L3 ping Test ICMP reachability ping 8.8.8.8
L3 traceroute Show hop path mtr 8.8.8.8
L4 ss List sockets ss -ant
L4 tcpdump Capture packets tcpdump -i eth0 port 443
L7 dig DNS lookup dig example.com
L7 curl Test HTTP curl -vk https://site
Cross nmap Port scan nmap -sS 10.1.2.3

5. IP Addressing Basics

5.1 IPv4 Classes & Reservations

👉 Today we use CIDR instead of classful boundaries.

5.2 Convert Binary to Decimal

  1. Take the binary 10000100.
  2. Multiply each bit by its place value:

    • 1×128 + 0×64 + 0×32 + 0×16 + 0×8 + 1×4 + 0×2 + 0×1
  3. Add them up → 132.
Position 1 2 3 4 5 6 7 8 Sum
Decimal 128 64 32 16 8 4 2 1
Bit 1 0 0 0 0 1 0 0
Value 128 0 0 0 0 4 0 0 132

👉 So 10000100 in decimal = 132

5.3 Convert Decimal to to Binary

Take the first octet of 132.12.1.23.

  1. Start from 128 → 132 ≥ 128 → put 1, remainder = 132 − 128 = 4.
  2. Next (64) → 4 < 64 → 0.
  3. Next (32) → 4 < 32 → 0.
  4. Next (16) → 4 < 16 → 0.
  5. Next (8) → 4 < 8 → 0.
  6. Next (4) → 4 ≥ 4 → 1, remainder = 0.
  7. Next (2) → 0 < 2 → 0.
  8. Next (1) → 0 < 1 → 0.

Result row: 1 0 0 0 0 1 0 0

Position 1 2 3 4 5 6 7 8
Decimal 128 64 32 16 8 4 2 1
Representation 1 0 0 0 0 1 0 0

👉 So 132 in binary = 10000100


6. Advanced Networking Topics

6.1 NAT (Network Address Translation)

6.2 DDoS Attacks (3 categories)

  1. Volumetric → Flood bandwidth with massive traffic (e.g., UDP floods, DNS/NTP amplification).
  2. Protocol → Exploit L3/L4 weaknesses, exhausting connection state (e.g., SYN flood, Smurf attack, Ping of Death).
  3. Application → Target app layer (L7) with valid-looking requests that overwhelm servers (e.g., HTTP floods, Slowloris).

6.3 BGP (Border Gateway Protocol)

The internet is a network of networks (Autonomous Systems, or AS):

6.4 Jumbo Frames

6.5 Layer 7 Firewalls

Contents