ARP 在更改端口 IP 地址时发送 ARP 请求

网络工程 思科-ios ARP gns3
2022-02-22 00:08:26

在 GNS3 上使用 c7200 图像。我这样配置了两个路由器: GNS3 拓扑

打开 arp 调试,在分配一个 ip 地址后,我看到每个路由器都发送一个免费的 ARP 响应数据包(此处仅显示 R1 的调试输出):

 ARP: flush cache for interface FastEthernet0/0, by 60093304
*Jun 18 23:05:41.419: ARP: flushing ARP entries for interface FastEthernet0/0
*Jun 18 23:05:41.427: IP ARP: sent rep src 192.168.1.1 ca01.2f98.0000,
                 dst 192.168.1.1 ffff.ffff.ffff FastEthernet0/0

查看show arp输出显示,此时两个路由器都没有了解彼此的 IP 到 ARP 映射。我了解发送无偿 ARP 响应数据包是为了检查 IP 地址冲突。但是,为什么路由器不能使用免费的 arp 数据包将条目插入到它们的 arp 表中?

接下来从 R1 ping R2(因此两个路由器都有彼此的 ip-to-mac 条目),我将 R1 的 ip 地址更改为 192.168.1.3,显示 R1 的调试输出(时间戳已删除,每一行都是一个新的输出消息:

ARP: flush cache for interface FastEthernet0/0, by 60093304
IP ARP: sent req src 192.168.1.3 ca01.2f98.0000, dst 192.168.1.2 ca02.4314.0000 FastEthernet0/0
ARP: flushing ARP entries for interface FastEthernet0/0
IP ARP: sent rep src 192.168.1.3 ca01.2f98.0000, dst 192.168.1.3 ffff.ffff.ffff FastEthernet0/0
IP ARP: rcvd rep src 192.168.1.2 ca02.4314.0000, dst 192.168.1.3 FastEthernet0/0
IP ARP: creating entry for IP address: 192.168.1.2, hw: ca02.4314.0000

随后对 R2 的 arp 表的检查表明,R2 有一个新配置的地址的新 ARP 条目,在上面的输出中,我们可以看到它在第 5 行作为对第 2 行请求的响应接收到。为什么 ARP 请求在第二行发送?

1个回答

但是,为什么路由器不能使用免费的 arp 数据包将条目插入到它们的 arp 表中?

因为设备应该只更新现有的 ARP 表条目,而不是为此创建新条目,除非该设备是目标。这在RFC 826,以太网地址解析协议中包含的伪代码中进行了解释:

 ?Do I have the hardware type in ar$hrd? Yes: (almost definitely)  
 [optionally check the hardware length ar$hln]   ?Do I speak the
 protocol in ar$pro?   Yes:
     [optionally check the protocol length ar$pln]
     Merge_flag := false
     If the pair <protocol type, sender protocol address> is
         already in my translation table, update the sender
         hardware address field of the entry with the new
         information in the packet and set Merge_flag to true.
     ?Am I the target protocol address?
     Yes:
       If Merge_flag is false, add the triplet <protocol type,
           sender protocol address, sender hardware address> to
           the translation table.
       ?Is the opcode ares_op$REQUEST?  (NOW look at the opcode!!)
       Yes:
         Swap hardware and protocol fields, putting the local
             hardware and protocol addresses in the sender fields.
         Set the ar$op field to ares_op$REPLY
         Send the packet to the (new) target hardware address on
             the same hardware on which the request was received.

注意上面写着“我是目标协议地址吗? ”的部分,“否”表示放弃它。

为什么发送第二行的 ARP 请求?

路由器在更改其地址后正在更新其 ARP 表,这将同时更新两个路由器的 ARP 表以用于这些接口。