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

相關主題

发表回复

2021-07-22

Posted In: Layer 2 网络技术

Leave a Comment