🌍 Networking

OSI Model

OSI Model

An international standard reference model that divides network communication into 7 layers. Composed of the physical, data link, network, transport, session, presentation, and application layers, it is the basis for network troubleshooting and protocol design.

📖 Detailed Explanation

The OSI (Open Systems Interconnection) model is a reference model for network communication standards published by the International Organization for Standardization (ISO) in 1984. It explains how data is transmitted over a network by dividing it into 7 layers, with each layer responsible for a specific function. Thanks to this model, equipment from different manufacturers can communicate in a standardized way.

Before the OSI model appeared, network equipment and protocols differed from manufacturer to manufacturer, and compatibility problems were serious. Proprietary network architectures such as IBM's SNA and Digital's DECnet proliferated. The OSI model sorted out this confusion and presented a common standard that allows all systems to interoperate.

The core principle of the 7-layer structure is "Encapsulation." Each time data moves from an upper layer to a lower layer, that layer's header is added. For example, for HTTP data at the application layer, a TCP header is added at the transport layer, an IP header at the network layer, and an Ethernet frame at the data link layer. On the receiving side, this process proceeds in reverse order.

In practice, the OSI model is used as the standard framework for network troubleshooting. When you receive a problem such as "The internet isn't working," you can systematically find the cause by checking in order from Layer 1 (cable connection) to Layer 7 (application). It is also used to clearly distinguish the role of each layer when designing security solutions, network equipment, and protocols.

🏗️ OSI 7 Layers in Detail

Layer Name Role Protocols/Equipment
7 Application Provides application services that interact directly with the user HTTP, HTTPS, FTP, SMTP, DNS
6 Presentation Data format conversion, encryption/decryption, compression/decompression SSL/TLS, JPEG, MPEG, ASCII
5 Session Manages establishment, maintenance, and termination of communication sessions NetBIOS, RPC, NFS
4 Transport Reliable end-to-end data transfer, port number management TCP, UDP, port numbers
3 Network Logical addressing (IP), optimal path selection (routing) IP, ICMP, router
2 Data Link Physical addressing (MAC), frame transmission, error detection Ethernet, MAC, switch
1 Physical Bit-level electrical signal transmission, physical connection Cable, hub, repeater

Mnemonic tip: You can memorize them with "All People Seem To Need Data Processing" from top to bottom (7→1), and "Please Do Not Throw Sausage Pizza Away" from bottom to top (1→7).

⚖️ OSI vs TCP/IP Model Comparison

The actual internet operates on the 4-layer TCP/IP model, not the 7-layer OSI. The OSI model is a theoretical reference model, while TCP/IP is a protocol stack that was actually implemented.

OSI 7 Layers TCP/IP 4 Layers Description
7. Application
6. Presentation
5. Session
Application HTTP, FTP, SMTP, DNS, etc.
4. Transport Transport TCP, UDP
3. Network Internet IP, ICMP, ARP
2. Data Link
1. Physical
Network Access Ethernet, Wi-Fi

Why is TCP/IP used more? The OSI model was designed in the late 1970s and completed in 1984, but TCP/IP had already been in actual use on ARPANET since 1983. As TCP/IP became established as the standard first, OSI was left for education and reference purposes.

💻 Code Example

# OSI 계층별 패킷 분석 예제 (scapy 사용)
from scapy.all import *

# 패킷 캡처 및 계층 분석
def analyze_packet(packet):
    print("=" * 50)

    # Layer 2: 데이터 링크 계층 (Ethernet)
    if packet.haslayer(Ether):
        eth = packet[Ether]
        print(f"[L2 데이터 링크] MAC: {eth.src} → {eth.dst}")

    # Layer 3: 네트워크 계층 (IP)
    if packet.haslayer(IP):
        ip = packet[IP]
        print(f"[L3 네트워크] IP: {ip.src} → {ip.dst}, TTL: {ip.ttl}")

    # Layer 4: 전송 계층 (TCP/UDP)
    if packet.haslayer(TCP):
        tcp = packet[TCP]
        print(f"[L4 전송] TCP Port: {tcp.sport} → {tcp.dport}")
        print(f"         Flags: {tcp.flags}, Seq: {tcp.seq}")
    elif packet.haslayer(UDP):
        udp = packet[UDP]
        print(f"[L4 전송] UDP Port: {udp.sport} → {udp.dport}")

    # Layer 7: 응용 계층 (HTTP)
    if packet.haslayer(Raw):
        payload = packet[Raw].load.decode('utf-8', errors='ignore')
        if 'HTTP' in payload or 'GET' in payload or 'POST' in payload:
            print(f"[L7 응용] HTTP 요청 감지")
            print(f"         {payload[:100]}...")

# 패킷 캡처 (10개)
# sniff(filter="tcp port 80", prn=analyze_packet, count=10)

# 수동 패킷 생성으로 OSI 계층 이해하기
packet = Ether()/IP(dst="8.8.8.8")/TCP(dport=80)/Raw(b"GET / HTTP/1.1")
print("\n생성된 패킷 구조:")
packet.show()

# 각 계층 크기 확인
print(f"\nL2 (Ethernet): {len(Ether())} bytes")
print(f"L3 (IP): {len(IP())} bytes")
print(f"L4 (TCP): {len(TCP())} bytes")
print(f"전체 패킷: {len(packet)} bytes")
# OSI 계층별 네트워크 진단 명령어

# ===== Layer 1: 물리 계층 =====
# 네트워크 인터페이스 상태 확인
ip link show
ethtool eth0  # 링크 속도, 듀플렉스 확인

# ===== Layer 2: 데이터 링크 계층 =====
# MAC 주소 확인
ip link show | grep ether
arp -a  # ARP 테이블 (IP↔MAC 매핑)

# ===== Layer 3: 네트워크 계층 =====
# IP 주소 및 라우팅 확인
ip addr show
ip route show
traceroute google.com  # 경로 추적
ping -c 4 google.com   # ICMP 연결 테스트

# ===== Layer 4: 전송 계층 =====
# 열린 포트 및 연결 상태 확인
ss -tuln  # TCP/UDP 리스닝 포트
netstat -an | grep ESTABLISHED
# TCP 3-way handshake 확인
tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) != 0'

# ===== Layer 7: 응용 계층 =====
# HTTP 연결 테스트
curl -I https://google.com  # HTTP 헤더만
curl -v https://google.com  # 상세 연결 정보
# DNS 조회
dig google.com
nslookup google.com

# ===== 통합 진단 =====
# 모든 계층 한번에 점검
mtr google.com  # traceroute + ping 결합

# tcpdump로 패킷 계층별 분석
tcpdump -i eth0 -nn -v 'host google.com' -c 5
# Wireshark 필터로 OSI 계층별 분석

# ===== Layer 2 필터 (데이터 링크) =====
eth.addr == aa:bb:cc:dd:ee:ff    # 특정 MAC 주소
eth.type == 0x0800               # IPv4 패킷만
arp                              # ARP 패킷만

# ===== Layer 3 필터 (네트워크) =====
ip.addr == 192.168.1.1           # 특정 IP
ip.src == 192.168.1.0/24         # 특정 서브넷 출발
ip.ttl < 10                      # TTL 낮은 패킷
icmp                             # ICMP 패킷만

# ===== Layer 4 필터 (전송) =====
tcp.port == 80                   # TCP 80 포트
tcp.flags.syn == 1               # SYN 패킷 (연결 시작)
tcp.flags.rst == 1               # RST 패킷 (연결 리셋)
tcp.analysis.retransmission      # 재전송 패킷
udp.port == 53                   # DNS 쿼리

# ===== Layer 7 필터 (응용) =====
http                             # HTTP 트래픽
http.request.method == "GET"     # GET 요청만
http.response.code == 404        # 404 에러
dns                              # DNS 트래픽
tls.handshake                    # TLS 핸드셰이크

# ===== 복합 필터 예시 =====
# 특정 서버와의 HTTPS 연결 문제 분석
ip.addr == 8.8.8.8 && (tcp.port == 443 || dns)

# TCP 연결 문제 진단
tcp.analysis.flags && !tcp.analysis.window_update

🗣️ Say It Like This in Practice

💬 In Network Incident Response
"Let's first check layer by layer according to OSI. Starting with Layer 1, the cable connection is normal and the link LED is on. Layer 3 ping works, but the Layer 4 TCP connection fails. It looks like the port is blocked on the firewall."
💬 In Security Solution Discussions
"A WAF analyzes HTTP traffic at Layer 7, the application layer, while a general firewall filters by IP and port at Layers 3-4. To block attacks such as SQL Injection, you need a Layer 7 security solution."
💬 In a technical interview
"When you enter a URL in a web browser, the domain is resolved via Layer 7 DNS, a connection is established with the Layer 4 TCP 3-way handshake, and then a Layer 7 HTTP request is sent. In practice, the TCP/IP 4-layer model is used, but thinking in terms of the OSI 7 layers makes troubleshooting more systematic."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Misunderstanding the OSI model as the actual internet standard

The actual internet is based on the TCP/IP model. OSI is a reference model for education and troubleshooting, not an actual implementation standard.

❌
Treating the boundaries between layers as absolute

In reality, the boundaries between layers are often blurry. TLS spans Layers 5-6, and QUIC in HTTP/3 integrates the functions of Layers 4-7.

❌
Looking for network problems in only one layer

If "ping works but the web doesn't," Layer 3 is normal and the problem is in Layers 4-7. Be sure to check multiple layers systematically.

✅
The right approach

When troubleshooting, check in order starting from Layer 1 (Physical). Use the diagnostic tool for each layer appropriately (ping = Layer 3, telnet = Layer 4, curl = Layer 7).

🔗 Related Terms

📚 Learn More