arp的作用和使用方法【转】

一、什么是arp

1. 什么是arp

地址解析协议(Address Resolution Protocol),其基本功能为透过目标设备的IP地址,查询目标设备的MAC地址,以保证通信的顺利进行。它是IPv4中网络层必不可少的协议,不过在IPv6中已不再适用,并被邻居发现协议(NDP)所替代。

说白了,就是把通过ip地址找到设备mac地址。

2. arp有什么作用

在计算机间通信的时候,计算机要知道目的计算机是谁(就像我们人交流一样,要知道对方是谁),这中间需要涉及到MAC地址,而MAC是真正的电脑的唯一标识符。

为什么需要ARP协议呢?因为在OSI七层模型中,对数据从上到下进行封装发送出去,然后对数据从下到上解包接收,但是上层(网络层)关心的IP地址,下层关心的是MAC地址,这个时候就需要映射IP和MAC,通过ip地址找到mac地址。

1.命令简介

arp(Address Resolution Protocol)操作主机的 ARP 缓存。

arp 可以显示 arp 缓冲区中的所有条目、删除指定的条目或者添加静态的 IP 地址与 MAC 地址对应关系。

2.命令格式

arp [-vn] [-H <type>] [-i <if>] [-ae] [<hostname>]

arp [-v] [-i <if>] -d <hostname> [pub]

arp [-v] [-H <type>] [-i <if>] -s <hostname> <hw_addr> [temp]

arp [-v] [-H <type>] [-i <if>] -s <hostname> <hw_addr> [netmask <nm>] pub

arp [-v] [-H <type>] [-i <if>] -Ds <hostname> <ifname> [netmask <nm>] pub

arp [-vnD] [-H <type>] [-i <if>] -f [<filename>]

3.选项说明

-a
使用备用 BSD 样式输出格式(没有固定列)。
-H, --hw-type, -t <type>
指定arp指令使用的地址类型。
-d <address>
从 arp 缓存中删除指定主机的 arp 条目。
-D, --use-device
使用指定接口的硬件地址。
-e
以 Linux 的显示风格显示 arp 缓存中的条目。
-i, --device <if>
指定要操作 arp 缓存的网络接口。
-n, --numeric
以数字方式显示 arp 缓存中的条目。
-v, --verbose
显示详细的arp缓存条目,包括缓存条目的统计信息。
-f, --file <filename>
设置主机的IP地址与 MAC 地址的静态映射。

 

4.常用示例

(1)查看 arp 缓存表。

arp
Address HWtype HWaddress Flags Mask Iface
169.254.0.47 ether fe:ee:7f:99:99:19 C eth0
169.254.0.4 ether fe:ee:7f:99:99:19 C eth0
169.254.0.15 ether fe:ee:7f:99:99:19 C eth0

 



(2)查看 arp 表,并且用 IP 显示而不是主机名称。

arp -n
Address HWtype HWaddress Flags Mask Iface
169.254.0.47 ether fe:ee:7f:99:99:19 C eth0
169.254.0.4 ether fe:ee:7f:99:99:19 C eth0
169.254.0.15 ether fe:ee:7f:99:99:19 C eth0

 



(3)查看 arp 表,使用备用 BSD 样式输出格式(没有固定列)。

arp -a
? (169.254.0.47) at fe:ee:7f:99:99:19 [ether] on eth0
? (169.254.0.4) at fe:ee:7f:99:99:19 [ether] on eth0
? (169.254.0.15) at fe:ee:7f:99:99:19 [ether] on eth0

 



(4)IP 和 MAC 地址绑定。

arp -s 172.16.0.76 00:50:56:26:d8:87

 



(5)删除 ARP 缓存表中指定项。

arp -d 169.254.0.47

 



(6)删除指定网卡的 arp 表。

arp -i eth0 -d 169.254.0.4

 



(7)使用 eth1 的 MAC 地址回答 eth0 上的 192.168.60.2 的 arp 请求。

arp -i eth0 -Ds 192.168.60.2 eth1 pub

 



(8)显示详细的 arp 缓存条目,包括缓存条目的统计信息。

arp -v
Address HWtype HWaddress Flags Mask Iface
169.254.0.47 ether fe:ee:7f:99:99:19 C eth0
169.254.0.4 ether fe:ee:7f:99:99:19 C eth0
169.254.0.15 ether fe:ee:7f:99:99:19 C eth0
169.254.0.3 ether fe:ee:7f:99:99:19 C eth0
169.254.0.2 ether fe:ee:7f:99:99:19 C eth0
169.254.128.8 ether fe:ee:7f:99:99:19 C eth0
169.254.128.12 ether fe:ee:7f:99:99:19 C eth0
169.254.0.138 ether fe:ee:7f:99:99:19 C eth0
169.254.0.55 ether fe:ee:7f:99:99:19 C eth0
10.0.0.1 ether fe:ee:7f:99:99:19 C eth0
169.254.0.23 ether fe:ee:7f:99:99:19 C eth0
Entries: 11 Skipped: 0 Found: 11

 


转自

(44条消息) Linux 命令(199)—— arp 命令_linux arp_恋喵大鲤鱼的博客-CSDN博客
https://blog.csdn.net/K346K346/article/details/127658885

如何利用ARP命令解决网络故障 | 《Linux就该这么学》
https://www.linuxprobe.com/arp-network.html

 

posted @ 2023-03-09 09:02  paul_hch  阅读(880)  评论(0编辑  收藏  举报