arping命令

arping命令

  arping命令用来向目标主机发送ARP请求。
  arping命令最简单的用法是用来探测与目标主机的网络连通性:

[root@localhost ~]# arping 192.168.1.102
ARPING 192.168.1.102 from 192.168.1.11 eth0
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.495ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.641ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.385ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.369ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.359ms
^CSent 5 probes (1 broadcast(s))
Received 5 response(s)
[root@localhost ~]#

  arping命令与ping命令类似,会一直执行,直到用户使用Ctrl+C强制终止。可以使用选项-f使得接收到第一个返回数据包时自动退出arping命令:

[root@localhost ~]# arping -f 192.168.1.102
ARPING 192.168.1.102 from 192.168.1.11 eth0
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.462ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)
[root@localhost ~]#

  与ping命令一样,可以使用选项-c指定发送包的次数,达到指定次数就会自动退出arping命令:

[root@localhost ~]# arping -c 4 192.168.1.102
ARPING 192.168.1.102 from 192.168.1.11 eth0
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.285ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.367ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.358ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.367ms
Sent 4 probes (1 broadcast(s))
Received 4 response(s)
[root@localhost ~]#

  与ping命令一样,可以使用选项-w指定执行的时间(单位秒),达到时间就会自动退出arping命令:

[root@localhost ~]# arping -w 10 192.168.1.102
ARPING 192.168.1.102 from 192.168.1.11 eth0
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.437ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.383ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.312ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.342ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.388ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.401ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.420ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.384ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.279ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.340ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.374ms
Sent 11 probes (1 broadcast(s))
Received 11 response(s)
[root@localhost ~]#

  arping命令可以使用选项-D(Duplicate address detection mode (DAD))来探测IP地址是否冲突,即有多个主机拥有同一个IP地址。如果探测到IP地址冲突,则返回0;否则,返回非0(xxx需要验证)。例如:

[root@localhost ~]# arping -D -c 4 192.168.1.102; echo $?
ARPING 192.168.1.102 from 0.0.0.0 enp0s3
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.481ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)
1
[root@localhost ~]#

  可以通过选项-I指定发送数据包的网络接口,例如:

[root@localhost ~]# arping -I eth0 192.168.1.102
ARPING 192.168.1.102 from 192.168.1.11 eth0
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.278ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.386ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.340ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.393ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.330ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.356ms
Unicast reply from 192.168.1.102 [1C:1B:0D:DD:19:68] 1.377ms
^CSent 7 probes (1 broadcast(s))
Received 7 response(s)
[root@localhost ~]#