ARP缓存表更新机制
收到ARP请求后,更新ARP缓存表和应答的条件:
1,收到一个请求包,若目的mac是硬件广播地址,且目的IP是本机IP,即请求本机mac,则查看ARP缓存表是否有源主机IP与源主机mac
地址的对应条目,若有且与收到的不一致则更新,若无,则添加,最后构造一个针对请求主机的ARP单播应答包。
2, 收到一个请求包,若目的mac是硬件广播地址,但目的IP不是本机IP,即不是请求本机mac,那么忽略该请求。
(注:实验表明:目的mac是本机网卡mac,且目的IP是本机IP,主机也会作出应答。分析:收到的这个请求包可能发生了错误,因为既然知道了目的主机mac就无需再请求了,但也不排除是其他协议在检测网络状态)。
(结论:只有目的MAC是硬件广播地址,且目的IP是本机IP,才对条目进行添加或者更新,并回复应答包。)
arping命令
1.概述
arping常用于检测IP是否已经存在、某个IP的MAC的地址等。
2.arping各参数含义
a.无参数,持续的向特定IP地址请求arp
[root@smart Desktop]# arping 192.168.1.105
ARPING 192.168.1.105 from 192.168.1.120 eth0
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 1.324ms
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 104.092ms
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 8.286ms
b. -c count,发送arp包个数
[root@smart Desktop]# arping -c 1 192.168.1.105
ARPING 192.168.1.105 from 192.168.1.120 eth0
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 1.413ms
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 101.567ms
Sent 1 probes (1 broadcast(s))
Received 2 response(s)
[root@smart Desktop]# arping -c 2 192.168.1.105
ARPING 192.168.1.105 from 192.168.1.120 eth0
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 1.321ms
[root@smart Desktop]# arping -c 3 192.168.1.105
ARPING 192.168.1.105 from 192.168.1.120 eth0
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 1.378ms
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 45.732ms
[root@smart Desktop]# arping -c 4 192.168.1.105
ARPING 192.168.1.105 from 192.168.1.120 eth0
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 1.581ms
Unicast reply from 192.168.1.105 [3C:BD:3E:61:13:08] 14.577ms
Sent 4 probes (1 broadcast(s))
Received 2 response(s)
c. -f 收到回复后退出
[root@smart ~]# arping -f 192.168.1.1
ARPING 192.168.1.1 from 192.168.1.120 eth0
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.205ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)
1
2
3
4
5
d. -q 不输出结果,常与-c等共用
[root@smart ~]# arping -q 192.168.1.2 -c 1
[root@smart ~]# echo $?
e. -I interface address,网卡
[root@smart ~]# arping 192.168.1.1 -I eth0
ARPING 192.168.1.1 from 192.168.1.120 eth0
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.435ms
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.118ms
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.083ms
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.079ms
^CSent 4 probes (1 broadcast(s))
Received 4 response(s)
f. -s 指定源地址
[root@smart ~]# arping 192.168.1.1 -s 192.168.1.120
ARPING 192.168.1.1 from 192.168.1.120 eth0
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.183ms
Unicast reply from 192.168.1.1 [6C:59:40:FC:C4:F3] 1.153ms
^CSent 2 probes (1 broadcast(s))