CSF (ConfigServer Firewall) is the default firewall stack on most cPanel installations. It writes iptables rules based on its configuration plus its runtime bans from lfd (login failure detection). On a host with country-blocking enabled, IP-set lists, and a long-running lfd accumulating bans, the iptables rule count can grow into the tens of thousands. iptables is O(n) — every packet traverses the rule chain in order — so a large rule count costs CPU on every connection. Most teams set CSF up and never look at the rule count again.
What’s happening
iptables processes packets by walking through a chain of rules until one matches. With 100 rules, this is microseconds; with 50,000 rules (typical of a host that has been banning attackers for years without cleanup), it can be milliseconds per packet. Multiply by thousands of new connections per second, and CSF starts showing up in top as %si (software interrupts).
The biggest contributors:
- Country blocking with many countries can expand to large IP lists.
- Persistent denied IPs (
/etc/csf/csf.deny) accumulate over months. A host that has been online for a year often has 5-20k entries. lfdtemp bans (csf.tempban) recycle quickly but spike under attack.- IP-set lookups are O(1), but the rule that invokes the IP-set still costs.
CSF can use the ipset module (which is hash-based, O(1)) instead of individual rules. This is dramatically faster at large rule counts, but cPanel’s CSF defaults often do not enable it.
How to verify
Current rule count:
iptables -L | wc -l
iptables -L -n | wc -l
iptables -nvL | head -20
A host with normal CSF should have under 1000 rules. Over 10,000 means cleanup is overdue.
CSF deny lists:
wc -l /etc/csf/csf.deny
wc -l /etc/csf/csf.tempban
csf -s | head
Per-rule packet counts to identify hot rules:
iptables -nvL INPUT | sort -k1 -n -r | head -20
ipset use:
ipset list -terse
csf --status | grep -i ipset
Software interrupt CPU:
mpstat -P ALL 1 5
# %soft column shows softirq CPU; high values suggest firewall pressure
The fix
-
Enable ipset in CSF. In
/etc/csf/csf.conf:IPSET = "1" USE_CONNTRACK = "1"Restart CSF. This converts large IP lists to ipset lookups — orders of magnitude faster than rule iteration.
-
Trim long-stale deny entries. Anything banned over 90 days ago is usually no longer relevant (botnets shift IPs):
awk -F'#' '/^[0-9]/ {print $0}' /etc/csf/csf.deny | wc -l # Backup, then prune old entries cp /etc/csf/csf.deny /etc/csf/csf.deny.bak.$(date +%Y%m%d) # Keep only entries banned in the last 90 days (depends on your annotation format) -
Use
CC_DENY(country blocking) only if you need it. Each country can be 1-10k+ rules. If you block 50 countries, you have a lot of rules. Convert to ipset format if you use it. -
Set sensible lfd thresholds. Default
LF_TRIGGER = 5is fine; do not lower it so the temp ban list does not balloon under sustained low-volume attack. -
Cron a periodic cleanup. Weekly: deduplicate
csf.deny, expire entries older than your retention policy, restart CSF cleanly. -
Measure softirq CPU after each change. Should drop. If it does not, the rule processing is not the bottleneck — something else is.
The principle: a firewall that blocks 50,000 IPs by individual iptables rules is doing meaningful work but paying a CPU tax. Convert to ipset and the same protection costs a fraction of the CPU. Stack Harbor tunes CSF as part of managed cPanel operations.