详细讲解linux内核参数arp_announce和arp_ignore

linux内核/proc/sys/net/ipv4/conf中下面会有各网卡的配置参数其中arp_ignore和arp_annouce与arp相关

 

 

arp_ignore  取值为integer

  1. 0 (default) :reply for any local target IP address configured on any interface
  2. 1 : reply only if the target IP address is local address configured on the incoming interface
  3. 2 : reply only if the target IP address is local address configured on the incoming interface and both with the sender's IP address are part from the same subnet on this interface
  4. 3 : do not reply for local address configured with scope host,only resolutions for global and link addresses are replied
  5. 4-7 : reserved
  6. 8 : do not reply for all local addresses


arp_ignore=0:此为默认值,遇到任何网卡,任何IP地址,内核都会相应arp请求

arp_ignore=1:只有IP地址配置在接收到arp请求的网卡上时,内核才会做出arp回应

arp_ignore=2:比arp_ignore多了一层限制,就是不仅要同网卡,还必须同网段

arp_ignore=3:scope为host的全部拒绝,只回应IP地址scope为global和link的

arp_ignore=8:属于自我封闭式,不做出任何arp回应,如果其他主机要与本机通信,需设置固定ip mac对应关系

    

 

 

     /etc/ethers中 ip mac的格式,每行一条
    chmod +x /etc/rc.d/rc.local

    echo 'arp -f' >> /etc/rc.d/rc.local

 

 

实验准备:利用pend1(192.168.8.6)  pend2(192.168.8.7)实验

  1. arp -en显示arp解析的缓存

     

  2. --delete清除指定缓存条目,后必须跟<host>参数,但是非本网段的arp缓存删不掉,必须使用--device参数指定设备参能删除
    我写了一条命令可清除所有arp缓存

  3. arp -env|awk '/^[[:digit:]]/{print "arp -i",$5,"-d",$1}'|sh -x  或者   arp -env |awk '/^[[:digit:]]/{print "arp -i",$5,"-d",$1|"sh -x"}'
    不一定全部适用
  4. HWtype表示物理网络类型
    Flags C表示cache,动态生成的
        M表示map,静态配置的映射关系

     

     

     

     

     

apr_ignore=1

 

  1. 清除所有arp缓存

    

 

 

     

 

 

   2.设置内核参数
    

 

 

     

 

 

     

 

    3.抓包

 

 

 

    4.pend1 ping pend2
  

 

 

 

 

 

 ping的是pend2的第二张网卡,内核没有做出任何arp相应,因为10.1.1.2不是incoming interface

ping pend2的第一张网卡的10.1.1.3地址

 

 

 

 

 

 

 

 

 注意观察pend1的arp缓存情况
10.1.1.3 和 192.168.8.7 都是pend2 的 ens33网卡对应相同HWaddress
10.1.1.2 为pend2 ens37网卡 没有解析到mac

 

 

 

 将arp_ignore设为0

 

 

 

 

 

 

 发现已经能ping通了

 

 

 观察pend1 的arp缓存发现192.168.8.7   10.1.1.2  10.1.1.3 对应的mac地址全部相同,通信网卡为ens33

 

 

 

大家需要用心分析通信过程

 

接下来清除所有arp缓存,进行apr_ignore=2的实验

 

 

 

 

 

 

 

 

 

 

 

 发现pend2的同一网卡不同网段的IP内核已经拒绝arp请求了

 

 

arp_announce   取值为integer

  1. 0 (default): Use any local address,configured on any interface   announce本机所有IP地址和其mac映射
  2. 1 : try to avoid local address that are not in the target's subnet for this interface  announce同一网段的所有IP
  3. 2 : always use the best local address for this target  announce本网卡同一网段所有IP
posted @ 2020-06-06 18:38  ascertain  阅读(1141)  评论(0编辑  收藏  举报