解决 Linux 报错 neighbour: arp_cache: neighbor table overflow 丢包
分析 Linux 服务器连接大量容器或外部主机报 neighbor table overflow 根因,提供 gc_thresh1/2/3 内核调优方案。
问题现象
在大规模容器宿主机、网关或高并发服务器上,dmesg 控制台疯狂刷屏如下警告:
[Sun Nov 15 19:00:00 2026] neighbour: arp_cache: neighbor table overflow!
[Sun Nov 15 19:00:00 2026] neighbour: arp_cache: neighbor table overflow!
网络出现严重丢包,无法建立新 TCP 连接,ping 局域网主机偶发出现 Destination Host Unreachable。
触发根因
Linux 内核维护了一个邻居表(Neighbor Table / ARP 缓存表):
- 默认内核参数对 ARP 缓存表的大小限制非常保守:
gc_thresh1=128,gc_thresh2=512,gc_thresh3=1024。 - 当宿主机运行了数百个容器、接入了大型局域网或遭遇 ARP 扫描时,邻居表条目突破了硬上限
gc_thresh3(1024)。内核直接拒绝为新的目标 IP 分配 ARP 条目并强行丢弃报文。
诊断排查步骤
- 查看当前 ARP 缓存表条目数量:
ip neigh show | wc -l
- 查看当前系统配置的三级阈值:
cat /proc/sys/net/ipv4/neigh/default/gc_thresh1
cat /proc/sys/net/ipv4/neigh/default/gc_thresh2
cat /proc/sys/net/ipv4/neigh/default/gc_thresh3
解决步骤与操作命令
步骤一:调大内核 ARP 缓存表三级阈值(持久化配置)
编辑 /etc/sysctl.conf,将表容量扩大至满足数万级并发设备:
sudo bash -c 'cat <<EOF >> /etc/sysctl.conf
# 超过 4096 条时启动软垃圾回收
net.ipv4.neigh.default.gc_thresh1 = 4096
# 超过 8192 条时垃圾回收开始施加背压
net.ipv4.neigh.default.gc_thresh2 = 8192
# 硬上限提升至 16384 条
net.ipv4.neigh.default.gc_thresh3 = 16384
# IPv6 场景同步调大
net.ipv6.neigh.default.gc_thresh1 = 4096
net.ipv6.neigh.default.gc_thresh2 = 8192
net.ipv6.neigh.default.gc_thresh3 = 16384
EOF'
sudo sysctl -p
步骤二:清理过期的失效 ARP 条目
sudo ip -s -s neigh flush all
步骤三:验证与监控
再次查看内核日志:
dmesg | grep -i "neighbor table overflow"
确认刷屏警告彻底绝迹,网络丢包率归零。


