最新消息:

sysctl arp_announce 的作用

arp admin 4303浏览 0评论

公司办公网络入口新增一接入带宽,接入网关是一 Linux 服务器,比较奇怪的是在 新增了相应的 IP 地址后,ping 其对应的网关总是失败。tcpdump 抓 ICMP 包根本 就看不到 ICMP 包出去。 arp -an 也没有看到该网关地址的 MAC 记录。于是, 只抓 ARP 包,结果如下:

# tcpdump -nn -p -i eno2 arp
18:12:33.846927 ARP, Request who-has 124.xxx.xxx.xx tell 106.x.x.xxx, length 28

很快发现问题,ARP 请求的地址和要求回应的地址不在一个局域网内。为什么不用同一 局域网内的地址作为回应地址呢?应该有个参数控制这种行为才对。于是通过 sysctl -a | grep arp 寻找相关的配置参数,发现 arp_announce 这个参数可能和 碰到的问题相关。查询文档 Documentation/networking/ip-sysctl.txt 后,修改 值为 2 (sysctl -w net.ipv4.conf.eno2.arp_announce=2)后问题迅速解决。当然, 要重启后配置生效则需要配置 /etc/sysctl.d/local.conf 文件内容如下:

net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_announce = 2

arp_announce 的文档摘录如下:

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.

     Increasing the restriction level gives more chance for
     receiving answer from the resolved target while decreasing
     the level announces more valid sender's information.

P.S. 这个参数在 LVS DR 模式里也会用到。

转载请注明:爱开源 » sysctl arp_announce 的作用

您必须 登录 才能发表评论!