一、arp_ignore和arp_announce介紹
Define 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_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.
sysctl.conf中包含all和eth/lo(具體網卡)的arp_ignore參數,取其中較大的值生效。
二、arp_ignore和arp_announce參數示例

(1)當arp_ignore參數配置為0時,eth1網卡上收到目的IP為環回網卡IP的arp請求,但是eth1也會返回arp響應,把自己的mac地址告訴對端。
(2)當arp_ignore參數配置為1時,eth1網卡上收到目的IP為環回網卡IP的arp請求,發現請求的IP不是自己網卡上的IP,不會回arp響應。
(3)當arp_announce參數配置為0時,系統要發送的IP包源地址為eth1的地址,IP包目的地址根據路由表查詢判斷需要從eth2網卡發出,這時會先從eth2網卡發起一個arp請求,用於獲取目的IP地址的MAC地址。該arp請求的源MAC自然是eth2網卡的MAC地址,但是源IP地址會選擇eth1網卡的地址。
(4)當arp_announce參數配置為2時,eth2網卡發起arp請求時,源IP地址會選擇eth2網卡自身的IP地址。
三、arp_ignore和arp_announce參數在DR模式下的作用
1. arp_ignore
因為DR模式下,每個真實服務器節點都要在環回網卡上綁定虛擬服務IP。這時候,如果客戶端對於虛擬服務IP的arp請求廣播到了各個真實服務器節點,如果arp_ignore參數配置為0,則各個真實服務器節點都會響應該arp請求,此時客戶端就無法正確獲取LVS節點上正確的虛擬服務IP所在網卡的MAC地址。假如某個真實服務器節點A的網卡eth1響應了該arp請求,客戶端把A節點的eth1網卡的MAC地址誤認為是LVS節點的虛擬服務IP所在網卡的MAC,從而將業務請求消息直接發到了A節點的eth1網卡。這時候雖然因為A節點在環回網卡上也綁定了虛擬服務IP,所以A節點也能正常處理請求,業務暫時不會受到影響。但時此時由於客戶端請求沒有發到LVS的虛擬服務IP上,所以LVS的負載均衡能力沒有生效。造成的后果就是,A節點一直在單節點運行,業務量過大時可能會出現性能瓶頸。
所以DR模式下要求arp_ignore參數要求配置為1。
2. arp_announce
四、arp_ignore和arp_announce參數的配置方法
arp_ignore和arp_announce參數分別有all,default,lo,eth1,eth2...等對應不同網卡的具體參數。當all和具體網卡的參數值不一致時,取較大值生效。
一般只需修改all和某個具體網卡的參數即可(取決於你需要修改哪個網卡)。下面以修改lo網卡為例:
1. 修改/etc/sysctl.conf文件,然后sysctl -p刷新到內存。
2. 使用sysctl -w直接寫入內存:
3. 修改/proc文件系統: