Skip to content

TCP backlog, CSF, and SYN flood behavior on cPanel hosts

When a small SYN flood hits a cPanel host, the kernel TCP backlog and CSF firewall interact in non-obvious ways. Connections get dropped that should not. Here is what to tune.

A SYN flood does not have to be a serious DDoS to cause real harm on a cPanel host. A few thousand SYN packets per second with no completing handshake can fill the SYN backlog, exhaust conntrack slots, or push CSF’s rate-limiting rules over their thresholds — at which point legitimate connections start getting dropped along with the attack traffic. The interaction between the kernel TCP backlog and the CSF firewall is the subtle piece that often goes wrong.

What’s happening

A new TCP connection takes three packets (SYN, SYN-ACK, ACK). The kernel keeps half-open connections (received SYN, sent SYN-ACK, no ACK yet) in the SYN queue, sized by net.ipv4.tcp_max_syn_backlog. When this queue fills, the kernel either drops new SYNs or, if net.ipv4.tcp_syncookies=1, falls back to SYN cookies — a stateless mechanism that lets the handshake complete without storing per-connection state. SYN cookies trade some TCP options away (no scaled windows, no SACK) for resistance to flood attacks.

CSF (ConfigServer Firewall) adds another layer: connection-rate limits via the iptables connlimit and recent modules, plus lfd log-watching for SYN flood signatures. When CSF detects a SYN flood from one IP, it bans the IP. But if the flood comes from many spoofed IPs, CSF cannot ban them all, and the kernel backlog becomes the relevant defense.

How to verify

During or after an event:

ss -s
netstat -s | grep -i syn
dmesg | grep -i 'TCP:.*possible SYN'
cat /proc/net/netstat | grep -i syn

ss -s shows current TCP state counts. Look at “synrecv” count — if it is large and growing, the SYN queue is filling.

Check CSF state:

csf -l | grep -i syn
tail -200 /var/log/lfd.log | grep -i syn
csf -r  # restart and reload

For conntrack pressure:

conntrack -C
cat /proc/sys/net/netfilter/nf_conntrack_max
dmesg | grep 'nf_conntrack: table full'

A full conntrack table mid-attack means legitimate connections from new IPs cannot be tracked — symptoms include “connection timed out” on first visits, working fine on subsequent visits.

The fix

  1. Enable SYN cookies — net.ipv4.tcp_syncookies = 1 in sysctl. This is on by default on most distros but worth confirming. With cookies, a SYN flood does not exhaust the backlog.
  2. Raise the SYN backlog — net.ipv4.tcp_max_syn_backlog = 4096 (or higher). The kernel allocates roughly 4 KB per entry, so 4096 = 16 MB.
  3. Tune net.core.somaxconn — match or exceed tcp_max_syn_backlog. Apps that pass a high backlog to listen() (nginx, php-fpm) need this raised; the kernel silently caps the listen() backlog at somaxconn.
  4. Configure CSF SYNFLOOD rules — in /etc/csf/csf.conf, set SYNFLOOD = "1" and SYNFLOOD_RATE = "100/s". CSF will then use iptables to rate-limit incoming SYNs.
  5. Raise conntrack — net.netfilter.nf_conntrack_max = 524288 so a moderate flood does not fill the table.
  6. Consider connection-tracking exemption for established traffic — for very busy hosts, NOTRACK rules on web traffic can take the entire web port out of conntrack accounting. Advanced; do not apply blindly.

After tuning, simulate a moderate SYN flood with hping3 --flood --rand-source -S -p 80 <host> from a test machine and watch the metrics. Stack Harbor configures the kernel + CSF combo as part of cPanel/WHM management.