NetGuru by NetSmooth Corporation

74
p.1 NetGuru NetGuru by NetSmooth Corporation 創創 創創 網網網網網網網網網網網網 網網網網網網網網網網網網 第第第 IP Address 第 MAC Address 第第第 PART I TCP/IP 網網網網網網網網 / 網 NetGuru 網網

description

創新 網路通訊實驗教學解決方案. NetGuru by NetSmooth Corporation. PART I TCP/IP 通訊協定深入剖析 / 以 NetGuru 實作. 第二章 IP Address 與 MAC Address 之涵意. Overview. Internet Protocol IEEE 802 與 Ethernet MAC address ARP 運作機制 實驗導引 實驗 2.1 了解 ARP 運作機制 實驗 2.2 Subnetting 實驗 2.3 了解 Subnet 的運作與限制 - PowerPoint PPT Presentation

Transcript of NetGuru by NetSmooth Corporation

Page 1: NetGuru by NetSmooth Corporation

p.1

NetGuruNetGuruby NetSmooth Corporation

創新 創新 網路通訊實驗教學解決方案網路通訊實驗教學解決方案

第二章 IP Address 與 MAC Address 之涵意

PART I TCP/IP 通訊協定深入剖析 / 以 NetGuru 實作

Page 2: NetGuru by NetSmooth Corporation

p.2

Overview

Internet Protocol IEEE 802 與 Ethernet MAC address ARP 運作機制 實驗導引

– 實驗 2.1 了解 ARP 運作機制– 實驗 2.2 Subnetting– 實驗 2.3 了解 Subnet 的運作與限制– 實驗 2.4 Supernetting

Page 3: NetGuru by NetSmooth Corporation

p.3

Internet Protocol

Page 4: NetGuru by NetSmooth Corporation

p.4

概述 IP (Internet Protocol ) 通訊協定定義於 RFC 791 網際網路所使用的網路層通訊協定,負責傳送資料到

指定位址,但並不確認資料是否正確傳達,是一種無連結(Connectionless)的通訊協定

負責做 Packet 路徑選擇 (Routing) , Packet 分割 (Fragmentation) 及重組 (Re-assembly)

Page 5: NetGuru by NetSmooth Corporation

p.5

分級 IP Address

Internet Protocol Version 4 用來辨別裝置或主機唯一的識別碼,適用於不同網路

間定址 由 32 Bits 組成,可有 232 = 4,294,967,296 個位

址 由網路位址及主機位址兩部分組成 依照網路位址和主機位址的分配,分成五種 Class :

進位制與轉換

Page 6: NetGuru by NetSmooth Corporation

p.6

Class First Bits First Byte Values MAX of Hosts in its Subnet

A 0 0~127 224-2=16,777,214

B 1 0 128~191 216-2=65,534

C 1 1 0 192~223 28-2=254

D 1 1 1 224~239 Reversed for multicast

E 1 1 1 1 240~255 Reversed

Page 7: NetGuru by NetSmooth Corporation

p.7

Netmask

目的:對 IP Address 分類,以判定所屬網路號碼 netid

例: 192.168.1.96 / 27

Page 8: NetGuru by NetSmooth Corporation

p.8

名詞介紹 netid

– 每一組 IP 位址的第一個第一個 IP 位址,即為該組 IP 位址的網路號碼(netid)

– 例: 192.168.1.0 / 24 -> 192.168.1.0

broadcast– 每一組 IP 位址的最後一個最後一個 IP ,即為該組 IP 位址的廣播位址 (br

oadcast)– 例: 192.168.1.0 / 24 -> 192.168.1.255

Page 9: NetGuru by NetSmooth Corporation

p.9

不分級 IP Address - CIDR

Classless Inter-Domain Routing 使用 CIDR 即可代表數個 Class C 取代以往需要

使用一個 Class B 之位址浪費,可節省位址 例: 222.77.235.0/21 及 222.77.237.0/21 222.77.235.0 11011110.1001101.11101011.0

222.77.237.0 11011110.1001101.11101101.0

由左至右比對到第 21 個 bit 皆相同,視為同網域

Page 10: NetGuru by NetSmooth Corporation

p.10

Subnetting

將一較大的網路區段切割成幾組較小的網路 使用於 Interior Routing Protocol 例如: 172.16.0.0 / 16

可將一個 B 級網路分成 256 個較小網路 172.16.0.0 / 24 172.16.1.0 / 24 172.16.2.0 / 24 . . . 172.16.255.0 / 24

實驗 2.3 了解 subnet 的運作與限制

實驗 2.2 Subnetting

Page 11: NetGuru by NetSmooth Corporation

p.11

Supernetting

由數個較小的網路區段組合成單一較大網路 使用於 Exterior Routing Protocol 可減少 Routing Table 的 Entry 數 例如: 203.100.64.0 / 20

(203.100.64.0 ~ 203.100.79.255)將 16 個 C 級網路合成一個 203.100.64.0/20 較大網路– netid : 203.100.64.0– range : 203.100.64.0 ~ 203.100.79.255– netmask : 255.255.240.0– broadcast : 203.100.79.255

實驗 2.4 Supernetting

Page 12: NetGuru by NetSmooth Corporation

p.12

Private Address

不需申請,可直接使用 不能讓 Routing Information 流到單位外的網路上 需透過位址轉換 NAT ( Network Address Transl

ation )才能對外連線 可用之 Private Address 範圍:

– 10.0.0.0 ~ 10.255.255.255 ( 10.0.0.0/8 )– 172.16.0.0 ~ 172.31.255.255 ( 172.16.0.0/12 )– 192.168.0.0 ~ 192.168.255.255 ( 192.168.0.0/24 )

Page 13: NetGuru by NetSmooth Corporation

p.13

IP Protocol Header

Page 14: NetGuru by NetSmooth Corporation

p.14

Version(4 bits)– IP Protocol 的版本,目前為 IPv4 ,下一代為 IPv6

Header Len(4 bits)– IP Header 的長度 (5~15) ,預設為 5( 即為 5×4=20Bytes)

[ 註: 5rows , 4Bytes/row]

Type of Service(8 bits) ( 目前作為 Differentiated Services,RFC 3317, RFC 2474)– Precedence (3 bits) :代表封包的重要性,值愈高表愈重要– D (1bit) :設定 0 為一般延遲,設定 1 為低延遲 (Low delay)

– T (1 bit) :設定 0 為一般傳送量,設定 1 為高的傳送量 (Throughput)

– R (1 bit) :設定 0 為一般 Reliability ,設定 1 為高的 Reliability

– C (1 bit) :設定 0 為一般 Cost ,設定為 1 為低 Cost

– Unused (1 bits) :未使用

Page 15: NetGuru by NetSmooth Corporation

p.15

Total Length(16 bits)– 總長度 (IP header + data , 576 ~ 65535 Bytes)– 單位為 Byte

Identification用來識別 Datagram 使用,分割與依序重組

Flags– Bit 0: reserved, must be zero – Bit 1: (DF) 0 = May Fragment, 1 = Don't Fragment. – Bit 2: (MF) 0 = Last Fragment, 1 = More Fragments. Fragme

nt Offset

Page 16: NetGuru by NetSmooth Corporation

p.16

Fragment Offset– 0 ~ 8191 ( = 213 -1)– 分割後封包的位移量– 以 8 bytes 為基本位移單位– 最大總資料量 = 8192 × 8 = 65536 bytes

Time to Live (TTL)– 封包在網路的存活時間– 每經過一個 Router 計數器自動減一,直至 0 為止,便將封包丟

棄 (Discard)

範例說明

Page 17: NetGuru by NetSmooth Corporation

p.17

Protocol – 0 :保留– 1 : ICMP , Internet Control Message– 2 : IGMP , Internet Group Management– 5 : ST , Stream– 6 : TCP , Transmission Control– 8 : EGP , Exterior Gateway Protocol– 9 : IGP , Any private interior gateway– 17 : UDP , User Datagram– 其他請參考 rfc1700 Assigned Numbers

http://www.ietf.org/rfc/rfc1700.txt

範例說明

Page 18: NetGuru by NetSmooth Corporation

p.18

Header Checksum– IP Header 的錯誤檢查碼,將 IP Header 中所有 16-bit 的 word

轉為 1 的補數相加後,再取一的補數,此值即為 Checksum 值 Source IP Address

– 來源 IP 位址 Destination IP Address

– 目的 IP 位址 Options

– 選擇性欄位 Data

– 真正傳送的資料

Page 19: NetGuru by NetSmooth Corporation

p.19

IP Header Checksum 計算範例

4500+0030+9ea4+4000+8006+3ddd+0385+d348+fe06=3b68a

進位的 3 加回 b68a 中, 3+b68a=b68d ,換成二進位為 1011 0110 1000 1101

再取其補數 0100 1001 0111 0010

Page 20: NetGuru by NetSmooth Corporation

p.20

IEEE 802 與 Ethernet

Page 21: NetGuru by NetSmooth Corporation

p.21

IEEE 802 & Ethernet 比較

Page 22: NetGuru by NetSmooth Corporation

p.22

IEEE 802

Dst MAC ( Destination MAC Address)目的的實體位址

Src MAC (Source MAC Address)來源的實體位址

Len (Length)從頭到尾的長度(不含 CRC )

Page 23: NetGuru by NetSmooth Corporation

p.23

802.2 LLC (Logical Link Control)– DSAP (Destination Service Access Point)– SSAP (Source Service Access Point)– Control( 有三種類型 )

802.2 SNAP (Sub-network Access Protocol)– Org Code– Ether Type :與乙太網路的類別同

CRC (Cyclic Redundancy Check)– 錯誤檢查碼– Trailer

Page 24: NetGuru by NetSmooth Corporation

p.24

Ethernet Encapsulation

Page 25: NetGuru by NetSmooth Corporation

p.25

Dst MAC (Destination MAC Address) :目的的實體位置 Src MAC (Source MAC Address) :源的實體位置 Ether Type

– 0x0800(2048) : IPv4

– 0x08DD(2269) : IPv6

– 0x0806(2054) : ARP

– 0x8035(32821) : RARP

Payload :上層網路層的資料封包 CRC (Cyclic Redundancy Check)

– 錯誤檢查碼– Trailer

Page 26: NetGuru by NetSmooth Corporation

p.26

最大傳輸單位 MTU

Maximum Transmission Unit– Data-link layer 中對資料 (payload) 傳輸的最大限制– Network layer 會因 Data-link layer 傳輸最大限制而做切割 (fra

gment)

Page 27: NetGuru by NetSmooth Corporation

p.27

MAC Address

Page 28: NetGuru by NetSmooth Corporation

p.28

MAC Address

每張網路卡出廠時即擁有一個全世界獨一無二的位址 目的在於直接相鄰設備間的定址,適用於同一網路中 由 6 個 bytes 組成,例: 00 : 10 : F3 : 03 :

28 : B0

MAC Layer 之位址,負責和 Physical Layer 溝通

Page 29: NetGuru by NetSmooth Corporation

p.29

MAC Address

Broadcast Address– FF: FF: FF: FF: FF: FF

Multicast Address– 01: 00: 5E: xx: xx: xx

Page 30: NetGuru by NetSmooth Corporation

p.30

Linux 指令: ifconfig

ifconfig - 網路介面控制程式 由指令及其輸出結果可看出系統之設計以及相關設定之作用 範例 :ifconfig eth0

eth0 Link encap:Ethernet Hwaddr 52:54:AB:ED:6F:6152:54:AB:ED:6F:61 inet addr:210.34.6.89210.34.6.89 Bcast:210.34.6.127210.34.6.127 Mask:255.255.255.128255.255.255.128 UP BROADCAST RUNNING MULTICAST MTU:1500 1500 Metric:1 RX packets:46299 errors:0 dropped:0 overruns:0 frame:189 TX packets:3057 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100 Interrupt:5 Base address:0xece0

Page 31: NetGuru by NetSmooth Corporation

p.31

網路卡接收 Packet 的依據 在以下四種情況中,網路卡會擷取封包

– Destination MAC Address 為該網路卡的 MAC Address– 廣播位址( Broadcast Address )– 群播位址( Multicast Address )– 當網路卡在 Promiscuous ModePromiscuous Mode 時

• Ethereal 預設即是 Promiscuous Mode

Page 32: NetGuru by NetSmooth Corporation

p.32

MAC Address 與 IP Address

為何不使用 MAC Address 為定址方法?– 各 MAC Protocol 之 MAC Address  無法統一– MAC Address 無法有任何之階層觀念

設計 IP Address 供定址使用 IP Address 的設計精神:

– 階層式– IPv4 使用 32 Bits 位址、 IPv6 使用 128Bits 位址

Page 33: NetGuru by NetSmooth Corporation

p.33

ARP 的運作機制

Page 34: NetGuru by NetSmooth Corporation

p.34

ARP

AAddress RResolution PProtocol , RFC903 作業系統之網路核心會有兩者對應之表格: ARP Ta

ble 區域網路 IP 連線之步驟:

– 發送者查詢 ARP Table 中是否有接收者之 MAC Address – 若無,進行 ARP 查詢接收者之 MAC Address – 發送者對接收者以查到的 MAC Address 發送資料

Page 35: NetGuru by NetSmooth Corporation

p.35

ARP 的運作機制

例: Host A 欲與 Host B 做 telnet 連線前之 ARP 運作

Page 36: NetGuru by NetSmooth Corporation

p.36

ARP 的運作機制 (1)

Page 37: NetGuru by NetSmooth Corporation

p.37

ARP 的運作機制 (2)

Page 38: NetGuru by NetSmooth Corporation

p.38

ARP 的運作機制 (3)

Page 39: NetGuru by NetSmooth Corporation

p.39

ARP 的運作機制 (4)

Page 40: NetGuru by NetSmooth Corporation

p.40

ARP 的運作機制 (5)

Page 41: NetGuru by NetSmooth Corporation

p.41

Linux 指令: arp

其功能是列出系統的 ARP Table ,以及設定及刪除 ARP Table 中之欄位

實驗 2.1 瞭解 ARP 運作機制

Page 42: NetGuru by NetSmooth Corporation

p.42

範例架構

Page 43: NetGuru by NetSmooth Corporation

p.43

IP & MAC Address

為何有需要兩個 Address ( IP , MAC)? IP Address

– IP Address形成階層式架構階層式架構,方便在路徑的繞徑 (Routing)– 不同網路,方便更改電腦的 IP Address 成為該網路的 Domain

MAC Address– Ethernet 網卡 MAC Address 前三位元組為製造商的號碼,看似

有階層式架構,但購買者分佈各地,實際上卻無法形成階層架構– 適用時機僅在同一網路內

Page 44: NetGuru by NetSmooth Corporation

p.44

額外補充說明

Page 45: NetGuru by NetSmooth Corporation

p.45

無連結導向 (Connectionless-oriented)

在資料傳送前,並不透過事先的連線協調及建立連線才傳送資料;在資料送達對方時亦不送回確認資訊,所以效率較高,但錯誤率相對也較高

廣告郵件是一種無連結傳送,廠商將廣告傳單加上地址交由郵局寄送,但不能確定地址與收件人是否正確,也不能確定收件人是否能正確收到資料。

無連結傳送也可用來建立連結導向的傳送,在上面廣告郵件的例子中,可使用回函的方式來確認消費者是否接收到廣告郵件

Page 46: NetGuru by NetSmooth Corporation

p.46

連結導向 (Connection-oriented)

在發送資料前會建立一個連結,並使用錯誤檢查等方式確保資料能夠正確無誤的傳送,如果發生錯誤會自動嘗試重傳資料

電話是一種連結導向的通訊方式,使用者必須先確定電話號碼,然後撥電話,若是無人接聽則無法建立連結,若是接聽則發話與受話端可藉由交談來確認資料正確傳遞

返回

Page 47: NetGuru by NetSmooth Corporation

p.47

進位制

Page 48: NetGuru by NetSmooth Corporation

p.48

進位制的換算 – 十進位轉二進位

139=1*27 +0*26 +0*25 +0*24 +1*23 +0*22 +1*21 +1*20

Page 49: NetGuru by NetSmooth Corporation

p.49

進位制的換算 – 十進位轉八進位

139=2*82 +1*81 +3*80

Page 50: NetGuru by NetSmooth Corporation

p.50

進位制的換算 – 十進位轉十六進位

1230=4*162 +12*161 +14*160

Page 51: NetGuru by NetSmooth Corporation

p.51

進位制的換算 – 二進位轉八、十六進位 二進位轉八進位

二進位轉十六進位

返回

Page 52: NetGuru by NetSmooth Corporation

p.52

範例說明

Page 53: NetGuru by NetSmooth Corporation

p.53

IP Fragmentation 範例說明 目的:觀察 Unicast 與 Broadcast 封包運作情形及

封包被切割的情形 步驟:

– Step1 :啟動 HostA、 HostB 及 HostC 的 Ethereal– Step2 : 使用 HostA

ping –c1 –s 2000 192.168.0.2– Step3 :觀察是否 ping 的封包被切割成兩個

返回

Page 54: NetGuru by NetSmooth Corporation

p.54

IP Header 中的 Protocol 範例說明 範例一:可使用 ping 範例二:使用 UDP

– Step1:HostA 與 HostB 同時啟動 Ethereal– Step2: HostA 啟動 udpserver 如下

udpserver– Step3: HostB 使用 udpsend 如下

udpsend –d 192.168.0.1 –dport 9090 –m Hello– Step4: 觀察 protocol 欄位是否為 17 (0x11)

返回

Page 55: NetGuru by NetSmooth Corporation

p.55

實驗導引實驗 2.1 了解 ARP 運作機制實驗 2.2 Subnetting

實驗 2.3 了解 subnet 的運作與限制實驗 2.4 Supernetting

Page 56: NetGuru by NetSmooth Corporation

p.56

實驗 2.1 了解 ARP 運作機制

實驗目的 瞭解 arp 指令 瞭解 ARP table 的意義 瞭解 ARP table 資料產生的方式 瞭解 ARP table 資料自動消失的原因

Page 57: NetGuru by NetSmooth Corporation

p.57

實驗架構圖

Page 58: NetGuru by NetSmooth Corporation

p.58

Step 1 :觀察 ARP table

Host A :– 開啟 Ethereal , interface 選 eth0 ,以觀察下列步驟之封包

Host A :– arp –an– ping 192.168.0.2– ping 192.168.0.3– 再次執行 arp –an– 觀察 arp table 的改變– 分析相關封包並與 ARP 運作機制驗證

Page 59: NetGuru by NetSmooth Corporation

p.59

Step 2 :手動寫入 ARP table

Host A :– arp –s 192.168.0.2 xx:xx:xx:xx:xx:xx

xx:xx:xx:xx:xx:xx 表示MAC address( 此 MAC address 可由上一步驟觀察 ARP table得知 )

– 再次執行 arp –an ,觀察 ARP table 的改變 問題與討論

– 手動寫入 ARP table 時,若MAC address打錯會造成什麼結果– 192.168.0.3 的資料為何要消失 ?若不自動消失會產生什麼問題 ?– 手動寫入 ARP table 有什麼好處 ?

返回

Page 60: NetGuru by NetSmooth Corporation

p.60

實驗 2.2 Subnetting

實驗目的 使用 ifconfig 指令設定 IP address 及 netmask 在一個實體網路中切割子網路 瞭解網路遮罩運算方式 瞭解“ Network is unreachable” 訊息的意義

Page 61: NetGuru by NetSmooth Corporation

p.61

實驗架構圖

Page 62: NetGuru by NetSmooth Corporation

p.62

Step 1: 實驗環境設定 Host A :

– ifconfig eth0 192.168.0.1 netmask 255.255.255.192

Host B :– ifconfig eth0 192.168.0.2 netmask 255.255.255.192

Host C :– ifconfig eth0 192.168.0.254 netmask 255.255.255.192

三台 Host 分屬於兩個邏輯網路– Host A 與 B 位於 192.168.0.0/26– Host C 位於 192.168.0.192/26

Page 63: NetGuru by NetSmooth Corporation

p.63

Step 2: 測試 subnets 間的連線 Host A :

– 開啟 Ethereal , interface 選 eth0 ,以觀察下列步驟之封包 由 Host A ping Host B 及 Host C

– arp –an– ping 192.168.0.2– ping 192.168.0.254– 觀察是否有回應– 再次執行於 Host A, B, C 分別執行 arp -an– 分析相關封包

問題與討論– 為何由 Host A ping 192.168.0.254 時,無產生任何 ARP entry亦擷取不到任何 ARP 封包 ?

– 討論“ Network is unreachable” 訊息的意義返回

Page 64: NetGuru by NetSmooth Corporation

p.64

網路遮罩運算流程圖

Page 65: NetGuru by NetSmooth Corporation

p.65

實驗 2.3 瞭解 subnet 的運作

實驗目的 使用 ifconfig 指令設定 IP address 及 netmask 在一個實體網路中切割子網路 了解 netmask 的意義

Page 66: NetGuru by NetSmooth Corporation

p.66

實驗架構圖

Page 67: NetGuru by NetSmooth Corporation

p.67

Step 1: 實驗環境設定 Host A :

– ifconfig eth0 192.168.0.1 netmask 255.255.255.0

Host B :– ifconfig eth0 192.168.0.2 netmask 255.255.255.192

Host C :– ifconfig eth0 192.168.0.254 netmask 255.255.255.192

三台 Host 分屬於三個邏輯網路– Host A 位於 192.168.0.0/24– Host B 位於 192.168.0.0/26– Host C 位於 192.168.0.192/26

Page 68: NetGuru by NetSmooth Corporation

p.68

Step 2: 測試 subnets 間的連線 Host A :

– 開啟 Ethereal , interface 選 eth0 ,以觀察下列步驟之封包 Host A :

– arp -an– ping 192.168.0.2– ping 192.168.0.254– arp –an– 觀察是否有回應– 分析相關封包及探討相關運作細節

Page 69: NetGuru by NetSmooth Corporation

p.69

Host B :– 開啟 Ethereal , interface 選 eth0 ,以觀察下列步驟之封包

Host B :– arp -an– ping 192.168.0.1– ping 192.168.0.254– arp –an– 觀察是否有回應– 分析相關封包及探討相關運作細節

Page 70: NetGuru by NetSmooth Corporation

p.70

Host C :– 開啟 Ethereal , interface 選 eth0 ,以觀察下列步驟之封包

Host C :– arp -an– ping 192.168.0.1– ping 192.168.0.2– arp –an– 觀察是否有回應– 分析相關封包及探討相關運作細節

返回

Page 71: NetGuru by NetSmooth Corporation

p.71

實驗 2.4 Supernetting

實驗目的 使用 ifconfig 指令設定 IP 及 netmask 在一個實體網路中合併子網路

Page 72: NetGuru by NetSmooth Corporation

p.72

實驗架構圖

Page 73: NetGuru by NetSmooth Corporation

p.73

Step 1: 設定實驗環境 Host A :

– ifconfig eth0 192.168.4.1 netmask 255.255.254.0

Host B :– ifconfig eth0 192.168.4.2 netmask 255.255.254.0

Host C :– ifconfig eth0 192.168.5.254 netmask 255.255.254.0

Page 74: NetGuru by NetSmooth Corporation

p.74

Step 2: 對 supernetting進行測試 Host A :

– 開啟 Ethereal , interface 選 eth0 ,以觀察下列步驟之封包 Host A :

– arp -an– ping 192.168.4.2– ping 192.168.5.254– arp -an– 觀察是否有回應,並解釋原因

返回