← Back to Blog
DevOps October 14, 2026

Prevent Kernel Panics: Monitor and Tune Conntrack Table Limits Before They Explode

A sudden spike in traffic from a misconfigured client or a DDoS attack can fill your kernel’s connection tracking table. When nf_conntrack hits its maximum limit, the kernel stops tracking new connections and starts dropping packets, leading to intermittent connectivity failures that are notoriously difficult to debug because they often don’t generate clear error logs. This "silent drop" behavior confuses monitoring tools and leaves engineers hunting for phantom network issues when the root cause is a simple resource exhaustion in the kernel.

The 5-minute setup

First, check your current connection usage against the configured maximum to see if you are approaching the limit. The conntrack command line tool is the standard way to inspect this state.

# Check current usage vs. maximum limit
sudo conntrack -S | grep -E 'entries|search'
# Or more directly for human-readable status:
sudo conntrack -L | wc -l
cat /proc/sys/net/netfilter/nf_conntrack_count
cat /proc/sys/net/netfilter/nf_conntrack_max

If nf_conntrack_count is close to nf_conntrack_max, you are in danger. To fix this immediately, increase the maximum allowed connections. This is a runtime change, so it applies immediately but won't persist after a reboot.

# Increase the maximum number of tracked connections (e.g., to 1 million)
sudo sysctl -w net.netfilter.nf_conntrack_max=1048576

To make this permanent, edit /etc/sysctl.d/99-conntrack.conf:

net.netfilter.nf_conntrack_max=1048576
net.netfilter.nf_conntrack_buckets=262144

Then apply the configuration:

sudo sysctl --system

Note: The nf_conntrack_buckets setting controls the hash table size for looking up connections. If you increase nf_conntrack_max significantly, you should also increase nf_conntrack_buckets (typically to max / 4 or max / 8) to prevent performance degradation due to long hash chains.

Why it works

The Linux kernel uses the nf_conntrack subsystem to keep track of all active connections for stateful firewalling (iptables/nftables). This tracking table is stored in kernel memory. When the table fills up, the kernel cannot allocate new tracking entries for new connections. Instead of rejecting the connection gracefully, the kernel often silently drops the initial SYN packets or subsequent packets depending on the firewall rules, causing timeouts and connection resets that look like network instability. By increasing the limit, you provide the kernel with enough headroom to handle traffic spikes without exhausting memory or table slots, preventing these hard-to-diagnose packet drops.

Pro Tip

Add a quick cron job or monitoring check to alert you when usage exceeds 80% of the limit. This gives you time to investigate why the spike is happening (e.g., a misbehaving application, a port scan, or an attack) before the table fills up and traffic starts dropping.

# Simple one-liner to check if conntrack usage is above 80%
current=$(cat /proc/sys/net/netfilter/nf_conntrack_count)
max=$(cat /proc/sys/net/netfilter/nf_conntrack_max)
threshold=$((max * 80 / 100))

if [ "$current" -gt "$threshold" ]; then
    echo "ALERT: Conntrack usage critical: $current / $max" | logger -t conntrack-alert
fi

Integrate this into your existing monitoring stack (Prometheus node_exporter already exposes node_nf_conntrack_entries and node_nf_conntrack_entries_limit metrics, which is the preferred method for production monitoring).