(转)Linux内核参数之arp_ignore和arp_announce
原文:https://blog.csdn.net/ccy19910925/article/details/79960599
一、arp_ignore和arp_announce介紹
arp_ignore和arp_announce參數(shù)都和ARP協(xié)議相關,主要用于控制系統(tǒng)返回arp響應和發(fā)送arp請求時的動作。這兩個參數(shù)很重要,特別是在LVS的DR場景下,它們的配置直接影響到DR轉(zhuǎn)發(fā)是否正常。 首先看一下Linux內(nèi)核文檔中對于它們的描述: arp_ignore - INTEGERDefine different modes for sending replies in response to
received ARP requests that resolve local target IP addresses:
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 same subnet on this interface
3 - do not reply for local addresses configured with scope host,
only resolutions for global and link addresses are replied
4-7 - reserved
8 - do not reply for all local addresses
The max value from conf/{all,interface}/arp_ignore is used
when ARP request is received on the {interface} arp_ignore參數(shù)的作用是控制系統(tǒng)在收到外部的arp請求時,是否要返回arp響應。 arp_ignore參數(shù)常用的取值主要有0,1,2,3~8較少用到: 0:響應任意網(wǎng)卡上接收到的對本機IP地址的arp請求(包括環(huán)回網(wǎng)卡上的地址),而不管該目的IP是否在接收網(wǎng)卡上。 1:只響應目的IP地址為接收網(wǎng)卡上的本地地址的arp請求。 2:只響應目的IP地址為接收網(wǎng)卡上的本地地址的arp請求,并且arp請求的源IP必須和接收網(wǎng)卡同網(wǎng)段。 3:如果ARP請求數(shù)據(jù)包所請求的IP地址對應的本地地址其作用域(scope)為主機(host),則不回應ARP響應數(shù)據(jù)包,如果作用域為全局(global)或鏈路(link),則回應ARP響應數(shù)據(jù)包。 4~7:保留未使用 8:不回應所有的arp請求 sysctl.conf中包含all和eth/lo(具體網(wǎng)卡)的arp_ignore參數(shù),取其中較大的值生效。
arp_announce - INTEGER
Define different restriction levels for announcing the local
source IP address from IP packets in ARP requests sent on
interface:
0 - (default) Use any local address, configured on any interface
1 - Try to avoid local addresses that are not in the target's
subnet for this interface. This mode is useful when target
hosts reachable via this interface require the source IP
address in ARP requests to be part of their logical network
configured on the receiving interface. When we generate the
request we will check all our subnets that include the
target IP and will preserve the source address if it is from
such subnet. If there is no such subnet we select source
address according to the rules for level 2.
2 - Always use the best local address for this target.
In this mode we ignore the source address in the IP packet
and try to select local address that we prefer for talks with
the target host. Such local address is selected by looking
for primary IP addresses on all our subnets on the outgoing
interface that include the target IP address. If no suitable
local address is found we select the first local address
we have on the outgoing interface or on all other interfaces,
with the hope we will receive reply for our request and
even sometimes no matter the source IP address we announce.
The max value from conf/{all,interface}/arp_announce is used. arp_announce的作用是控制系統(tǒng)在對外發(fā)送arp請求時,如何選擇arp請求數(shù)據(jù)包的源IP地址。(比如系統(tǒng)準備通過網(wǎng)卡發(fā)送一個數(shù)據(jù)包a,這時數(shù)據(jù)包a的源IP和目的IP一般都是知道的,而根據(jù)目的IP查詢路由表,發(fā)送網(wǎng)卡也是確定的,故源MAC地址也是知道的,這時就差確定目的MAC地址了。而想要獲取目的IP對應的目的MAC地址,就需要發(fā)送arp請求。arp請求的目的IP自然就是想要獲取其MAC地址的IP,而arp請求的源IP是什么呢? 可能第一反應會以為肯定是數(shù)據(jù)包a的源IP地址,但是這個也不是一定的,arp請求的源IP是可以選擇的,控制這個地址如何選擇就是arp_announce的作用) arp_announce參數(shù)常用的取值有0,1,2。 0:允許使用任意網(wǎng)卡上的IP地址作為arp請求的源IP,通常就是使用數(shù)據(jù)包a的源IP。 1:盡量避免使用不屬于該發(fā)送網(wǎng)卡子網(wǎng)的本地地址作為發(fā)送arp請求的源IP地址。 2:忽略IP數(shù)據(jù)包的源IP地址,選擇該發(fā)送網(wǎng)卡上最合適的本地地址作為arp請求的源IP地址。
sysctl.conf中包含all和eth/lo(具體網(wǎng)卡)的arp_ignore參數(shù),取其中較大的值生效。
二、arp_ignore和arp_announce參數(shù)示例
(1)當arp_ignore參數(shù)配置為0時,eth1網(wǎng)卡上收到目的IP為環(huán)回網(wǎng)卡IP的arp請求,但是eth1也會返回arp響應,把自己的mac地址告訴對端。
(2)當arp_ignore參數(shù)配置為1時,eth1網(wǎng)卡上收到目的IP為環(huán)回網(wǎng)卡IP的arp請求,發(fā)現(xiàn)請求的IP不是自己網(wǎng)卡上的IP,不會回arp響應。
?
?
(3)當arp_announce參數(shù)配置為0時,系統(tǒng)要發(fā)送的IP包源地址為eth1的地址,IP包目的地址根據(jù)路由表查詢判斷需要從eth2網(wǎng)卡發(fā)出,這時會先從eth2網(wǎng)卡發(fā)起一個arp請求,用于獲取目的IP地址的MAC地址。該arp請求的源MAC自然是eth2網(wǎng)卡的MAC地址,但是源IP地址會選擇eth1網(wǎng)卡的地址。
?
(4)當arp_announce參數(shù)配置為2時,eth2網(wǎng)卡發(fā)起arp請求時,源IP地址會選擇eth2網(wǎng)卡自身的IP地址。
?
三、arp_ignore和arp_announce參數(shù)在DR模式下的作用
1. arp_ignore
因為DR模式下,每個真實服務器節(jié)點都要在環(huán)回網(wǎng)卡上綁定虛擬服務IP。這時候,如果客戶端對于虛擬服務IP的arp請求廣播到了各個真實服務器節(jié)點,如果arp_ignore參數(shù)配置為0,則各個真實服務器節(jié)點都會響應該arp請求,此時客戶端就無法正確獲取LVS節(jié)點上正確的虛擬服務IP所在網(wǎng)卡的MAC地址。假如某個真實服務器節(jié)點A的網(wǎng)卡eth1響應了該arp請求,客戶端把A節(jié)點的eth1網(wǎng)卡的MAC地址誤認為是LVS節(jié)點的虛擬服務IP所在網(wǎng)卡的MAC,從而將業(yè)務請求消息直接發(fā)到了A節(jié)點的eth1網(wǎng)卡。這時候雖然因為A節(jié)點在環(huán)回網(wǎng)卡上也綁定了虛擬服務IP,所以A節(jié)點也能正常處理請求,業(yè)務暫時不會受到影響。但時此時由于客戶端請求沒有發(fā)到LVS的虛擬服務IP上,所以LVS的負載均衡能力沒有生效。造成的后果就是,A節(jié)點一直在單節(jié)點運行,業(yè)務量過大時可能會出現(xiàn)性能瓶頸。
所以DR模式下要求arp_ignore參數(shù)要求配置為1。
2. arp_announce
每個機器或者交換機中都有一張arp表,該表用于存儲對端通信節(jié)點IP地址和MAC地址的對應關系。當收到一個未知IP地址的arp請求,就會再本機的arp表中新增對端的IP和MAC記錄;當收到一個已知IP地址(arp表中已有記錄的地址)的arp請求,則會根據(jù)arp請求中的源MAC刷新自己的arp表。 如果arp_announce參數(shù)配置為0,則網(wǎng)卡在發(fā)送arp請求時,可能選擇的源IP地址并不是該網(wǎng)卡自身的IP地址,這時候收到該arp請求的其他節(jié)點或者交換機上的arp表中記錄的該網(wǎng)卡IP和MAC的對應關系就不正確,可能會引發(fā)一些未知的網(wǎng)絡問題,存在安全隱患。 所以DR模式下要求arp_announce參數(shù)要求配置為2。四、arp_ignore和arp_announce參數(shù)的配置方法
arp_ignore和arp_announce參數(shù)分別有all,default,lo,eth1,eth2...等對應不同網(wǎng)卡的具體參數(shù)。當all和具體網(wǎng)卡的參數(shù)值不一致時,取較大值生效。
一般只需修改all和某個具體網(wǎng)卡的參數(shù)即可(取決于你需要修改哪個網(wǎng)卡)。下面以修改lo網(wǎng)卡為例:
?1. 修改/etc/sysctl.conf文件,然后sysctl -p刷新到內(nèi)存。
net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.lo.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.lo.arp_announce=2?2. 使用sysctl -w直接寫入內(nèi)存:
sysctl -w net.ipv4.conf.all.arp_ignore=1 sysctl -w net.ipv4.conf.lo.arp_ignore=1 sysctl -w net.ipv4.conf.all.arp_announce=2 sysctl -w net.ipv4.conf.lo.arp_announce=2?3. 修改/proc文件系統(tǒng):
echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2">/proc/sys/net/ipv4/conf/all/arp_announce echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce轉(zhuǎn)載于:https://www.cnblogs.com/liujiacai/p/10448137.html
總結
以上是生活随笔為你收集整理的(转)Linux内核参数之arp_ignore和arp_announce的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查询数据库耗费资源的sql
- 下一篇: 其它综合-使用Putty远程连接管理Li