ARP(Address Resolution Protocol)地址解析协议用来建立和维护IP地址和MAC地址之间的映射关系,称为"ARP表"。ARP表中有动态表项和静态表项,动态表项可以老化。
ARP表
查看arp表
C:UsersJustin>arp -a 接口: 192.168.1.3 --- 0xd Internet 地址 物理地址 类型 192.168.1.1 78-c3-13-4b-1f-a1 动态 192.168.1.2 f4-83-cd-b1-69-b7 动态 192.168.1.255 ff-ff-ff-ff-ff-ff 静态 224.0.0.22 01-00-5e-00-00-16 静态 224.0.0.251 01-00-5e-00-00-fb 静态 224.0.0.252 01-00-5e-00-00-fc 静态 239.11.20.1 01-00-5e-0b-14-01 静态 239.255.255.250 01-00-5e-7f-ff-fa 静态 255.255.255.255 ff-ff-ff-ff-ff-ff 静态
添加ARP表项
C:UsersJustin>arp -s 10.10.10.10 34-bf-9c-00-01-76 C:UsersJustin>arp -a 接口: 192.168.1.3 --- 0xd Internet 地址 物理地址 类型 10.10.10.10 34-bf-9c-00-01-76 静态 192.168.1.1 78-c3-13-4b-1f-a1 动态 192.168.1.2 f4-83-cd-b1-69-b7 动态 192.168.1.255 ff-ff-ff-ff-ff-ff 静态 224.0.0.22 01-00-5e-00-00-16 静态 224.0.0.251 01-00-5e-00-00-fb 静态 224.0.0.252 01-00-5e-00-00-fc 静态 239.11.20.1 01-00-5e-0b-14-01 静态 239.255.255.250 01-00-5e-7f-ff-fa 静态 255.255.255.255 ff-ff-ff-ff-ff-ff 静态
ARP 报文分析
本机只知道对方的IP地址,不知道对方的MAC地址时,会在当前子网内广播ARP请求,让子网内所有设备接收到这个广播ARP请求报文;对方主机收到这个ARP请求报文之后,会发送一个单播ARP应答报文,告知自己的MAC地址。
ARP请求报文
广播包,EtherType 0x0806, IpProtocol 0x0800,OpCode 1
ARP应答报文
单播包,EtherType 0x0806, IpProtocol 0x0800,OpCode 2
ARP表刷新
RFC1122定义了四种ARP缓存条目刷新的机制:
1)Timeout 超时老化
2)Unicast Poll 单播轮询
Actively poll the remote host by periodically sending a point-to-point ARP Request to it, and delete the entry if no ARP Reply is received from N successive polls. Again, the timeout should be on the order of a minute, and typically N is 2。
定时向ARP表中的主机发送单播ARP请求报文,超过N次没有收到ARP应答报文,则从ARP表中删除该条目。
3)Link-Layer Advice 链路层故障清空ARP表
If the link-layer driver detects a delivery problem, flush the corresponding ARP cache entry.
4)Higher-layer Advice 应用层故障清空ARP表
Provide a call from the Internet layer to the link layer to indicate a delivery problem. The effect of this call would be to invalidate the corresponding cache entry.
This call would be analogous to the "ADVISE_DELIVPROB()" call from the transport layer to the Internet layer (see Section 3.4), and in fact the ADVISE_DELIVPROB routine might in turn call the link-layer advice routine to invalidate the ARP cache entry.
代理ARP
代理ARP是ARP协议的一个变种。 对于没有配置缺省网关的计算机要和其他网络中的计算机实现通信,网关收到源计算机的 ARP请求会使用自己的 MAC地址与目标计算机的 IP地址对源计算机进行应答。代理ARP就是将一个主机“作为”另一个主机对收到的ARP请求进行应答。它能使得在不影响路由表的情况下添加一个新的Router,使得子网对该主机来说变得更透明化。同时也会带来巨大的风险,除了ARP欺骗,和某个网段内的ARP增加,最重要的就是无法对网络拓扑进行网络概括。代理ARP的使用一般是使用在没有配置默认网关和路由策略的网络上的。