linux的网络hack用法之arp

arp

我们都知道arp协议在网络中重要位置,如果没有arp整个二层和三层的网络将全部瘫痪,那么linux 内核在arp上面有哪些细节和特殊用法吗,下面我们逐一介绍
首先看一下各种状态
这里写图片描述
这里我们看到arp表所有的状态信息,我特地标注黄色的stale状态是一个最特殊的状态。
然后再看看各个状态的切换图
这里写图片描述
首先是arp的表的配置在

/proc/sys/net/ipv4/neigh/*/*

文件中,第一个* 号代表网卡。

用户态征询

在这个目录下,有个app_solicit 的文件,先看作用

  app_solicit (since Linux 2.2)
              The maximum number of probes to send to the user space ARP
              daemon via netlink before dropping back to multicast probes
              (see mcast_solicit).  Defaults to 0.

这里如果设置一个大于0的指,那么linux将在发送arp请求之前,先向本地用户空间程序发送一个arp的探测,那么用户空间就可以直接返回arp的结果,flannel网络的实现就是利用这个原理。

reachable 检查周期

这个参数是指定已经reachable arp条目的检查周期

 base_reachable_time (since Linux 2.2)
              Once a neighbor has been found, the entry is considered to be
              valid for at least a random value between base_reach‐
              able_time/2 and 3*base_reachable_time/2.  An entry's validity
              will be extended if it receives positive feedback from higher
              level protocols.  Defaults to 30 seconds.  This file is now
              obsolete in favor of base_reachable_time_ms.

它虽然设定的固定数值,但真正作用的使用是 1/2 到 3/2的一个随机数值,也就是说如果设置30s,那么它的数值将在15s到45s之间。如果收到了高层协议的数据反馈那么就可以确认是有效的。

延迟探测时间

这个参数指定延迟探测的,当stale状态的后并不是直接进入probe探测阶段,而是先延迟一段时间

 delay_first_probe_time (since Linux 2.2)
              Delay before first probe after it has been decided that a
              neighbor is stale.  Defaults to 5 seconds.

这样如果在这个时间段内,有来自stale机器的数据包达到就可以直接从delay进入reachable了,避免arp的发送

gc 时间

这两个参数是是指定gc回收的周期

      gc_interval (since Linux 2.2)
              How frequently the garbage collector for neighbor entries
              should attempt to run.  Defaults to 30 seconds.

       gc_stale_time (since Linux 2.2)
              Determines how often to check for stale neighbor entries.
              When a neighbor entry is considered stale, it is resolved
              again before sending data to it.  Defaults to 60 seconds.

gc_interval是gc回收的周期,而gc_stale_time是检查已经是stale的arp项。

gc保存的上限

gc_thresh1 (since Linux 2.2)
              The minimum number of entries to keep in the ARP cache.  The
              garbage collector will not run if there are fewer than this
              number of entries in the cache.  Defaults to 128.

gc_thresh2 (since Linux 2.2)
              The soft maximum number of entries to keep in the ARP cache.
              The garbage collector will allow the number of entries to
              exceed this for 5 seconds before collection will be performed.
              Defaults to 512.

gc_thresh3 (since Linux 2.2)
              The hard maximum number of entries to keep in the ARP cache.
              The garbage collector will always run if there are more than
              this number of entries in the cache.  Defaults to 1024.

这里的gc三个阈值代表不同的三个触发点,当低于gc_thresh1时不会触发gc,当达到gc_thresh2后开始触发回收,而gc_thresh3是一个硬上限,不能超过,否自会报没有空间存储arp表的错误,当flannel集群大于1000个节点后,会产生这个问题,需要关注一下。

如果想要临时修改可以直接通过proc文件系统修改

/proc/sys/net/ipv4/neigh/default/gc_thresh1
/proc/sys/net/ipv4/neigh/default/gc_thresh2
/proc/sys/net/ipv4/neigh/default/gc_thresh3

如果永久生效还是要通过sysctl去修改,老版本的linux是通过/etc/sysctl.conf 去修改的,但新版redhat是通过在cat /etc/sysctl.d/*.conf 的配置去修改,然后通过sysctl -p或者-f去生效。

发布了215 篇原创文章 · 获赞 103 · 访问量 461万+

猜你喜欢

转载自blog.csdn.net/u010278923/article/details/82345016