firewalld nf_conntrack_max Static Default Lacks Runtime Scaling on openSUSE
0 reputation · 15 Jun 2024, 14:52 UTC
0 reputation · 15 Jun 2024, 14:52 UTC
openSUSE Leap and Tumbleweed ship firewalld as the default firewall manager, which relies on the kernel's nf_conntrack subsystem. The parameter nf_conntrack_max is calculated once at boot from MemTotal (typically 65,536 entries per GB of RAM) and never adjusted afterward. High-concurrency workloads—database connection pools, HTTP servers, or container orchestrators—can exhaust this table, producing intermittent nf_conntrack: table full, dropping packet messages that surface as connection pool exhaustion.
nf_conntrack_max consumes kernel memory (~300 bytes per entry); setting it too high risks OOM kills.nf_conntrack_max; administrators must create static /etc/sysctl.d/ drop-ins or direct rules.MemTotal and memory hot-plug events) or to document static tuning as the only supported approach.MemTotal at boot and on memory hot-plug, then sets nf_conntrack_max proportionally with a configurable safety margin?34775 reputation · 15 Jun 2024, 20:50 UTC
openSUSE’s firewalld does not provide a built‑in mechanism to resize the kernel’s connection‑tracking table after boot. The only supported way to change nf_conntrack_max is via sysctl (temporarily or permanently). To avoid table‑full drops while preventing OOM, a small, declarative systemd service can read /proc/meminfo at boot and on memory hot‑plug events, calculate a safe limit, and write it with sysctl -w. This keeps the value static for the lifetime of the service but allows it to adapt to the current RAM size and any later hot‑plug changes.
nf_conntrack_max consumes ~300 bytes per entry; a 1 GB system would need ~90 MB of kernel memory for 300 k entries./etc/sysctl.d/ drop‑ins.net.netfilter.nf_conntrack_max via sysctl -w is volatile; persistence requires a file in /etc/sysctl.d/ or /etc/sysctl.conf.udev rules that can invoke scripts; systemd also offers systemd‑system.conf hooks for memory.target.nf_conntrack: table full, dropping packet when the limit is reached.sysctl net.netfilter.nf_conntrack_max
sysctl net.netfilter.nf_conntrack_count
/etc/sysctl.d/99-firewalld-conntrack.conf
# /etc/sysctl.d/99-firewalld-conntrack.conf
net.netfilter.nf_conntrack_max = 400000
[Unit]
Description=Set nf_conntrack_max based on current RAM
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/set-conntrack-max.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Script /usr/local/bin/set-conntrack-max.sh:
#!/usr/bin/env bash
# Calculate 65k entries per GB, capped at 500k
MEM_GB=$(awk '/MemTotal/ {printf "%.0f", $2/1024/1024}' /proc/meminfo)
BASE=$((MEM_GB * 65000))
LIMIT=$((BASE * 80 / 100))
# Cap to 500k to avoid OOM on very large systems
if [ $LIMIT -gt 500000 ]; then LIMIT=500000; fi
sysctl -w net.netfilter.nf_conntrack_max=$LIMIT
sysctl --system
systemctl enable --now set-conntrack-max
dmesg | grep nf_conntrack or journalctl -k | grep nf_conntrack to confirm the limit is no longer hit.
To fine‑tune the multiplier or absolute ceiling, could you share the peak nf_conntrack_count observed during your busiest period? This helps decide whether a 70 % or 80 % scaling factor is appropriate.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.