
命令红色字体标记
系统初始arp环境
[root@esx ~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.1.175 ether 00:24:1D:97:B6:7F C vswif0
192.168.1.120 ether 00:1F:C6:3A:DC:81 C vswif0
192.168.1.51 (incomplete) vswif0
执行清除所有arp 缓存命令
[root@esx ~]# arp -n|awk '/^[1-9]/{print "arp -d " $1}'|sh -x
+ arp -d 192.168.1.175
+ arp -d 192.168.1.120
+ arp -d 192.168.1.51
Linux是一套免费使用和自由传播的类Unix *** 作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的 *** 作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络 *** 作系统。
组合命令清楚所有arp缓存:
[html] view plaincopy
arp -n|awk '/^[1-9]/{system("arp -d "$1)}'
以上命令必须 root 才可以执行。
使用ip命令清除某一网络接口的arp(下面命令是 eth0 接口)
[html] view plaincopy
ip neigh flush dev eth0
Linux 清除arp缓存是把列表标记为(incomplete),在下一次系统清理垃圾是会清除。
Liunx添加ARP表方式如下:[功能]管理系统的arp缓存。 [描述]用来管理系统的arp缓存,常用的命令包括:arp: 显示所有的表项。arp -d address: 删除一个arp表项。arp -s address hw_addr: 设置一个arp表项。 常用参数:-a 使用bsd形式输出。(没有固定的列)-n 使用数字形式显示ip地址,而不是默认的主机名形式。-D 不是指定硬件地址而是指定一个网络接口的名称,表项将使用相应接口的MAC地址。一般用来设置ARP代理。-H type, --hw-type type: 指定检查特定类型的表项,默认type为ether,还有其他类型。-i If, --device If: 指定设置哪个网络接口上面的arp表项。-f filename: 作用同'-s',不过它通过文件来指定IP地址和MAC地址的绑定。文件中每行分别是主机和MAC,中间以空格分割。如果没有指定文件名称,则使用/etc/ethers文件。 以下例子中,用主机名称的地方也可以用点分10进制的ip地址来表示。另外输出结果中用"C"表示ARP缓存内容,"M"表示永久性表项,"P"表示公共的表项。[举例]*查看arp表:#arpAddress HWtype HWaddress FlagsMaskIfacehostname1ether 44:37:e6:97:92:16 C eth0hostname2ether 00:0f:fe:43:28:c5 C eth0hostname3ether 00:1d:92:e3:d5:ee C eth0hostname4ether 00:1d:0f:11:f2:a5 C eth0这里,Flags中的"C"代表此表项目是高速缓存中的内容,高速缓存中的内容过一段时间(一般20分钟)会清空,而"M"则表示静态表项,静态表项的内容不会过一段时间被清空。 *查看arp表,并且用ip显示而不是主机名称:# arp -nAddress HWtype HWaddress FlagsMaskIface10.1.10.254 ether 00:1d:92:e3:d5:ee C eth010.1.10.253 ether 44:37:e6:9b:2c:53 C eth010.1.10.178 ether 00:1b:78:83:d9:85 C eth010.1.10.119 ether 00:1d:0f:11:f2:a5 C eth0这里,对于上面的条目,假设当我们"ping 10.1.10.1"通过之后,arp中会多一条"10.1.10.1"相关的信息。 *查看arp表,显示主机名称和ip:#arp -ans.amazon.esdl.others.com (10.1.10.254) at00:1d:92:e3:d5:ee [ether] on eth0server.amazon.eadl.others.com (10.1.10.253) at44:37:e6:9b:2c:53 [ether] on eth0D2-baijh.amazon.esdl.others.com (10.1.10.178) at00:1b:78:83:d9:85 [ether] on eth0aplab.local (10.1.10.119) at 00:1d:0f:11:f2:a5[ether] on eth0 *添加一对IP和MAC地址的绑定:# arp -s 10.1.1.1 00:11:22:33:44:55:66这里,如果网络无法达到,那么会报告错误,具体如下:root@quietheart:/home/lv-k# arp -s 10.1.1.100:11:22:33:44:55:66SIOCSARP: Network is unreachableroot@quietheart:/home/lv-k# arp -nAddress HWtype HWaddress FlagsMaskIface10.1.10.254 ether 00:1d:92:e3:d5:ee C eth010.1.10.253 ether 44:37:e6:9b:2c:53 C eth010.1.10.178 ether 00:1b:78:83:d9:85 C eth010.1.10.119 ether 00:1d:0f:11:f2:a5 C eth0实际上,如果"arp -s"设置成功之后,会增加一个Flags为"CM"的表项,有些系统静态条目不会因为ARP响应而更新,而高速缓存中的条目会因此而更新。如果想要手工设置没有"M",那么用"temp"选项,例如:"arp -s IP MAC temp"类似的命令,实践发现,如果已经设置过IP了,那么再设置也不会改变其Flags。 *删除一个arp表项:# arp -d 10.1.10.118这里,删除之后只是硬件地址没有了,如下:root@quietheart:~# arp -nAddress HWtype HWaddress FlagsMaskIface10.1.10.118 ether 00:25:9c:c2:79:90 CMeth010.1.10.254 ether 00:1d:92:e3:d5:ee C eth0root@quietheart:~# arp -d 10.1.10.118root@quietheart:~# arp -nAddress HWtype HWaddress FlagsMaskIface10.1.10.118 (incomplete) eth010.1.10.254 ether 00:1d:92:e3:d5:ee C*删除eth0上面的一个arp表项:# arp -i eth0 -d 10.1.10.118 [其它]*指定回复的MAC地址:#/usr/sbin/arp -i eth0 -Ds 10.0.0.2 eth1 pub当eth0收到IP地址为10.0.0.2的请求时,将会用eth1的MAC地址回答。例如,双网卡机器运行这条命令:/usr/sbin/arp -i eth0 -Ds 10.0.0.2 eth1 pub会多一项:10.0.0.2 * MPeth01、系统初始arp环境[root@esx ~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.1.175 ether 00:24:1D:97:B6:7F C vswif0
192.168.1.120 ether 00:1F:C6:3A:DC:81 C vswif0
192.168.1.51(incomplete) vswif0
2、执行清除所有arp 缓存命令
[root@esx ~]# arp -n|awk '/^[1-9]/{print "arp -d " $1}'|sh -x
+ arp -d 192.168.1.175
+ arp -d 192.168.1.120
+ arp -d 192.168.1.51
3、执行命令后,本机arp缓存信息
[root@esx ~]# arp -n
Address HWtype HWaddress Flags MaskIface
192.168.1.175 (incomplete)vswif0
192.168.1.120 (incomplete)vswif0
192.168.1.51 (incomplete) vswif0
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)