OSI Model
OSI(Open System Interconnection)開放式通訊系統互連參考模型,是網路通訊的基礎架構。


七層模型概覽
| OSI Layer | Layer Name | Protocols & Technologies | Full English Name |
|---|---|---|---|
| 7 | Application Layer | HTTP/HTTPS, FTP, SMTP, DNS, Telnet, SNMP, POP3/IMAP | HTTP/HTTPS: Hypertext Transfer Protocol / Secure, FTP: File Transfer Protocol, SMTP: Simple Mail Transfer Protocol, DNS: Domain Name System |
| 6 | Presentation Layer | SSL/TLS, ASCII, EBCDIC, JPEG, GIF, PNG, MPEG, MP3 | SSL/TLS: Secure Sockets Layer / Transport Layer Security, ASCII: American Standard Code for Information Interchange |
| 5 | Session Layer | NetBIOS, PPTP, RPC, SMB | NetBIOS: Network Basic Input/Output System, PPTP: Point-to-Point Tunneling Protocol, RPC: Remote Procedure Call, SMB: Server Message Block |
| 4 | Transport Layer | TCP, UDP, SCTP, DCCP | TCP: Transmission Control Protocol, UDP: User Datagram Protocol, SCTP: Stream Control Transmission Protocol |
| 3 | Network Layer | IP, ICMP, IGMP, OSPF, RIP, BGP | IP: Internet Protocol, ICMP: Internet Control Message Protocol, OSPF: Open Shortest Path First, BGP: Border Gateway Protocol |
| 2 | Data Link Layer | Ethernet (MAC layer), PPP, ARP, HDLC, MPLS, VLAN | PPP: Point-to-Point Protocol, ARP: Address Resolution Protocol, HDLC: High-Level Data Link Control, MPLS: Multiprotocol Label Switching |
| 1 | Physical Layer | Ethernet (physical), USB, Bluetooth, DSL, IEEE 802.11 | USB: Universal Serial Bus, DSL: Digital Subscriber Line, IEEE 802.11: Wireless LAN/Wi-Fi Standards |
Layer 7 - Application Layer
應用層 - 提供網路服務給應用程式,最接近終端使用者。
- 提供為應用軟體而設計的介面,以設定與另一應用軟體之間的通訊
- Protocols: SMTP, HTTP, HTTPS, Telnet, FTP, DNS, DHCP, SNMP
Layer 6 - Presentation Layer
表現層 - 處理資料格式轉換、加密/解密、壓縮。
- 把數據轉換為能與接收者的系統格式相容並適合傳輸的格式
- SSL / TLS
Layer 5 - Session Layer
會議層 - 管理應用程式之間的會話或連線。
- 負責在數據傳輸中設定和維護電腦網路中兩台電腦之間的通訊連接
- Stateful firewall (e.g., AWS Security Groups)

Layer 4 - Transport Layer
傳輸層 - 確保完整的資料傳輸,包含錯誤修正、流量控制和分段。
主要負責電腦整體的資料傳輸及控制。它可以將一個較大的資料切割成多個適合傳輸的資料,替模型頂端的第五、六、七等三個通訊層提供流量管制及錯誤控制。
TCP 協定在傳輸資料內加入驗證碼,當對方收到後,就會依這個驗證碼,回傳對應的確認訊息(ACK),若對方未及時傳回確認訊息,資料就會重新傳遞一次,以確保資料傳輸的完整性。

TCP & UDP Overview

TCP - Transmission Control Protocol
connection is a reliable connection, provided via the segments encapsulated in IP Packets.
TCP Segments

3-way Handshake

Frame Types
- Unicast Frame: Destination MAC is another host. Switch will flood only if MAC Address is not in MAC address table.
- Broadcast Frame: Destination MAC address of FFFF.FFFF.FFFF. Broadcast frames are always flooded.
Layer 3 - Network Layer
網路層 - 管理定址、路由和跨網路資料傳遞。
- End to End - 終端機或使用者端的封包傳送協定
- IP address (IPv4/v6) - cross network addressing
- ARP - Find the MAC address for this IP
- Route - where to forward this packet
- Route Tables - Multiple Routes
- Router - moves packets from SRC to DST
- Devices: Router
Layer 2 → Layer 3
Building a Common L3 Network - a hop occurs when a packet is passed from one network segment to the next.

Datagram / Packet Structure
Layer 4 Protocol: ICMP = 1 / TCP = 6 / UDP = 17

IPv4
Dotted-decimal Notation: 4 x 0-255

Subnet Mask
Allows a Host to determine if IP addresses it needs to communicate with is local or remote. Influences if it needs to use a gateway or can communicate locally.

Route Table & Routes
0.0.0.0/0 is the default route.

Address Resolution Protocol (ARP)
Links a L3 address to a L2 address. The Address Resolution Protocol is a layer 2 protocol used to map MAC addresses to IP addresses.

IP Routing

Layer 3 Problems

Layer 2 - Data Link Layer
資料連結層 - 處理同一區域網路(LAN)內節點之間的資料傳輸。
- Hop to Hop - 指的是 router 傳送封包的協定
- MAC address: 48 bits (e.g., 3e:22:fb:b9:5b:75), 24 bits for manufacturer (OUI)
- Collision Detection (CSMA/CD)
- Unicast (1:1) / Broadcast (1:ALL)
- Devices: Switch

Frame Format
| Field | Description |
|---|---|
| Preamble | 一連串的 1010…10,用來同步 |
| SFD | Start of Frame Delimiter,為 10101011,表示資料的起始 |
| DA | Destination Address,目標的 MAC 位址 |
| SA | Source Address,來源的 MAC 位址 |
| ET | EtherType,IP 封包為 0x0800;ARP 封包為 0x0806 |
| Payload | MAC 封包所要傳送的資料內容(46~1500 bytes) |
| PAD | Padding,補滿至最小長度 |
| FCS | Frame Check Sequence (CRC32),用來確認傳送資料是否有錯誤 |
CSMA/CD
Carrier Sense Multiple Access With Collision Detection(載波偵聽多路訪問/碰撞檢測)
Without Layer 2:

With Layer 2 (CSMA/CD):

Layer 2 using a HUB
Still occurs multiple collisions.

Layer 2 using a Switch
Collision occurs on one port only.

Layer 1 - Physical Layer
實體層 - 定義實體連線和原始資料在媒介上的傳輸。
- Specifications define the transmission and reception of RAW BIT STREAMS between a device and a SHARED physical medium
- Defines voltage levels, timing, rates, distances, modulation and connectors
- No access Control
- No uniquely identified devices
- No device to device communications

Technologies
- Cables, WiFi, Repeaters, Hubs

Physical Medium
- Copper (electrical)
- Fibre (light)
- WiFi (RF, radio frequencies)
HUB

NAT - Network Address Translation
NAT 是設計來解決 IPv4 位址不足的問題,同時也提供一些安全性優勢。
- Static NAT: 1 private to 1 (fixed) public address (AWS IGW)
- Dynamic NAT: 1 private to 1st available Public
- PAT (Port Address Translation): many private to 1 public (AWS NATGW)
Static NAT
In AWS, this is how the Internet Gateway (IGW) functions.

Dynamic NAT
Public IP allocations are temporary allocations from a Public IP Pool.

PAT (Port Address Translation)
AWS NATGW functions - (MANY:1)(PrivateIP:PublicIP) Architecture.

IPv4 Address Space
Total: 4,294,967,296 addresses

Private Addressing (RFC1918)
| Range | Class | Addresses |
|---|---|---|
| 10.0.0.0 - 10.255.255.255 | 1 x Class A | 16,777,216 |
| 172.16.0.0 - 172.31.255.255 | 16 x Class B | 16 x 65,536 |
| 192.168.0.0 - 192.168.255.255 | 256 x Class C | 256 x 256 |
Subnetting


Summary

TCP/IP Model
