#OSI Model & TCP/IP

Understand the networking foundation that powers the internet and all DevOps infrastructure.


#šŸŽÆ Learning Objectives

After completing this section, you will be able to:

  • Explain each layer of the OSI and TCP/IP models
  • Identify which protocols operate at each layer
  • Troubleshoot network issues by understanding layer interactions
  • Map real-world network traffic to appropriate layers

#OSI Model (7 Layers)

The Open Systems Interconnection (OSI) model is a conceptual framework that standardizes network communication into seven distinct layers.

LayerNameFunctionProtocols/ExamplesDevOps Relevance
7ApplicationUser interface & network servicesHTTP, HTTPS, SSH, DNS, FTPAPI calls, web servers
6PresentationData formatting, encryptionSSL/TLS, JPEG, ASCIICertificate management
5SessionConnection managementNetBIOS, RPC, SMBSession handling
4TransportEnd-to-end deliveryTCP, UDPPort management, load balancing
3NetworkRouting & addressingIP, ICMP, ARPVPC design, subnetting
2Data LinkLocal network deliveryEthernet, MAC, PPPNIC configuration
1PhysicalHardware transmissionCables, Fiber, WirelessData center infrastructure

#Layer Deep Dive

#Layer 7 - Application Layer

bash
1# Examples of Layer 7 protocols in action
2curl https://api.github.com/users/octocat    # HTTPS
3ssh user@server.example.com                   # SSH
4dig google.com                                # DNS

#Layer 4 - Transport Layer

bash
1# View active TCP connections
2netstat -tuln                    # Linux
3Get-NetTCPConnection            # Windows PowerShell
4
5# Test TCP connectivity
6nc -zv hostname 443              # netcat
7Test-NetConnection hostname -Port 443  # PowerShell

#Layer 3 - Network Layer

bash
1# View routing table
2ip route show                    # Linux
3route print                      # Windows
4
5# Trace packet path
6traceroute google.com            # Linux
7tracert google.com               # Windows

#TCP/IP Model (4 Layers)

The TCP/IP model is the practical implementation used on the internet, mapping to the OSI model.

TCP/IP LayerOSI EquivalentKey ProtocolsDescription
ApplicationLayers 5-7HTTP, DNS, SSH, SMTP, FTPUser-facing services
TransportLayer 4TCP, UDPReliable/unreliable delivery
InternetLayer 3IP, ICMP, ARPLogical addressing & routing
Network AccessLayers 1-2Ethernet, Wi-FiPhysical transmission

#Protocol Stack Visualization

diagram
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Application Layer                               │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”ā”‚
│  │  HTTP   │ │   DNS   │ │   SSH   │ │  SMTP   ││
│  ā””ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”˜ā”‚
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│  Transport Layer                                 │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”    │
│  │        TCP        │ │        UDP        │    │
│  │  (Reliable, ordered)│ │(Fast, connectionless)│
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜    │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│  Internet Layer                                  │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”  │
│  │                    IP                      │  │
│  │         (Addressing & Routing)             │  │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│  Network Access Layer                            │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”  │
│  │              Ethernet / Wi-Fi              │  │
│  │         (Physical transmission)            │  │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

#TCP vs UDP

Understanding when to use TCP vs UDP is crucial for DevOps engineers.

FeatureTCPUDP
ConnectionConnection-oriented (3-way handshake)Connectionless
ReliabilityGuaranteed delivery with acknowledgmentsNo guarantee (best-effort)
OrderingPackets delivered in orderNo ordering guarantee
SpeedSlower (overhead for reliability)Faster (minimal overhead)
Header Size20-60 bytes8 bytes
Flow ControlYes (sliding window)No
Error CheckingChecksum + retransmissionChecksum only

#When to Use Each

Use TCP for:

  • Web traffic (HTTP/HTTPS)
  • SSH connections
  • Database connections
  • File transfers (FTP, SFTP)
  • Email (SMTP, IMAP)

Use UDP for:

  • DNS queries (small, quick)
  • Streaming media
  • Gaming
  • VoIP
  • Monitoring/logging (where occasional loss is acceptable)

#TCP Three-Way Handshake

diagram
Client                          Server
  │                               │
  │ ──────── SYN (seq=x) ───────► │
  │                               │
  │ ◄──── SYN-ACK (seq=y, ack=x+1)│
  │                               │
  │ ──────── ACK (ack=y+1) ──────►│
  │                               │
  │       Connection Established   │
  │                               │

#Common Ports Reference

Every DevOps engineer should know these essential ports:

#Well-Known Ports (0-1023)

PortServiceProtocolDescription
20/21FTPTCPFile Transfer Protocol
22SSHTCPSecure Shell
23TelnetTCPUnsecure remote access (avoid!)
25SMTPTCPEmail sending
53DNSTCP/UDPDomain Name System
67/68DHCPUDPDynamic Host Configuration
80HTTPTCPWeb traffic (unencrypted)
110POP3TCPEmail retrieval
143IMAPTCPEmail retrieval
443HTTPSTCPWeb traffic (encrypted)

#Registered Ports (1024-49151)

PortServiceProtocolDescription
3000Dev serversTCPNode.js, React default
3306MySQLTCPMySQL database
5432PostgreSQLTCPPostgreSQL database
5672RabbitMQTCPMessage broker
6379RedisTCPIn-memory cache
8080HTTP AltTCPAlternative HTTP
8443HTTPS AltTCPAlternative HTTPS
9090PrometheusTCPMetrics server
9200ElasticsearchTCPSearch engine
27017MongoDBTCPDocument database

#Practical Troubleshooting Commands

#Check If a Port Is Open

bash
1# Linux - using netcat
2nc -zv hostname 443
3# Output: Connection to hostname 443 port [tcp/https] succeeded!
4
5# Linux - using telnet
6telnet hostname 443
7
8# Windows PowerShell
9Test-NetConnection -ComputerName hostname -Port 443

#View Listening Ports

bash
1# Linux - all listening ports
2ss -tuln
3netstat -tuln
4
5# Filter specific port
6ss -tuln | grep :80
7
8# Windows
9netstat -an | findstr LISTENING
10Get-NetTCPConnection -State Listen

#Packet Capture Basics

bash
1# Capture HTTP traffic
2sudo tcpdump -i eth0 port 80
3
4# Capture with more detail
5sudo tcpdump -i any -nn -v port 443
6
7# Save to file for Wireshark analysis
8sudo tcpdump -i eth0 -w capture.pcap

#IP Addressing Essentials

#IPv4 Address Classes

ClassRangeDefault SubnetUse Case
A1.0.0.0 - 126.255.255.255255.0.0.0 (/8)Large networks
B128.0.0.0 - 191.255.255.255255.255.0.0 (/16)Medium networks
C192.0.0.0 - 223.255.255.255255.255.255.0 (/24)Small networks

#Private IP Ranges (RFC 1918)

10.0.0.0    - 10.255.255.255   (10.0.0.0/8)     - Class A private
172.16.0.0  - 172.31.255.255   (172.16.0.0/12)  - Class B private
192.168.0.0 - 192.168.255.255  (192.168.0.0/16) - Class C private

#CIDR Notation Quick Reference

CIDRSubnet MaskUsable Hosts
/32255.255.255.2551
/30255.255.255.2522
/28255.255.255.24014
/24255.255.255.0254
/16255.255.0.065,534
/8255.0.0.016,777,214

#Key Takeaways

  1. OSI Model provides a conceptual framework; TCP/IP is the practical implementation
  2. TCP is reliable but slower; UDP is fast but unreliable
  3. Memorize common ports - they appear in every DevOps scenario
  4. Master troubleshooting commands: netstat, ss, tcpdump, traceroute
  5. Understanding networking layers helps isolate problems effectively

[!TIP] Mnemonic for OSI layers: "Please Do Not Throw Sausage Pizza Away" (Physical → Application)

[!NOTE] DevOps Application: When configuring firewalls, security groups, or load balancers, you're primarily working at Layers 3-4 (IP addresses and ports) and Layer 7 (application-level routing).