linux arp命令学习

arp命令用来管理系统中的arp缓存。

1. 先了解一下arp协议?
ARP协议即Address Resolution Protocol,ARP协议是网络层协议。
地址解析协议用于将目标设备的IP地址转换为MAC地址,以保证通信的顺利进行。

2. 为什么会要arp缓存?
因为通过IP地址来查询MAC地址,是需要时间的;
另外根据局部性原理,最近一次访问的地址下次再次访问的概率非常大;
所以将最近访问的目标设备的IP与MAC缓存起来,有助于提高网络访问的效率。

以下试验:
1. 目前主机192.168.0.150最初不在arp缓存中,
sh-# arp
? (192.168.0.1) at b8:a3:86:ac:a2:5a [ether] on eth0
sh-#

2. ping这个目标主机,起初会卡一下,并且还会丢包,
sh-# ping 192.168.0.150
PING 192.168.0.150 (192.168.0.150) 56(84) bytes of data.
From 192.168.0.162 icmp_seq=1 Destination Host Unreachable
From 192.168.0.162 icmp_seq=2 Destination Host Unreachable
From 192.168.0.162 icmp_seq=3 Destination Host Unreachable
64 bytes from 192.168.0.150: icmp_req=4 ttl=64 time=650 ms
^C
--- 192.168.0.150 ping statistics ---
5 packets transmitted, 1 received, +3 errors, 80% packet loss, time 4016ms
rtt min/avg/max/mdev = 650.714/650.714/650.714/0.000 ms, pipe 3

sh-#

3. 因为192.168.0.150已经访问过,所以会被加到arp缓存中,
sh-# arp
? (192.168.0.1) at b8:a3:86:ac:a2:5a [ether] on eth0
? (192.168.0.150) at 78:52:1a:4d:d0:a5 [ether] on eth0
sh-#

4. 再去访问192.168.0.150看看,
sh-# ping 192.168.0.150
PING 192.168.0.150 (192.168.0.150) 56(84) bytes of data.
64 bytes from 192.168.0.150: icmp_req=1 ttl=64 time=103 ms
64 bytes from 192.168.0.150: icmp_req=2 ttl=64 time=126 ms
64 bytes from 192.168.0.150: icmp_req=3 ttl=64 time=34.1 ms
64 bytes from 192.168.0.150: icmp_req=4 ttl=64 time=56.1 ms
^C
--- 192.168.0.150 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3016ms
rtt min/avg/max/mdev = 34.199/80.174/126.437/36.738 ms

sh-#

5. 手动删除一条arp缓存信息,
sh-# arp -d 192.168.0.150
sh-# arp
? (192.168.0.1) at b8:a3:86:ac:a2:5a [ether] on eth0
? (192.168.0.150) at <incomplete> on eth0
sh-#

6. 如果要手动添加一条arp缓存记录,则必须要知道目标设备的IP地址以及MAC地址,
sh-# arp -s 192.168.0.150 78:52:1a:4d:d0:a5
sh-# arp
? (192.168.0.1) at b8:a3:86:ac:a2:5a [ether] on eth0
? (192.168.0.150) at 78:52:1a:4d:d0:a5 [ether] PERM on eth0
sh-#
sh-# ping 192.168.0.150
PING 192.168.0.150 (192.168.0.150) 56(84) bytes of data.
64 bytes from 192.168.0.150: icmp_req=1 ttl=64 time=297 ms
64 bytes from 192.168.0.150: icmp_req=2 ttl=64 time=105 ms
^C
--- 192.168.0.150 ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2011ms
rtt min/avg/max/mdev = 105.379/201.388/297.397/96.009 ms

sh-#

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值