Felix Lin
•
•
•
•
•
•
•
•
•

Warm Up
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
•
•
•
•
•

思考
問對問題
國際觀
吸收新知 (Ex: TED)
學習模式
Application Layer
Presentation Layer

Session Layer

Application
Layer

Transport Layer

Transport Layer

Network Layer

Internet Layer

Data Link Layer

Network Access Layer

Physical Layer

OSI Model

DOD Model
Application Layer

HTTP, SMTP, FTP, Telnet, …

Presentation Layer

Type of Data, Encrypt/Decrypt

Session Layer

Ports

Transport Layer

Mappin
g

TCP/UDP

Network Layer

IP

Data Link Layer

MAC, LLC, …

Physical Layer

Cable, Cat5e, …

OSI Model
Ethernet

TCP/IP over
Length

8

Preamble

6

6
Destination
MAC
Address

目標 MAC Address
Ex:
00:09:2D:AA:BB:CC,
28-D2-44-16-3C-6F
MAC Address
又稱硬體位址 (H/W Address)
或實體位址 (Physical Address)
6 Byte ID
OUI(3) + NIC Specific(3)
OUI List

2
Source MAC
Address

46-1500

Type

來源 MAC Address
Ex:
00:09:2D:AA:BB:CC,
28-D2-44-16-3C-6F

4

DATA

FCS

Ethernet Type
EtherType
資料類型
Ex: 0x0800 = IPv4
0x8100 = VLAN
Length

8

Preamble

6

6
Destination
MAC
Address

2
Source MAC
Address

46-1500

Type

資料內容,依據Type
不同而影響內容。
長度不定
MAC Address
又稱硬體位址 (H/W Address)
或實體位址 (Physical Address)
6 Byte ID
OUI(3) + NIC Specific(3)
OUI List

4

DATA

FCS

Frame Check Sequence
使用CRC32
(Cyclic redundancy check 32bit)
循環冗餘校驗
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
•
•
•
•
•
•

網際網路協議
將資料切割後封裝為 IP 訊框格式傳送
非連接性(Connectionless)
不可靠性(Unreliable)
主要仍以 IPv4 為主流,IPv6 仍在建置
IPv4 RFC791; IPv6 RFC2460
Range
0.0.0.0/8
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16
100.64.0.0/10

Description

Reference

Current network (only
valid as source
address)

RFC 5735

Private network

RFC 1918

Shared Address Space RFC 6598

127.0.0.0/8

Loopback

RFC 5735

169.254.0.0/16

Link-local
IETF Protocol
Assignments

RFC 3927

224.0.0.0/4

IP multicast

RFC 5771

255.255.255.255

Broadcast

RFC 919

192.0.0.0/24

RFC 5735
8
0

4
8

Version

16
IHL

24
ToS/DSCP

Total Length
Flags

Identification
Time To Live

32

Protocol

Fragment Offset(13)
Header Checksum

12

Source IP Address

16

Destination IP Address

20
…
…

Data
4
Version

8
IHL

16

32

ToS/DSCP

Internet Header
Length 表頭長度
通常為 0x1A
(20 Byte)

Total Length

Type of Service /
DiffServ Code Point
用以區分封包遞送的
優先權

TOS
0

IP版本
通常為 0x4 (IPv4)

IP封包總長度
(不含 Ether Header)

1

2

3

Precedence

4

5

6

7

Type of Service
DSCP

0

1

2

3

4

5

6

7

ECN
16

19

Identification

封包 ID
可做為判斷封包先後
順序與重組的依據

32
Flags

旗標
Bit0: always 0
Bit1: DF(dont Fragment)
Bit2:MF(more Fragment)

Fragment Offset(13)

封包切割位移
一般情況為0
當大封包被切割後將
會被標上序列號碼
8
Time To Live

TTL 存活時間
每經過一個 HOP 則
減一,為0時則丟棄
此封包

16

32
Protocol

協定 (wiki)
0x01 ICMP
0x02 IGMP
0x06 TCP
0x11 UDP
0x59 OSPF
…

Header Checksum

Checksum 16
32
Source IP Address
Destination IP Address

來源 IP 位置
Ex: 192.168.1.9
0xC0 0xA8 0x01 0x09

目標 IP 位置
Ex: 192.168.1.254
0xC0 0xA8 0x01 0xFE
• Unicast
• Broadcast
• Multicast
•
•
•
•
•
•

不須經過路由器或是網關即可到達
子網域遮罩(Subnet Mask)相同
Network ID 相同
Host ID 不同
IP AND Subnet Mask 必相同
IP OR Subnet Mask 必不同
藍老師有交代…
何謂相同 Segment?
A. 192.168.1.9/24 & 192.168.1.254/24
B. 10.20.124.96/8 & 10.30.124.96/8
C. 192.168.1.2/23 & 192.168.2.7/23
D. 192.168.1.129/25 & 192.168.1.200/25
E. 192.168.1.1/30 & 192.168.1.3/30
F. 10.20.65.40/18 & 10.20.64.50/18
G. 10.193.17.23/10 & 10.254.11.33/10
H. 192.168.1.9/24 & 192.168.1.254/25
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
• Address Resolution Protocol
– 位址解析協定
– 由(他人) IP 位址反查硬體位址(MAC Address)
– RFC826

• Reverse Address Resolution Protocol
– 反向位址解析協定
– 由(自己)硬體位址(MAC Address)查詢IP位址
– RFC903
8
0

4
8

16

24

32

Hardware Type
HLEN

Protocol Type
PLEN

Operation

Sender H/W Address (0~3)

12

Sender H/W Address (4~5)

Sender IP Address (0~1)

16

Sender IP Address (2~3)

Target H/W Address (0~1)

20

Target H/W Address (2~5)

24

Target IP Address (0~3)
8
0

4

16

HLEN

Protocol Type
PLEN

20

Operation

Sender H/W Address (0~3)
Sender H/W Address (4~5)
硬體類型

通常為 0x1 (Ethernet)
16

32

Hardware Type

8
12

24

Sender IP Address (2~3)

Hardware Length
硬體位址長度
24 通常為0x6 (MAC)

協定類型
Sender
通常為 0x0800 IP Address (0~1)
(IP)
Target H/W Address (0~1)

Target H/W Address (2~5)
Protocol Length

協定位址長度
通常為0x4 (IP)
Target IP Address (0~3)

運作模式
0x1 ARP Request
0x2 ARP Reply
0x3 RARP Request
0x4 RARP Reply
8
0

4

16

24

32

發送端硬體位址
Hardware Type
(MAC Address)
HLEN

Protocol 位址
發送端 IPType
PLEN

Operation

Sender H/W Address (0~3)

8
12

Sender H/W Address (4~5)

Sender IP Address (0~1)

16

Sender IP Address (2~3)

Target H/W Address (0~1)

20

24

Target H/W Address (2~5)

目標硬體位址
未知為 0x00

Target IP Address (0~3)

目標 IP 位址
•
•
•
•

IP – MAC 對應表
可分為動態與靜態
靜態通常自路由表(Routing Table)取得
封包傳遞過程中會將來源的 MAC address自動
加入ARP Table (動態),作為 cache
• 一段時間過後(default 10min)沒用到的MAC
Address將自動從ARP Table移除
• Command
– Windows: arp
– Linux: arp
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
• Internet Control Message Protocol
• 網路控制訊息協定
• 錯誤偵測與回報機制
– 偵測遠端主機是否存在。
– 建立及維護路由資料。
– 重導資料傳送路徑。
– 資料流量控制。

• Over IP
• RFC792
8
0

16

Type

4

24

32

Code

Checksum

Identifier

Sequence Number

Optional Data

8
ICMP 類別

訊息代碼

Checksum 16
Type
0 - Echo Reply

Code

Description

0

echo響應 (被程序ping使用)

0

目標網路不可達

1

目標主機不可達

2

目標協議不可達

3

目標埠不可達

4 - Source Quench

0

Source quench (congestion control)

8 - Echo Request

0

Echo請求

13 - Timestamp

0

時間戳

14 - Timestamp Reply
30 - Traceroute

0
0

時間戳響應
信息請求

3 - 目的地不可到達
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
•
•
•
•
•
•
•
•

Transmission Control Protocol
傳輸控制協定
連接性(connection)
可靠性(reliable)
三向交握(three-way handshake)
封包可為非連續
Over IP TCP/IP
RFC793
4
0

8

16

32

Source Port

Destination Port

4

Sequence Number

8

Acknowledgment Number

12

16
20
…
…

Data
Offset

Reserve
d

Control Flags (9)

Window Size

Checksum 16

Urgent Point
Options
N C E U A P R S F
S W C R C S S Y I
R E G K H T N N

•
•
•
•
•
•
•

Finish this session – 結束封包
Sync sequence number – 連線建立封包
Reset connection – 連線重置封包
Push function – 此封包須立即傳送
Acknowledgement – 回應封包
Urgent – 緊急封包
ECN(Explicit Congestion Notification, 明確擁塞通知)
Echo – RFC3168
• CWR(Congestion Window Reduced) – RFC3168
• NS(ECN-nonce concealment protection) – RFC3540
Port

Description

20

FTP data transfer

21

FTP control

22

SSH (Secure Shell)

23

Telnet

25

SMTP(Simple Mail Transfer Protocol)

53

DNS (Domain Name System)

67

DHCP (Dynamic Host Configuration Protocol) Server

68

DHCP (Dynamic Host Configuration Protocol) Client

80

HTTP (Hypertext Transfer Protocol)

110

POP3 (Post Office Protocol v3)

3389

Microsoft Terminal Server(RDP)

wiki
Client

Serve
r
Status

Description

CLOSED

連線未開啟

LISTEN

Server端開啟連線,等待 SYN

SYN-SENT

已傳送SYN,等待ACK

SYN-RCVD

已傳送SYN+ACK,等待ACK

ESTABLISHED

已建立連線,進行資料傳輸。

FIN-WAIT-1

已傳送第一個FIN,等待ACK

FIN-WAIT-2

已接收第一個FIN,等待ACK

CLOSE-WAIT

已接收第一個FIN且回傳ACK,等待應用程式關閉。

TIME-WAIT

已接收第二個FIN且回傳ACK,等待2MSL時間到。

LAST-ACK

已傳送第二個ACK,等待ACK。

CLOSING

雙方同時關閉。
Send 3 Packets

1

2

3

4

5

6

7

8

Send 2 Packets

1

2

3

4

5

6

7

8

Receive 2
ACKs

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

Send 2 Packets,
Receive 2 ACKs
Send 3 Packets

Send 2 Packets
Receive 2
ACKs
Send 2 Packets
Receive 2
ACKs
Send 2 Packets,
Receive 1 ACKs

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
•
•
•
•
•
•
•
•

User Datagram Protocol
用戶數據包協定
非連接性(connectionless)
不可靠性(unreliable)
封包必須為連續
通常用於具時效性封包(stream, trap)
易於通過NAT
RFC768
16

32

0

Source Port

Destination Port

4

Length

Checksum 16
Port

Description

53

Domain Name System (DNS)

67

Dynamic Host Configuration Protocol DHCP (Server)

68

Dynamic Host Configuration Protocol DHCP (Client)

69

Trivial File Transfer Protocol (TFTP)

123

Network Time Protocol (NTP)

161

Simple Network Management Protocol (SNMP)

162

Simple Network Management Protocol Trap (SNMP Trap)

514

Syslog

520

Routing Information Protocol (RIP)

wiki
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
• Ping
• Traceroute
• Wireshark/sniffer
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
•
•
•
•
•

DHCP
DNS
HTTP
FTP/TFTP
TELNET/SSH
•
•
•
•
•
•

Dynamic Host Configuration Protocol
動態主機設定協定
管理與分配區域網路內裝置的IP
具有網管之區域網路皆使用DHCP
由BOOTP(Bootstrap Protocol)轉變而來
RFC2131
8
0

OP

16

24

32

HTYPE

HLEN

4

XID

8

HOPS

CIADDR (Client IP Address)

12
16
20

24
…
48

YIADDR (Your IP Address)
GIADDR (Gateway IP Address)
CHADDR (Client Hardware Address)
…

CHADDR (Client Hardware Address)
…
options
Client

Serve
r
•
•
•
•
•
•

Domain Name Server
網域名稱系統
TCP port 80
主要用以紀錄名稱與IP位址的對應
DNS Server 若失效將造成網路無法外連
RFC1034
•
•
•
•

Hypertext Transfer Protocol
超文字傳輸協議
TCP port 80
HTTP/1.1
– OPTIONS, HEAD, GET, POST, PUT, DELETE, TRACE,
CONNECT

• Status Code – 1xx Message, 2xx Success, 3xx
Redirection, 4xx Request Error, 5xx Server Error
–
–
–
–
–

200 OK
400 Bed Request
401 Unauthorized
404 Not Found
502 Bad Gateway
• File Transfer Protocol/Trivial File Transfer
Protocol
• 文件傳輸協議/小型文件傳輸協議
• 提供檔案傳輸、共享
• TCP port 21,20/UDP port 69
• 可靠性、非加密
• RFC 959/2347
•
•
•
•
•
•

虛擬裝端機連線
文字導向互動式操作介面, CLI
Terminal/Console/BBS
TCP Port 23/22
Telnet未加密/SSH有加密
RFC 139, 854, 2941, … / 4250, 4251, …
•
•
•
•
•
•
•
•
•

OSI model
IP
ARP/RARP
ICMP
TCP
UDP
Debug Tools
Protocols
RFCs
• Request For Comments (徵求意見書)
• 由 IETF(Internet Engineering Task Force)
組織發行
• 成為標準前的草案
• 以序列數字編號,如RFC791, RFC1213
• Open and free
•
•
•
•
•
•
•
•

TCP/IP Protocol Suite, 3/e, Behrouz Forouzan, 全華 (*)
TCP/IP 最佳入門實用書, 蕭文龍, 碁峯 (*)
TCP/IP Illustrated, Vol. 1, Vol. 2, Vol.3 W. Richard Stevens
區域網路與高速網路, 黃能富, 維科(*)
最新網路概論, 施銘威研究室, 旗標
Study area - http://www.study-area.org/network/networkfr1.htm
鳥哥 - http://linux.vbird.org/
Wiki http://en.wikipedia.org/wiki/Transmission_Control_Protocol
• RFC - http://www.faqs.org/rfcs/

Computer Network 1 TCP/IP