Address Resolution Protocol (ARP) 位址解析協定

前言

我們利用 IP Address 把資訊送到目的地的網絡,最終也要找出該 Host 的 Media Access Control Address (MAC address) 才能準確無誤地到達。在 Ethernet 的環境下,要用 IP Address 來找出 MAC Address,用的就是 Address Resolution Protocol (ARP),這件事簡單直接,一點也不複雜。

查詢與回覆

其實 ARP 簡單而沒有什麼奧秘,當一個 host 要找另一個 host 時,它會用 broadcast 發出一個 ARP Query (查詢) ,這 ARP Query 包含想要查詢的 IP。由於是 broadcast,網段中所有 host 都會收到。

arp

只有擁有這個 IP 的 host 收到查詢後會回覆,回覆中包含它自己的 MAC Address。查詢的一方會把這個 MAC Address 記錄在 ARP Table 之中。

arp

做一個超簡單的小實驗:

arp

IP 設定如下:

hostname R1
 !
 interface Ethernet0/0
  ip address 192.168.1.1 255.255.255.0
hostname R2
 !
 interface Ethernet0/0
  ip address 192.168.1.129 255.255.255.0

show arp 指令可以查看 Router 的 ARP Table,R1 現時就只有自己 Interface 的紀錄。

R1#show arp
 Protocol  Address          Age (min)  Hardware Addr   Type   Interface
 Internet  192.168.1.1             -   cc00.1090.0000  ARPA   Ethernet0/0

當 R1 ping 192.168.1.129,由於 R1 的 ARP Table 中沒有 192.168.1.129 的紀錄, R1 就會發出 ARP 查詢,R2 回應之後,再看看 ARP Table 就發現多了一筆新的紀錄,這正是 R2 e0/0 的 MAC Address。Age 是這條紀錄產生了多久,Cisco Router 預設會保留紀錄 4 小時。過了 4 小時的話,紀錄會被刪除,紀錄被刪除後,下一次要再要到這個 host 的話就要再做 ARP 查詢了。

R1#ping 192.168.1.129
 
 Type escape sequence to abort.
 Sending 5, 100-byte ICMP Echos to 192.168.1.129, timeout is 2 seconds:
 .!!!!
 Success rate is 80 percent (4/5), round-trip min/avg/max = 20/37/60 ms
 R1#show arp
 Protocol  Address          Age (min)  Hardware Addr   Type   Interface
 Internet  192.168.1.1             -   cc00.1090.0000  ARPA   Ethernet0/0
 Internet  192.168.1.129           0   cc01.1090.0000  ARPA   Ethernet0/0
R2#show interfaces Ethernet 0/0
 Ethernet0/0 is up, line protocol is up
   Hardware is AmdP2, address is cc01.1090.0000 (bia cc01.1090.0000)
   Internet address is 192.168.1.129/24

<--output omitted-->

如果想更改預設的設定,可以在 Interface 裡面使用 arp timeout <time> 指令。不建議把此時間設定得太低,這會大幅增加網絡的 broadcast,影響網路效能。

R1#conf terminal
 Enter configuration commands, one per line.  End with CNTL/Z.
 R1(config)#int ethernet 0/0
 R1(config-if)#arp timeout 7200

Proxy ARP

Proxy ARP 在 Router Interface 預設會開啟,Proxy ARP 可以讓 Router 在收到 ARP 查詢時,查看自已的 Routing Table,如果 Routing Table 包含查詢 IP 的網段,就會發 ARP 回覆。文字不易說明,請看以下例子。我們嘗試在剛才的兩隻 Router 中間加入另一隻 Router。

arp

R1 設定不變,R3 IP 設定如下:

hostname R3
 !
 interface Ethernet0/0
  ip address 192.168.1.2 255.255.255.128
 !
 interface Ethernet0/1
  ip address 192.168.1.129 255.255.255.128

由於 R1 和 R2 被 R3 阻隔,R1 的 Broadcast ARP 查詢不能到達 R2。但由於 R3 預設開啟了 Proxy ARP,他知道自己連著 192.168.1.130 所在的網絡,因此他會用自己 e0/0 的 MAC Address 來回覆這個 ARP 查詢。

首先,用 clear arp-cache 指令來清除原有的 ARP Table。然後再 ping 192.168.1.130,結果在 ARP Table 裡看到 R3 的 0/0 的 MAC Address。

R1#clear arp-cache
 R1#show arp
 Protocol  Address          Age (min)  Hardware Addr   Type   Interface
 Internet  192.168.1.1             -   cc00.1090.0000  ARPA   Ethernet0/0
 R1#ping 192.168.1.130
 
 Type escape sequence to abort.
 Sending 5, 100-byte ICMP Echos to 192.168.1.130, timeout is 2 seconds:
 .!!!!
 Success rate is 80 percent (4/5), round-trip min/avg/max = 12/24/40 ms
 R1#show arp
 Protocol  Address          Age (min)  Hardware Addr   Type   Interface
 Internet  192.168.1.1             -   cc00.1090.0000  ARPA   Ethernet0/0
 Internet  192.168.1.130           0   cc03.1090.0000  ARPA   Ethernet0/0
R3#show interfaces ethernet 0/0
 Ethernet0/0 is up, line protocol is up
   Hardware is AmdP2, address is cc03.1090.0000 (bia cc03.1090.0000)
   Internet address is 192.168.1.2/25

<--output omitted-->

如果想關掉 Proxy ARP,可在 Interface 下執行 no ip proxy-arp

R3#conf terminal
 Enter configuration commands, one per line.  End with CNTL/Z.
 R3(config)#int ethernet 0/0
 R3(config-if)#no ip proxy-arp

相關主題

發佈留言

2014-07-24

Posted In: Layer 2 網絡技術

Leave a Comment