OSI Model and TCP/IP Protocol Suite

Level: Beginner Module: TCP/IP & Networking 7 min read Lesson 11 of 66

Overview

  • What you’ll learn: The OSI 7-layer reference model, the TCP/IP 4-layer model, encapsulation and decapsulation, and the protocols operating at each layer.
  • Prerequisites: Module 1 – Linux Fundamentals completed
  • Estimated reading time: 20 minutes

Introduction

Every time you browse a website, send an email, or transfer a file, data travels through a complex stack of networking protocols. Understanding how these protocols are organized into layers is fundamental to diagnosing network issues, configuring servers, and building networked applications.

Two models describe this layered architecture: the OSI (Open Systems Interconnection) model with seven layers, and the TCP/IP model with four layers. While the OSI model is primarily a theoretical reference, the TCP/IP model reflects how the Internet actually works. In this lesson, you will learn both models, understand how data is encapsulated as it moves down the stack, and identify key protocols at each layer.

The OSI 7-Layer Model

The OSI model was developed by the International Organization for Standardization (ISO) in 1984 as a universal framework for understanding network communication. It divides the communication process into seven distinct layers, each with a specific responsibility.

Layer 7 – Application Layer

The Application layer is the closest to the end user. It provides network services directly to applications such as web browsers, email clients, and file transfer utilities. Protocols at this layer include:

  • HTTP/HTTPS: Web browsing
  • SMTP/IMAP/POP3: Email
  • FTP/SFTP: File transfer
  • DNS: Domain name resolution
  • SSH: Secure remote access

Layer 6 – Presentation Layer

The Presentation layer handles data translation, encryption, and compression. It ensures that data sent by the Application layer of one system can be read by the Application layer of another system. Examples include SSL/TLS encryption, JPEG compression, and character encoding (ASCII, UTF-8).

Layer 5 – Session Layer

The Session layer establishes, manages, and terminates connections (sessions) between applications. It handles session checkpointing and recovery. Protocols such as NetBIOS and RPC operate at this layer.

Layer 4 – Transport Layer

The Transport layer provides end-to-end communication between processes. It is responsible for segmentation, flow control, and error recovery. The two primary protocols are:

  • TCP (Transmission Control Protocol): Reliable, connection-oriented, guarantees delivery through acknowledgments and retransmission.
  • UDP (User Datagram Protocol): Unreliable, connectionless, faster but with no delivery guarantee. Used for streaming, DNS queries, and gaming.
# View active TCP connections
$ ss -tn
State   Recv-Q  Send-Q  Local Address:Port   Peer Address:Port
ESTAB   0       0       192.168.1.10:22      192.168.1.5:54312
ESTAB   0       0       192.168.1.10:443     203.0.113.50:38721

# View listening UDP sockets
$ ss -uln
State   Recv-Q  Send-Q  Local Address:Port   Peer Address:Port
UNCONN  0       0       0.0.0.0:53           0.0.0.0:*
UNCONN  0       0       0.0.0.0:68           0.0.0.0:*

Layer 3 – Network Layer

The Network layer handles logical addressing and routing. It determines the best path for data to travel from source to destination across multiple networks. The primary protocol is IP (Internet Protocol), which provides IP addresses and routing. Other protocols include ICMP (used by ping) and IGMP (multicast).

# View the IP routing table
$ ip route show
default via 192.168.1.1 dev ens33 proto dhcp metric 100
192.168.1.0/24 dev ens33 proto kernel scope link src 192.168.1.10 metric 100

Layer 2 – Data Link Layer

The Data Link layer provides node-to-node data transfer between two directly connected nodes. It handles MAC (Media Access Control) addressing, frame formatting, and error detection. Ethernet and Wi-Fi (802.11) are Layer 2 technologies.

# View MAC addresses of network interfaces
$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP
    link/ether 00:0c:29:ab:cd:ef brd ff:ff:ff:ff:ff:ff

Layer 1 – Physical Layer

The Physical layer deals with the actual transmission of raw bits over a physical medium — copper cables, fiber optic, or wireless radio waves. It defines electrical signals, connectors, and data rates.

The TCP/IP 4-Layer Model

The TCP/IP model is the practical model used by the Internet. It consolidates the OSI model’s seven layers into four:

  • Application Layer (OSI Layers 5-7): HTTP, FTP, SSH, DNS, SMTP
  • Transport Layer (OSI Layer 4): TCP, UDP
  • Internet Layer (OSI Layer 3): IP, ICMP, ARP
  • Network Access Layer (OSI Layers 1-2): Ethernet, Wi-Fi
# Comparison of OSI and TCP/IP layers:
#
# OSI Model              TCP/IP Model
# ─────────────────      ────────────────
# 7. Application    ─┐
# 6. Presentation    ├─  Application
# 5. Session        ─┘
# 4. Transport      ───  Transport
# 3. Network        ───  Internet
# 2. Data Link      ─┐
# 1. Physical       ─┘   Network Access

Encapsulation and Decapsulation

As data travels down the protocol stack from application to physical medium, each layer adds its own header (and sometimes a trailer) to the data. This process is called encapsulation. When data arrives at the destination, each layer removes its header in reverse order — this is decapsulation.

  • Application data → Transport layer adds TCP/UDP header → Segment
  • Segment → Internet layer adds IP header → Packet
  • Packet → Network Access layer adds Ethernet header + trailer → Frame
  • Frame → Physical layer converts to bits → Bits on the wire
# Capture packets to see encapsulation in action
$ sudo tcpdump -i ens33 -c 3 -nn
tcpdump: verbose output suppressed, use -v for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
10:15:01.123456 IP 192.168.1.10.22 > 192.168.1.5.54312: Flags [P.], seq 1:37, ack 1, win 502, length 36
10:15:01.123789 IP 192.168.1.5.54312 > 192.168.1.10.22: Flags [.], ack 37, win 511, length 0
10:15:01.234567 IP 192.168.1.10.22 > 192.168.1.5.54312: Flags [P.], seq 37:109, ack 1, win 502, length 72

Protocol Data Units at Each Layer

Each layer uses a specific term for its data unit:

  • Application layer: Data / Message
  • Transport layer: Segment (TCP) or Datagram (UDP)
  • Internet layer: Packet
  • Network Access layer: Frame
  • Physical layer: Bits

Common Protocols by Layer

Here is a summary of the most important protocols you will encounter:

# Application Layer Protocols
HTTP   - Port 80   - Web traffic (unencrypted)
HTTPS  - Port 443  - Web traffic (encrypted via TLS)
SSH    - Port 22   - Secure remote shell
FTP    - Port 21   - File transfer
SMTP   - Port 25   - Email sending
DNS    - Port 53   - Name resolution
DHCP   - Port 67/68 - Dynamic IP assignment

# Transport Layer
TCP    - Connection-oriented, reliable
UDP    - Connectionless, best-effort

# Internet Layer
IPv4   - 32-bit addressing
IPv6   - 128-bit addressing
ICMP   - Diagnostics (ping, traceroute)

# Network Access Layer
Ethernet (802.3) - Wired LAN
Wi-Fi (802.11)   - Wireless LAN

Inspecting Layers on Linux

Linux provides powerful tools to inspect each layer of the network stack:

# Layer 2 – View Ethernet/MAC information
$ ip link show ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT
    link/ether 00:0c:29:ab:cd:ef brd ff:ff:ff:ff:ff:ff

# Layer 3 – View IP addresses
$ ip addr show ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
    inet 192.168.1.10/24 brd 192.168.1.255 scope global ens33
    inet6 fe80::20c:29ff:feab:cdef/64 scope link

# Layer 4 – View active connections (TCP and UDP)
$ ss -tunap
Netid  State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
tcp    LISTEN  0       128     0.0.0.0:22           0.0.0.0:*          users:(("sshd",pid=1234,fd=3))
tcp    ESTAB   0       0       192.168.1.10:22      192.168.1.5:54312  users:(("sshd",pid=5678,fd=4))
udp    UNCONN  0       0       0.0.0.0:68           0.0.0.0:*          users:(("dhclient",pid=890,fd=6))

# Layer 7 – Test an application-layer protocol
$ curl -I https://example.com
HTTP/2 200
content-type: text/html; charset=UTF-8
content-length: 1256

Key Takeaways

  • The OSI model provides a 7-layer theoretical framework for understanding network communication; the TCP/IP model is a practical 4-layer model used by the Internet.
  • Each layer has a specific responsibility: Application (user services), Transport (end-to-end delivery), Internet/Network (routing and addressing), Network Access/Data Link + Physical (local delivery and transmission).
  • Encapsulation adds headers at each layer as data moves down the stack; decapsulation removes them at the destination.
  • Protocol Data Units have specific names: Data, Segment/Datagram, Packet, Frame, Bits.
  • Linux tools like ip, ss, tcpdump, and curl allow you to inspect and troubleshoot each layer.

What’s Next

In Lesson 12, you will learn about IP Addressing, Subnetting, and CIDR — the foundation of how devices are identified and organized on networks. You will master IPv4 addressing, subnet calculations, and be introduced to IPv6.

繁體中文

概述

  • 學習目標:OSI 七層參考模型、TCP/IP 四層模型、封裝與解封裝,以及各層運作的協定。
  • 先決條件:模組 1 – Linux 基礎已完成
  • 預計閱讀時間:20 分鐘

簡介

每當您瀏覽網站、發送電子郵件或傳輸檔案時,資料都會經過一組複雜的網路協定堆疊。了解這些協定如何組織成層次,是診斷網路問題、設定伺服器和建構網路應用程式的基礎。

有兩種模型描述這種分層架構:具有七層的 OSI(開放系統互聯)模型,以及具有四層的 TCP/IP 模型。雖然 OSI 模型主要是理論參考,但 TCP/IP 模型反映了網際網路的實際運作方式。在本課程中,您將學習兩種模型,了解資料在堆疊中向下移動時如何封裝,並識別各層的關鍵協定。

OSI 七層模型

OSI 模型由國際標準化組織(ISO)於 1984 年開發,作為理解網路通訊的通用框架。它將通訊過程分為七個不同的層次,每層都有特定的職責。

第 7 層 – 應用層

應用層最接近終端使用者。它直接向網頁瀏覽器、電子郵件用戶端和檔案傳輸工具等應用程式提供網路服務。此層的協定包括:

  • HTTP/HTTPS:網頁瀏覽
  • SMTP/IMAP/POP3:電子郵件
  • FTP/SFTP:檔案傳輸
  • DNS:域名解析
  • SSH:安全遠端存取

第 6 層 – 表示層

表示層處理資料轉換、加密和壓縮。它確保一個系統的應用層發送的資料可以被另一個系統的應用層讀取。範例包括 SSL/TLS 加密、JPEG 壓縮和字元編碼(ASCII、UTF-8)。

第 5 層 – 會話層

會話層建立、管理和終止應用程式之間的連線(會話)。它處理會話檢查點和恢復。NetBIOS 和 RPC 等協定在此層運作。

第 4 層 – 傳輸層

傳輸層提供行程之間的端對端通訊。它負責分段、流量控制和錯誤恢復。兩個主要協定是:

  • TCP(傳輸控制協定):可靠的、連線導向的,透過確認和重傳保證交付。
  • UDP(使用者資料報協定):不可靠的、無連線的,速度較快但不保證交付。用於串流、DNS 查詢和遊戲。

第 3 層 – 網路層

網路層處理邏輯定址和路由。它決定資料從來源到目的地跨多個網路的最佳路徑。主要協定是 IP(網際網路協定),提供 IP 位址和路由。其他協定包括 ICMP(ping 使用)和 IGMP(多播)。

第 2 層 – 資料鏈結層

資料鏈結層在兩個直接連接的節點之間提供節點對節點的資料傳輸。它處理 MAC(媒體存取控制)定址、訊框格式化和錯誤偵測。乙太網路和 Wi-Fi(802.11)是第 2 層技術。

第 1 層 – 實體層

實體層處理通過實體媒介(銅纜、光纖或無線電波)的原始位元傳輸。它定義電氣訊號、連接器和資料速率。

TCP/IP 四層模型

TCP/IP 模型是網際網路使用的實際模型。它將 OSI 模型的七層整合為四層:

  • 應用層(OSI 第 5-7 層):HTTP、FTP、SSH、DNS、SMTP
  • 傳輸層(OSI 第 4 層):TCP、UDP
  • 網際網路層(OSI 第 3 層):IP、ICMP、ARP
  • 網路存取層(OSI 第 1-2 層):乙太網路、Wi-Fi

封裝與解封裝

當資料從應用程式向下移動到實體媒介時,每層都會在資料上添加自己的標頭(有時還有尾部)。這個過程稱為封裝。當資料到達目的地時,每層按相反順序移除其標頭——這就是解封裝

  • 應用程式資料 → 傳輸層添加 TCP/UDP 標頭 → 區段
  • 區段 → 網際網路層添加 IP 標頭 → 封包
  • 封包 → 網路存取層添加乙太網路標頭 + 尾部 → 訊框
  • 訊框 → 實體層轉換為位元 → 線路上的位元

重要觀念

  • OSI 模型提供了一個七層理論框架來理解網路通訊;TCP/IP 模型是網際網路使用的實際四層模型。
  • 每層都有特定職責:應用層(使用者服務)、傳輸層(端對端交付)、網際網路/網路層(路由和定址)、網路存取/資料鏈結 + 實體層(本地交付和傳輸)。
  • 封裝在資料向下移動堆疊時在每層添加標頭;解封裝在目的地移除標頭。
  • 協定資料單元有特定名稱:資料、區段/資料報、封包、訊框、位元。
  • Linux 工具如 ipsstcpdumpcurl 可讓您檢查和排除各層的問題。

下一步

在第 12 課中,您將學習 IP 定址、子網劃分和 CIDR——裝置在網路上識別和組織的基礎。您將掌握 IPv4 定址、子網計算,並認識 IPv6。

日本語

概要

  • 学習内容:OSI 7層参照モデル、TCP/IP 4層モデル、カプセル化とカプセル化解除、各層で動作するプロトコル。
  • 前提条件:モジュール1 – Linux 基礎を完了していること
  • 推定読了時間:20分

はじめに

ウェブサイトを閲覧したり、メールを送信したり、ファイルを転送するたびに、データは複雑なネットワークプロトコルスタックを通過します。これらのプロトコルがどのようにレイヤーに組織されているかを理解することは、ネットワーク問題の診断、サーバーの設定、ネットワークアプリケーションの構築の基礎です。

2つのモデルがこの階層アーキテクチャを記述しています:7層の OSI(開放型システム間相互接続)モデルと、4層の TCP/IP モデルです。OSIモデルは主に理論的な参照ですが、TCP/IPモデルはインターネットの実際の動作を反映しています。このレッスンでは、両方のモデルを学び、データがスタックを下に移動する際のカプセル化の仕組みを理解し、各層の主要プロトコルを特定します。

OSI 7層モデル

OSIモデルは1984年に国際標準化機構(ISO)によってネットワーク通信を理解するための普遍的なフレームワークとして開発されました。通信プロセスを7つの異なるレイヤーに分割し、各レイヤーには特定の責任があります。

第7層 – アプリケーション層

アプリケーション層はエンドユーザーに最も近い層です。ウェブブラウザ、メールクライアント、ファイル転送ユーティリティなどのアプリケーションにネットワークサービスを直接提供します。この層のプロトコルには以下が含まれます:

  • HTTP/HTTPS:ウェブ閲覧
  • SMTP/IMAP/POP3:メール
  • FTP/SFTP:ファイル転送
  • DNS:ドメイン名解決
  • SSH:安全なリモートアクセス

第6層 – プレゼンテーション層

プレゼンテーション層はデータの変換、暗号化、圧縮を処理します。あるシステムのアプリケーション層が送信したデータを別のシステムのアプリケーション層が読み取れるようにします。例としてSSL/TLS暗号化、JPEG圧縮、文字エンコーディング(ASCII、UTF-8)があります。

第5層 – セッション層

セッション層はアプリケーション間の接続(セッション)を確立、管理、終了します。セッションのチェックポイントと回復を処理します。NetBIOSやRPCなどのプロトコルがこの層で動作します。

第4層 – トランスポート層

トランスポート層はプロセス間のエンドツーエンド通信を提供します。セグメンテーション、フロー制御、エラー回復を担当します。2つの主要プロトコルは:

  • TCP(伝送制御プロトコル):信頼性が高く、コネクション指向で、確認応答と再送信により配信を保証。
  • UDP(ユーザーデータグラムプロトコル):信頼性がなく、コネクションレスで、高速だが配信保証なし。ストリーミング、DNSクエリ、ゲームに使用。

第3層 – ネットワーク層

ネットワーク層は論理アドレッシングとルーティングを処理します。複数のネットワークを越えて送信元から宛先へのデータの最適パスを決定します。主要プロトコルは IP(インターネットプロトコル)で、IPアドレスとルーティングを提供します。

第2層 – データリンク層

データリンク層は直接接続された2つのノード間のノード間データ転送を提供します。MAC(メディアアクセス制御)アドレッシング、フレームフォーマット、エラー検出を処理します。イーサネットとWi-Fi(802.11)は第2層の技術です。

第1層 – 物理層

物理層は物理媒体(銅線ケーブル、光ファイバー、無線電波)を介した生のビットの実際の伝送を扱います。電気信号、コネクタ、データレートを定義します。

TCP/IP 4層モデル

TCP/IPモデルはインターネットで使用される実用的なモデルです。OSIモデルの7層を4層に統合します:

  • アプリケーション層(OSI第5-7層):HTTP、FTP、SSH、DNS、SMTP
  • トランスポート層(OSI第4層):TCP、UDP
  • インターネット層(OSI第3層):IP、ICMP、ARP
  • ネットワークアクセス層(OSI第1-2層):イーサネット、Wi-Fi

カプセル化とカプセル化解除

データがアプリケーションから物理媒体へスタックを下に移動する際、各層はデータに独自のヘッダー(場合によってはトレーラー)を追加します。このプロセスをカプセル化と呼びます。データが宛先に到着すると、各層が逆順にヘッダーを除去します——これがカプセル化解除です。

  • アプリケーションデータ → トランスポート層がTCP/UDPヘッダーを追加 → セグメント
  • セグメント → インターネット層がIPヘッダーを追加 → パケット
  • パケット → ネットワークアクセス層がイーサネットヘッダー+トレーラーを追加 → フレーム
  • フレーム → 物理層がビットに変換 → ワイヤー上のビット

重要ポイント

  • OSIモデルはネットワーク通信を理解するための7層の理論的フレームワークを提供し、TCP/IPモデルはインターネットが使用する実用的な4層モデルです。
  • 各層には特定の責任があります:アプリケーション(ユーザーサービス)、トランスポート(エンドツーエンド配信)、インターネット/ネットワーク(ルーティングとアドレッシング)、ネットワークアクセス/データリンク+物理(ローカル配信と伝送)。
  • カプセル化はデータがスタックを下に移動する際に各層でヘッダーを追加し、カプセル化解除は宛先でヘッダーを除去します。
  • プロトコルデータユニットには特定の名前があります:データ、セグメント/データグラム、パケット、フレーム、ビット。
  • ipsstcpdumpcurlなどのLinuxツールで各層を検査しトラブルシューティングできます。

次のステップ

レッスン12では、IPアドレッシング、サブネット分割、CIDRについて学びます——ネットワーク上でデバイスがどのように識別され組織されるかの基礎です。IPv4アドレッシング、サブネット計算をマスターし、IPv6を紹介します。

You Missed