# apt install iputils-arping # 安装工具
# arping -h # 获取帮助信息
Usage:
arping [options] <destination>
Options:
-f quit on first reply 等到第一个回复就退出
-q be quiet 表示不打印输出,写脚本不想打印输出的时候,应该用的到
-b keep on broadcasting, do not unicast 用于持续发送以太网广播帧(FFFFFFFFFFFF),arping一开始使用广播地址,在收到响应后就使用unicast地址
-D duplicate address detection mode 重复地址检测模式
-U unsolicited ARP mode, update your neighbours 不请自来的ARP模式,更新您的邻居
-A ARP answer mode, update your neighbours ARP应答模式,更新邻居
-V print version and exit
-c <count> how many packets to send 发送指定数量的arp包后,即停止并退出
-w <timeout> how long to wait for a reply 等待回复多长时间
-i <interval> set interval between packets (default: 1 second) 设置数据包之间的间隔(默认值:1秒)
-I <device> which ethernet device to use 使用哪个以太网设备
-s <source> source ip address 源IP地址
<destination> dns name or ip address
For more details see arping(8).
# arping -I em1 -c 5 -s $VIP $GATEWAY # 更新VIP的arp记录到网关GATEWAY(注意脚本中的网卡别填错了,要跟VIP所在网卡一致)
一些示例:
root@ubuntu18:~# arping -I ens3 -c 5 -s 10.9.36.85 10.9.36.254 # 更新arp记录到网关
ARPING 10.9.36.254 from 10.9.36.85 ens3
Unicast reply from 10.9.36.254 [40:55:39:EA:61:FF] 13.968ms
Unicast reply from 10.9.36.254 [40:55:39:EA:61:FF] 3.791ms
Unicast reply from 10.9.36.254 [40:55:39:EA:61:FF] 2.381ms
Unicast reply from 10.9.36.254 [40:55:39:EA:61:FF] 2.120ms
Unicast reply from 10.9.36.254 [40:55:39:EA:61:FF] 1.769ms
Sent 5 probes (1 broadcast(s))
Received 5 response(s)
root@ubuntu18:~# arp -a # 查看本地arp缓存表
? (10.9.36.252) at 00:07:7d:67:60:ff [ether] on ens3
? (10.9.36.14) at c8:1f:66:c2:bd:a3 [ether] on ens3
? (10.9.36.64) at 52:54:00:9d:17:dc [ether] on ens3
? (10.9.36.50) at 52:54:00:33:b4:b0 [ether] on ens3
? (10.9.36.52) at 52:54:00:99:cf:5e [ether] on ens3
? (10.9.36.112) at fa:16:3e:b5:d6:6f [ether] on ens3
? (10.9.36.65) at 52:54:00:46:fa:87 [ether] on ens3
? (10.9.36.62) at 52:54:00:35:d3:52 [ether] on ens3
? (10.9.36.51) at 52:54:00:85:a4:f1 [ether] on ens3
? (10.9.36.10) at f0:1f:af:e4:8f:b0 [ether] on ens3
? (172.18.0.6) at 02:42:ac:12:00:06 [ether] on docker_gwbridge
? (10.9.36.70) at 52:54:00:9e:db:b0 [ether] on ens3
? (10.9.36.12) at f0:1f:af:e9:c3:a9 [ether] on ens3
? (10.9.36.63) at 52:54:00:2f:28:35 [ether] on ens3
_gateway (10.9.36.254) at 40:55:39:ea:61:ff [ether] on ens3 <--
? (10.9.36.11) at f0:1f:af:e9:c2:ad [ether] on ens3
? (10.9.36.13) at c8:1f:66:c2:c1:ef [ether] on ens3
? (10.9.36.66) at 52:54:00:30:55:b6 [ether] on ens3
? (10.9.36.61) at 52:54:00:97:fe:e5 [ether] on ens3
? (10.9.36.68) at 52:54:00:da:53:c1 [ether] on ens3
# arping -I ens3 -c 2 10.9.36.10 # 查看IP对应的MAC地址
ARPING 10.9.36.10 from 10.9.36.85 ens3
Unicast reply from 10.9.36.10 [F0:1F:AF:E4:8F:B0] 0.841ms
Unicast reply from 10.9.36.10 [F0:1F:AF:E4:8F:B0] 0.971ms
Sent 2 probes (1 broadcast(s))
Received 2 response(s)