OSI Model

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

OSI Model
Each Layer

七層模型概覽

OSI LayerLayer NameProtocols & TechnologiesFull English Name
7Application LayerHTTP/HTTPS, FTP, SMTP, DNS, Telnet, SNMP, POP3/IMAPHTTP/HTTPS: Hypertext Transfer Protocol / Secure, FTP: File Transfer Protocol, SMTP: Simple Mail Transfer Protocol, DNS: Domain Name System
6Presentation LayerSSL/TLS, ASCII, EBCDIC, JPEG, GIF, PNG, MPEG, MP3SSL/TLS: Secure Sockets Layer / Transport Layer Security, ASCII: American Standard Code for Information Interchange
5Session LayerNetBIOS, PPTP, RPC, SMBNetBIOS: Network Basic Input/Output System, PPTP: Point-to-Point Tunneling Protocol, RPC: Remote Procedure Call, SMB: Server Message Block
4Transport LayerTCP, UDP, SCTP, DCCPTCP: Transmission Control Protocol, UDP: User Datagram Protocol, SCTP: Stream Control Transmission Protocol
3Network LayerIP, ICMP, IGMP, OSPF, RIP, BGPIP: Internet Protocol, ICMP: Internet Control Message Protocol, OSPF: Open Shortest Path First, BGP: Border Gateway Protocol
2Data Link LayerEthernet (MAC layer), PPP, ARP, HDLC, MPLS, VLANPPP: Point-to-Point Protocol, ARP: Address Resolution Protocol, HDLC: High-Level Data Link Control, MPLS: Multiprotocol Label Switching
1Physical LayerEthernet (physical), USB, Bluetooth, DSL, IEEE 802.11USB: 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)
Session & State

Layer 4 - Transport Layer

傳輸層 - 確保完整的資料傳輸,包含錯誤修正、流量控制和分段。

主要負責電腦整體的資料傳輸及控制。它可以將一個較大的資料切割成多個適合傳輸的資料,替模型頂端的第五、六、七等三個通訊層提供流量管制及錯誤控制。

TCP 協定在傳輸資料內加入驗證碼,當對方收到後,就會依這個驗證碼,回傳對應的確認訊息(ACK),若對方未及時傳回確認訊息,資料就會重新傳遞一次,以確保資料傳輸的完整性。

Layer 4

TCP & UDP Overview

TCP & UDP

TCP - Transmission Control Protocol

Is a connection based protocol. A Connection is established between devices using a random port on client and a known port on the server. Once established the connection is bi-directional. The connection is a reliable connection, provided via the segments encapsulated in IP Packets.
TCP

TCP Segments

TCP Segments

3-way Handshake

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

網路層 - 管理定址、路由和跨網路資料傳遞。

網路層定義網路路由及定址功能,讓資料能夠在網路間傳遞。資料在傳輸時,該協定將 IP 位址加入傳輸資料內,並把資料組成封包(Packet)。在網路上傳輸時,封包裡面的 IP 位址會告訴網路設備這筆資料的來源及目的地。
  • 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.

Layer 2 to Layer 3

Datagram / Packet Structure

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

IPv4 and IPv6

IPv4

Dotted-decimal Notation: 4 x 0-255

IPv4

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.

Subnet Mask

Route Table & Routes

0.0.0.0/0 is the default route.

Route Table & Routes

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.

ARP

IP Routing

IP Routing Demo

Layer 3 Problems

Layer 3 Problems

Layer 2 - Data Link Layer

資料連結層 - 處理同一區域網路(LAN)內節點之間的資料傳輸。

將實體層的數位訊號封裝成一組符合邏輯傳輸資料,這組訊號稱為資料訊框(Data Frame)。訊框內包含媒體存取控制(Media Access Control,MAC)位址,而資料在傳輸時,這項位址資訊可讓對方主機辨識資料來源。MAC 位址是一組序號,每個網路設備的 MAC 位址都是獨一無二的。
  • 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
MAC Format

Frame Format

FieldDescription
Preamble一連串的 1010…10,用來同步
SFDStart of Frame Delimiter,為 10101011,表示資料的起始
DADestination Address,目標的 MAC 位址
SASource Address,來源的 MAC 位址
ETEtherType,IP 封包為 0x0800;ARP 封包為 0x0806
PayloadMAC 封包所要傳送的資料內容(46~1500 bytes)
PADPadding,補滿至最小長度
FCSFrame Check Sequence (CRC32),用來確認傳送資料是否有錯誤

CSMA/CD

Carrier Sense Multiple Access With Collision Detection(載波偵聽多路訪問/碰撞檢測)

Without Layer 2:

Without Layer 2

With Layer 2 (CSMA/CD):

With Layer 2

Layer 2 using a HUB

Still occurs multiple collisions.

Layer 2 using HUB

Layer 2 using a Switch

Collision occurs on one port only.

Layer 2 using Switch

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
Layer 1 Example

Technologies

  • Cables, WiFi, Repeaters, Hubs
Layer 1 Techs

Physical Medium

  • Copper (electrical)
  • Fibre (light)
  • WiFi (RF, radio frequencies)

HUB

Layer 1 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.

Static NAT

Dynamic NAT

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

Dynamic NAT

PAT (Port Address Translation)

AWS NATGW functions - (MANY:1)(PrivateIP:PublicIP) Architecture.

PAT

IPv4 Address Space

Total: 4,294,967,296 addresses

IPv4 Address Space

Private Addressing (RFC1918)

RangeClassAddresses
10.0.0.0 - 10.255.255.2551 x Class A16,777,216
172.16.0.0 - 172.31.255.25516 x Class B16 x 65,536
192.168.0.0 - 192.168.255.255256 x Class C256 x 256

Subnetting

Subnetting Overview
Subnetting Calculate

Summary

Model Summary

TCP/IP Model

TCP/IP Model