linux內核/proc/sys/net/ipv4/conf中下面會有各網卡的配置參數其中arp_ignore和arp_annouce與arp相關
arp_ignore 取值為integer
- 0 (default) :reply for any local target IP address configured on any interface
- 1 : reply only if the target IP address is local address configured on the incoming interface
- 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
- 3 : do not reply for local address configured with scope host,only resolutions for global and link addresses are replied
- 4-7 : reserved
- 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)實驗
- arp -en顯示arp解析的緩存
- --delete清除指定緩存條目,后必須跟<host>參數,但是非本網段的arp緩存刪不掉,必須使用--device參數指定設備參能刪除
我寫了一條命令可清除所有arp緩存 - arp -env|awk '/^[[:digit:]]/{print "arp -i",$5,"-d",$1}'|sh -x 或者 arp -env |awk '/^[[:digit:]]/{print "arp -i",$5,"-d",$1|"sh -x"}'
不一定全部適用 - HWtype表示物理網絡類型
Flags C表示cache,動態生成的
M表示map,靜態配置的映射關系
apr_ignore=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
- 0 (default): Use any local address,configured on any interface announce本機所有IP地址和其mac映射
- 1 : try to avoid local address that are not in the target's subnet for this interface announce同一網段的所有IP
- 2 : always use the best local address for this target announce本網卡同一網段所有IP