目录
- 问题
- 查找
- 解决
- 方式
- 参考
问题
linux 在使用双网卡系统时,当这两个不同网段的网口接到同一个交换机上,会出现 eth0 的 arp 请求,会在 eth1 上收到并回复,相当于自己检测到了自己的 ip。
查找
linux 的底层,默认情况下,多网卡的 arp 是互通的。
解决
可通过配置 arp_ignore
解决
arp_ignore - INTEGERDefine different modes for sending replies in response toreceived ARP requests that resolve local target IP addresses:0 - (default): reply for any local target IP address, configuredon any interface1 - reply only if the target IP address is local addressconfigured on the incoming interface2 - reply only if the target IP address is local addressconfigured on the incoming interface and both with thesender's IP address are part from same subnet on this interface3 - do not reply for local addresses configured with scope host,only resolutions for global and link addresses are replied4-7 - reserved8 - do not reply for all local addressesThe max value from conf/{all,interface}/arp_ignore is usedwhen ARP request is received on the {interface}
arp_ignore 参数常用的取值主要有 0、1、2
,3~8 较少用到:
copy 解释如下:
0 - 响应任意网卡上接收到的对本机IP地址的arp请求(包括环回网卡上的地址),
而不管该目的IP是否在接收网卡上。1 - 只响应目的IP地址为接收网卡上的本地地址的arp请求。2 - 只响应目的IP地址为接收网卡上的本地地址的arp请求,并且arp请求的源IP
必须和接收网卡同网段。3 - 如果ARP请求数据包所请求的IP地址对应的本地地址其作用域(scope)为
主机(host),则不回应ARP响应数据包,如果作用域为全局(global)或链路(link),
则回应ARP响应数据包。4~7 - 保留未使用8 - 不回应所有本地的arp请求
方式
- 1、直接修改
arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
- 2、通过
sysctl -w
命令写入
sysctl -w net.ipv4.conf.all.arp_ignore=1
- 3、通过 sysctl 的配置文件 /etc/
sysctl.conf
修改
net.ipv4.conf.all.arp_ignore=1
然后通过命令 sysctl -p
更新配置
参考
https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
https://www.jianshu.com/p/734640384fda
https://blog.csdn.net/bandaoyu/article/details/126669168