Linux 命令

arp 命令可以查看 ARP 缓存或者手动添加、删除缓存中的条目。

命令格式

arp [-evn] [-H type] [-i if] -a [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 ifa [netmask nm] pub

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

命令参数

-v, --verbose
  输出详细信息。

-n, --numeric
  以数字形式显示地址。

-H type, --hw-type type, -t type
  指定检查何种类型的 ARP 条目,默认的类型是 ether,其他取值有 arcnet(ARCnet)、pronet(PROnet)、ax25AX.25、 netrom(NET/ROM) 等。

-a [hostname], --all [hostname]
  显示特定主机对应的 ARP 条目,如果没有指定主机,则显示所有的条目。条目将以 BSD 的风格显示。

-d hostname, --delete hostname
  删除指定主机对应的 ARP 条目。

-e
  以默认的风格显示 ARP 条目。

-i If, --device If
  指定网络接口,如 eth0。

-s hostname hw_addr, --set hostname
  手动设置 ARP 条目。

-f filename, --file filename
  与 -s 选项类似,只是地址信息从指定的文件取的,如果没有指定文件,则 /etc/ethers 作为指定文件。文件每行的内容是以空格分隔开的物理地址和主机名。

实例

a) 查看 ARP 缓存。

[huey@huey-K42JE ~]$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
10.1.241.254             ether   c0:67:af:45:9d:3f   C                     eth0
10.1.241.145             ether   fa:1a:3e:b3:17:62   C                     eth0
10.1.241.253             ether   00:1c:54:ff:08:13   C                     eth0

b) 只显示 eth0 的 ARP 缓存。

[huey@huey-K42JE ~]$ arp -i eth0
Address                  HWtype  HWaddress           Flags Mask            Iface
10.1.241.254             ether   c0:67:af:45:9d:3f   C                     eth0
10.1.241.145             ether   fa:1a:3e:b3:17:62   C                     eth0

c) 手动 ARP 条目,将 10.1.241.253 与 00:1c:54:ff:08:13 绑定。

[huey@huey-K42JE ~]$ arp -s 10.1.241.253 00:1c:54:ff:08:13

d) 删除 10.1.241.253 主机对应的 ARP 条目。

[huey@huey-K42JE ~]$ arp -d 10.1.241.253
原文地址:https://www.cnblogs.com/huey/p/5413554.html