Skip to content
OSI Model & TCP/IP – Ultimate Master Reference

OSI Model & TCP/IP Reference

Mô hình OSI & TCP/IP Reference

A complete guide to the 7 network layers, mapping, and security.

Hướng dẫn đầy đủ về 7 tầng mạng, ánh xạ và bảo mật.

I. OSI Model vs TCP/IP Mapping I. Ánh xạ Mô hình OSI và TCP/IP

OSI is a 7-layer theoretical model. TCP/IP is a 4-layer practical implementation.

OSI là mô hình lý thuyết 7 tầng. TCP/IP là triển khai thực tế 4 tầng.

OSI LayerTầng OSI TCP/IP LayerTầng TCP/IP Key Protocols & FunctionGiao thức & Chức năng
7. Application7. Ứng dụng ApplicationỨng dụng Protocols: HTTP, FTP, SMTP, DNS, SSH.
Function: End-user application services.
Giao thức: HTTP, FTP, SMTP, DNS, SSH.
Chức năng: Dịch vụ ứng dụng người dùng.
6. Presentation6. Trình diễn
5. Session5. Phiên
4. Transport4. Giao vận TransportGiao vận Protocols: TCP, UDP.
Function: End-to-end delivery and reliability.
Giao thức: TCP, UDP.
Chức năng: Giao nhận đầu-cuối & tin cậy.
3. Network3. Mạng InternetMạng Internet Protocols: IPv4, IPv6, ICMP, ARP, IPsec.
Function: Logical addressing and routing.
Giao thức: IPv4, IPv6, ICMP, ARP, IPsec.
Chức năng: Địa chỉ logic & định tuyến.
2. Data Link2. Liên kết Network AccessTruy cập mạng Protocols: Ethernet, Wi-Fi, PPP, ARP.
Function: Physical transmission and local delivery.
Giao thức: Ethernet, Wi-Fi, PPP, ARP.
Chức năng: Truyền dẫn vật lý & nội bộ.
1. Physical1. Vật lý
II. Layer 7: Application II. Tầng 7: Ứng dụng
DATA
💡 Easy Analogy:Ẩn dụ dễ hiểu:
This is the software application you see and interact with. Think of it like apps on your phone (Chrome, Gmail, games). It’s the “face” of the network, but it doesn’t know how data is sent. Đây là ứng dụng phần mềm bạn thấy và tương tác. Hãy nghĩ về nó như các ứng dụng trên điện thoại (Chrome, Gmail, trò chơi). Nó là “bộ mặt” của mạng, nhưng nó không biết dữ liệu được gửi đi như thế nào.
🎯 Core Function:Chức năng chính:
Provides network services directly to end-user applications. Acts as the interface between software and network protocols, enabling applications to access and utilize network resources. Cung cấp các dịch vụ mạng trực tiếp cho ứng dụng người dùng cuối. Đóng vai trò là giao diện giữa phần mềm và giao thức mạng.
📊 Protocol Examples:Giao thức tiêu biểu:

HTTP/HTTPS (Web browsing) • FTP/SFTP (File transfer) • SMTP/IMAP/POP3 (Email) • DNS (Name resolution) • SSH (Secure shell) • SNMP (Network management) • Telnet (Remote access)

🔧 Common Issues:Lỗi thường gặp:
DNS resolution failures, HTTP 404/500 errors, Email delivery problems, Application timeouts, Certificate errors (HTTPS), Authentication failures Lỗi phân giải DNS, mã lỗi HTTP 404/500, lỗi gửi email, hết hạn phiên ứng dụng, lỗi chứng chỉ SSL (HTTPS), lỗi xác thực.
III. Layer 6: Presentation III. Tầng 6: Trình diễn
DATA
💡 Easy Analogy:Ẩn dụ dễ hiểu:
This is the universal translator. Imagine two people speaking different languages. This layer translates the sender’s data (e.g., ASCII) into a common format, then translates it back for the receiver. It also handles encryption (locking messages) and compression (making messages smaller). Đây là người thông dịch toàn cầu. Hãy tưởng tượng hai người nói các ngôn ngữ khác nhau. Tầng này dịch dữ liệu người gửi sang định dạng chung và ngược lại cho người nhận. Nó cũng xử lý mã hóa (khóa tin nhắn) và nén dữ liệu (làm cho tin nhắn nhỏ hơn).
🎯 Core Function:Chức năng chính:
Data translation, encryption, and compression. Ensures different systems can communicate by converting data formats and handling syntax differences. Dịch định dạng dữ liệu, mã hóa và nén. Đảm bảo các hệ thống khác nhau có thể giao tiếp bằng cách chuyển đổi định dạng và xử lý sự khác biệt cú pháp.
🔒 Key Responsibilities:Trách nhiệm chính:
  • Character Encoding:Mã hóa ký tự: ASCII, Unicode, EBCDIC conversion
  • Data Compression:Nén dữ liệu: JPEG, MPEG, GIF compression
  • Encryption/Decryption:Mã hóa/Giải mã: SSL/TLS, AES, RSA
  • Format Conversion:Chuyển đổi định dạng: MIME, XDR
IV. Layer 5: Session IV. Tầng 5: Phiên
DATA
💡 Easy Analogy:Ẩn dụ:
This is the conversation manager. Like starting a phone call. It “dials” to start the session, ensures both parties are “on the line” throughout the call, and “hangs up” when the session ends. Đây là người quản lý hội thoại. Giống như bắt đầu một cuộc gọi: tầng này quay số để bắt đầu, duy trì đường dây và gác máy khi kết thúc.
🎯 Core Function:Chức năng chính:
Establishes, manages, and terminates communication sessions. Handles dialog control and synchronization between applications. Thiết lập, quản lý và kết thúc các phiên liên lạc giữa các ứng dụng. Phụ trách điều khiển hội thoại và đồng bộ hóa.
🔗 Protocols:Giao thức:
NetBIOS • RPC • SOCKS • PPTP • L2TP • Session management APIs
🛡️ Security Threats:Mối đe dọa bảo mật:
Session hijacking, Session fixation, Man-in-the-middle attacks, CSRF (Cross-Site Request Forgery) Cướp quyền điều khiển phiên (Hijacking), Giả mạo phiên, Tấn công xen giữa (MITM), CSRF.
V. Layer 4: Transport V. Tầng 4: Giao vận
SEGMENT / DATAGRAM
💡 Easy Analogy:Ẩn dụ dễ hiểu:
Think of Layer 4 as the delivery person in an apartment building. Layer 3 (IP) already delivered the package to the correct building address. But Layer 4 (Port) reads the “room number” (port number) to deliver the package to the exact apartment (application) waiting for it (e.g., room 443 for web browser, room 25 for email). Hãy nghĩ về Tầng 4 như người giao hàng trong một tòa chung cư. Tầng 3 (IP) đã giao gói hàng đến đúng địa chỉ tòa nhà. Nhưng Tầng 4 (Port) sẽ đọc “số phòng” (số hiệu cổng) để giao gói hàng đến đúng căn hộ (ứng dụng) đang chờ (ví dụ: phòng 443 cho trình duyệt web, phòng 25 cho email).
🎯 Core Function:Chức năng chính:
Provides end-to-end communication. Key functions include: Cung cấp giao tiếp đầu-cuối. Các chức năng chính bao gồm:
  • Error Recovery: Ensures data arrives reliably (e.g., TCP’s acknowledgments).Phục hồi lỗi: Đảm bảo dữ liệu đến đích tin cậy (ví dụ: các xác nhận ACK của TCP).
  • Flow Control: An adaptive mechanism that matches the sender’s sending speed to the receiver’s processing speed.Kiểm soát luồng: Khớp tốc độ bên gửi với khả năng xử lý của bên nhận.
  • Multiplexing: Uses port numbers to direct data segments to the correct application.Ghép kênh: Dùng số hiệu cổng điều phối dữ liệu cho đúng ứng dụng.
CLIENT192.168.1.100
1. SYN →
← 2. SYN-ACK
3. ACK →
SERVER192.168.1.1

TCP vs UDP ComparisonSo sánh TCP và UDP

FeatureĐặc điểm TCP (Transmission Control) UDP (User Datagram)
ConnectionKết nối Connection-oriented (3-way handshake) Hướng kết nối (Handshake 3 bước) Connectionless (no handshake) Không kết nối (Không handshake)
ReliabilityĐộ tin cậy Reliable (ACK, retransmission, ordering) Tin cậy (ACK, gửi lại, thứ tự gói tin) Unreliable (best effort, no guarantees) Không tin cậy (nỗ lực tối đa, không đảm bảo)
SpeedTốc độ Slower (overhead for reliability) Chậm hơn (do overhead kiểm tra tin cậy) Faster (minimal overhead) Nhanh hơn (overhead tối thiểu)
Header SizeKích thước Header 20 – 60 bytes 8 bytes
Use CasesTrường hợp sử dụng Web (HTTP/HTTPS), Email, File transfer Web (HTTP/HTTPS), Email, Truyền tệp Streaming, Gaming, VoIP, DNS Streaming, Trò chơi, VoIP, DNS
VI. Layer 3: Network VI. Tầng 3: Mạng
PACKET
💡 Easy Analogy:Ẩn dụ dễ hiểu:
Think of Layer 3 as a global GPS system. You just enter the “IP address” (home address) of the destination machine. The Router (navigator) at Layer 3 automatically calculates the fastest path, passing through many “intersections” (other routers) to deliver your packet to the correct “city” and “home address” (destination computer). Hãy coi Tầng 3 như một hệ thống GPS toàn cầu. Bạn chỉ cần nhập “địa chỉ IP” (địa chỉ nhà) của máy tính đích. Router (người dẫn đường) tại Tầng 3 sẽ tự động tính toán con đường nhanh nhất, đi qua nhiều “ngã tư” (các router khác) để gửi gói tin của bạn đến đúng “thành phố” và “số nhà” (máy tính đích).
🎯 Core Function:Chức năng chính:
Logical addressing (IP) and routing. Determines optimal path for packets across multiple networks from source to destination. Địa chỉ logic (IP) và định tuyến. Xác định đường đi tối ưu cho các gói tin qua nhiều mạng từ nguồn đến đích.
🌐 IP Addressing:Địa chỉ IP:

IPv4: 32-bit (e.g., 192.168.1.1), ~4.3B addresses, dotted decimal

IPv6: 128-bit (e.g., 2001:db8::1), ~3.4×10³⁸ addresses, hexadecimal

Private Ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16

Special: 127.0.0.1 (loopback), .0 (network), .255 (broadcast)

🔀 Routing Protocols:Giao thức định tuyến:
Static: Manual routes • Dynamic IGP: OSPF, RIP, EIGRP • Dynamic EGP: BGP • Other: ICMP (ping/traceroute), IGMP (multicast), IPsec (VPN).
VII. Layer 2: Data Link VII. Tầng 2: Liên kết dữ liệu
FRAME
💡 Easy Analogy:Ẩn dụ dễ hiểu:
This is the local mail carrier for a specific neighborhood (LAN). He doesn’t know about other cities (other networks). He uses “house numbers” (MAC addresses) to deliver mail (frames) to the exact house on his route. A Switch acts like the local post office for that neighborhood. Đây là người đưa thư địa phương cho một khu phố cụ thể (mạng LAN). Anh ta không biết về các thành phố khác (các mạng khác). Anh ta sử dụng “số nhà” (địa chỉ MAC) để giao thư (các khung – frames) đến chính xác ngôi nhà trong tuyến đường của mình. Một thiết bị Switch đóng vai trò như bưu điện địa phương của khu phố đó.
🎯 Core Function:Chức năng chính:
Node-to-node delivery within the same local network. Handles framing, physical addressing (MAC), error detection, and flow control. Chuyển phát dữ liệu giữa các nút trong cùng một mạng nội bộ. Xử lý đóng khung (framing), địa chỉ vật lý (MAC), phát hiện lỗi và kiểm soát luồng.
🔗 MAC Address vs IP Address:So sánh Địa chỉ MAC và IP:

MAC Address (Layer 2):Địa chỉ MAC (Tầng 2):

  • 48-bit hardware address (e.g., 00:1A:2B:3C:4D:5E)Địa chỉ phần cứng 48-bit (ví dụ: 00:1A:2B:3C:4D:5E)
  • Burned into NIC, unique per deviceĐược gắn cứng vào card mạng, duy nhất cho mỗi thiết bị
  • Local network scope onlyChỉ có giá trị trong phạm vi mạng nội bộ
  • Format: OUI (first 3 bytes) + Device ID (last 3 bytes)Định dạng: OUI (3 byte đầu) + ID thiết bị (3 byte cuối)

IP Address (Layer 3):Địa chỉ IP (Tầng 3):

  • 32/128-bit logical addressĐịa chỉ logic 32/128-bit
  • Assigned via DHCP or static configĐược cấp qua DHCP hoặc cấu hình tĩnh
  • Global routing scopePhạm vi định tuyến toàn cầu
  • Can change based on network locationCó thể thay đổi tùy theo vị trí mạng kết nối
⚙️ Switch vs Router:Switch và Router:

Switch (Layer 2):Switch (Tầng 2): Uses MAC addresses, forwards frames within LAN, creates collision domains.Sử dụng địa chỉ MAC, chuyển tiếp khung trong LAN, tạo ra các miền xung đột (collision domains).

Router (Layer 3):Router (Tầng 3): Uses IP addresses, routes packets between networks, connects LANs/WANs.Sử dụng địa chỉ IP, định tuyến gói tin giữa các mạng, kết nối các mạng LAN/WAN với nhau.

📡 Protocols & Devices: Ethernet (802.3), Wi-Fi (802.11), PPP, ARP, VLAN (802.1Q) • Devices: Switches, Bridges, NICs

VIII. Layer 1: Physical VIII. Tầng 1: Vật lý
BIT
💡 Easy Analogy:Ẩn dụ dễ hiểu:
This is the physical path, cable, or radio waves that data (bits) travel on. It’s the copper in cables, glass in fiber optic cables, or radio signals for WiFi. If the “path” is broken (unplugging a cable), nothing can pass through. Đây là con đường vật lý, dây cáp hoặc sóng vô tuyến mà dữ liệu (các bit) di chuyển trên đó. Đó là lõi đồng trong dây cáp, sợi thủy tinh trong cáp quang hoặc tín hiệu vô tuyến của WiFi. Nếu “con đường” bị hỏng (ví dụ rút cáp), không gì có thể đi qua được.
🎯 Core Function:Chức năng chính:
Physical transmission of raw bit streams. Defines electrical, mechanical, and procedural specifications for activating and maintaining physical links. Truyền dẫn vật lý các luồng bit thô. Định nghĩa các đặc tính kỹ thuật về điện, cơ và quy trình để kích hoạt và duy trì các liên kết vật lý.
🔌 Transmission Media:Môi trường truyền dẫn:
CopperCat5e/6/6a (1/10Gbps), Coaxial
FiberSingle-mode (long distance), Multi-mode, DWDM
Wireless802.11ac/ax (Wi-Fi 5/6), Bluetooth, NFC
Standards10BASE-T, 100BASE-TX, 1000BASE-T, 10GBASE-T
🔧 Physical Devices & Tools:Thiết bị & Công cụ:
Cables, Hubs, Repeaters, Transceivers, NICs • Tools: Cable testers, OTDR, Tone generators.

IX. How Data Encapsulation Works (Sending)

IX. Cơ chế Đóng gói Dữ liệu (Khi gửi đi)

L5-7: Application DATA
L4: Transport (Adds Header) SEGMENT
L3: Network (Adds Header) PACKET
L2: Data Link (Adds Header) FRAME
L1: Physical (Transmits Bits) BITS

X. Key Concepts ReviewX. Tổng ôn kiến thức

ConceptKhái niệm DescriptionMô tả OSI Layer
IP Address Logical, unique address for a device on a network (e.g., 192.168.1.10). Can change. Địa chỉ logic, duy nhất cho một thiết bị trên mạng (vd: 192.168.1.10). Có thể thay đổi. Layer 3
MAC Address Physical, globally unique hardware address burned into the network card (e.g., 0A:2B:C3:4D:5E:6F). Does not change. Địa chỉ vật lý, duy nhất toàn cầu được gắn cứng trên card mạng (vd: 0A:2B:C3:4D:5E:6F). Không thay đổi. Layer 2
Router A device that connects different networks and forwards packets between them based on IP addresses. Thiết bị kết nối các mạng khác nhau và chuyển tiếp gói tin dựa trên địa chỉ IP. Layer 3
Switch A device that connects devices on a *local* network and forwards frames between them based on MAC addresses. Thiết bị kết nối các thiết bị trong mạng *nội bộ* và chuyển tiếp khung (frame) dựa trên địa chỉ MAC. Layer 2
Hub An old “dumb” device that just repeats all traffic to all ports. Creates collisions. Thiết bị cũ “ngu ngơ” chỉ lặp lại mọi traffic ra tất cả các cổng. Dễ gây xung đột (collision). Layer 1
Port A number used at the Transport layer to identify a specific application or service on a device. Một con số ở tầng Giao vận dùng để xác định một ứng dụng hoặc dịch vụ cụ thể trên thiết bị. Layer 4

Quick Comparison: Q&AHỏi & Đáp nhanh

A quick reference table for common comparison questions to help reinforce key concepts from the article.

Bảng tra cứu nhanh cho các câu hỏi so sánh phổ biến để giúp củng cố kiến thức trong bài viết.

QuestionCâu hỏi Quick Answer (Key Difference)Đáp án nhanh (Sự khác biệt chính) Layer
How do TCP and UDP differ?TCP và UDP khác nhau thế nào? TCP: Reliable, connection-oriented (3-way handshake).
UDP: Unreliable, connectionless (send and forget).
TCP: Tin cậy, hướng kết nối (handshake 3 bước).
UDP: Không tin cậy, không kết nối (gửi và quên).
Layer 4
What’s the difference between a MAC and IP address?Sự khác biệt giữa MAC và IP? MAC: Physical, fixed address used within a LAN.
IP: Logical, changeable address used for global routing.
MAC: Địa chỉ vật lý, cố định trong mạng LAN.
IP: Địa chỉ logic, có thể thay đổi dùng để định tuyến toàn cầu.
L2 (MAC) / L3 (IP)
What’s the difference between a Switch and a Router?Sự khác biệt giữa Switch và Router? Switch: Uses MAC addresses to forward frames within one LAN.
Router: Uses IP addresses to route packets between different networks.
Switch: Dùng địa chỉ MAC để chuyển khung trong một LAN.
Router: Dùng địa chỉ IP để định tuyến gói tin giữa các mạng khác nhau.
L2 (Switch) / L3 (Router)
Why does DNS use both TCP and UDP?Tại sao DNS dùng cả TCP và UDP? UDP (Port 53): Standard queries (fast).
TCP (Port 53): Zone transfers or large responses (reliable).
UDP (Cổng 53): Truy vấn tiêu chuẩn (nhanh).
TCP (Cổng 53): Truyền vùng (zone transfer) hoặc phản hồi lớn (tin cậy).
L7 (Protocol) / L4
What is the TCP 3-Way Handshake?Cơ chế TCP 3-Way Handshake là gì? A 3-step process to establish a connection: (1) SYN, (2) SYN-ACK, (3) ACK. Quy trình 3 bước thiết lập kết nối: (1) SYN, (2) SYN-ACK, (3) ACK. Layer 4
Why FTP uses two ports (20 & 21)?Tại sao FTP dùng 2 cổng (20 & 21)? Port 21 (Control): Sends commands and authentication.
Port 20 (Data): Transmits the actual file data.
Cổng 21 (Điều khiển): Gửi lệnh và xác thực.
Cổng 20 (Dữ liệu): Truyền dữ liệu tệp thực tế.
L7 (Protocol) / L4

Common Security Threats by LayerMối đe dọa bảo mật theo tầng

Layer 7: Application
SQL Injection, XSS, DDoS: Targeting logic or flooding servers with fake requests.
Layer 6: Presentation
SSL Stripping, Decryption: MITM attacks forcing users from secure HTTPS down to insecure HTTP.
Layer 5: Session
Session Hijacking: Stealing session cookies or IDs to gain unauthorized access.
Layer 4: Transport
SYN Flood, Port Scanning: Overwhelming connections or scanning for open ports.
Layer 3: Network
IP Spoofing, Ping of Death: Faking source identity to bypass security rules.
Layer 2: Data Link
ARP Poisoning: Intercepting local traffic via MAC identity theft.

🛡️ Defense in Depth

  • Layer 7 Defense: Web Application Firewall (WAF)
  • Layer 4 Defense: Firewalls (blocking unused ports)
  • Layer 3 Defense: Access Control Lists (ACLs) on routers
  • Layer 2 Defense: Port Security on switches

Well-Known Ports (0-1023)Cổng mạng phổ biến (0-1023)

PortProtoDescriptionMô tảStatus
20/21TCPFTP – File Transfer (P20: Data, P21: Control).Insecure
22TCPSSH – Secure Shell access to a server.Secure
23TCPTelnet – Unencrypted CLI access. HIGHLY INSECURE.Insecure
25TCPSMTP – Simple Mail Transfer Protocol.Caution
53UDP/TCPDNS – Domain Name translation.Essential
80TCPHTTP – Standard unencrypted web traffic.Insecure
443TCPHTTPS – Secure web traffic (SSL/TLS encrypted).Secure
3389TCPRDP – Remote Desktop Protocol for Windows.High-target
🛡️ Best PracticesNguyên tắc bảo mật

Principle of Least Privilege: Only open necessary ports.
Avoid Insecure Protocols: Use SSH/SFTP over Telnet/FTP.
Change Defaults: Don’t use standard ports for remote access.

Nguyên tắc đặc quyền tối thiểu: Chỉ mở những cổng thực sự cần thiết.
Giao thức an toàn: Dùng SSH/SFTP thay cho Telnet/FTP.
Thay đổi mặc định: Tránh dùng cổng mặc định cho dịch vụ.

Troubleshooting MatrixMa trận xử lý sự cố OSI

LayerProblemSự cốQuestionCâu hỏiTool
1. PhysCable bad/unplugged“Is it plugged in?”Tester
2. DataMAC conflict, VLAN error“Switch active?”arp -a
3. NetWrong IP, No gateway“Can I ping 8.8.8.8?”ping
4. TransFirewall blocking Port“Reach site on 80 not 443?”telnet
5-7. AppAuth error, DNS fail“Brows Google works?”Browser
🛠️ MethodologyPhương pháp

Bottom-Up: Start at L1 confirmed before moving up.
Top-Down: Start at L7 to check app issues first.

Từ dưới lên (Bottom-Up): Bắt đầu từ Tầng 1 (Lỗi phần cứng).
Từ trên xuống (Top-Down): Bắt đầu từ Tầng 7 (Lỗi phần mềm).

© 2025 DoanhPT Blog – OSI Master Design Fix

Leave a Reply

Your email address will not be published. Required fields are marked *

QR Code

Chủ web
xin được nuôi 🍜

Support Me Touch here ^_^
Contact