Skip to content

fail2ban alongside CSF on cPanel — when it helps, when to skip it

CSF/LFD already does what fail2ban does on a cPanel host. Here is when adding fail2ban earns its keep, and how to keep the two from fighting over the firewall.

The honest first answer is: on a cPanel server running CSF/LFD, you usually do not need fail2ban. They watch the same logs and write to the same iptables. The cases where fail2ban earns its place are narrow — custom application logs that LFD does not natively understand. Treat fail2ban as a supplement, not a replacement.

What’s happening

CSF’s LFD daemon already monitors sshd, cpaneld, webmaild, exim, pure-ftpd, and Dovecot. fail2ban has a richer set of out-of-the-box jails for non-cPanel software (custom Apache locations, Postfix on a non-cPanel server, Nextcloud, custom auth endpoints). On a stock cPanel host, fail2ban duplicates work and adds a second writer to iptables, which makes troubleshooting blocks confusing.

How to verify

systemctl status fail2ban
fail2ban-client status
fail2ban-client status sshd
csf -l | grep -E "fail2ban"
iptables -L f2b-sshd -n 2>/dev/null | head
grep -E "^(jail|chain) " /etc/fail2ban/jail.local 2>/dev/null

If both CSF and fail2ban have rules for SSH, you have duplicate enforcement and one of them is doing nothing useful.

The fix

  1. On stock cPanel, do not install fail2ban. Tune LFD instead — LF_SSHD, LF_FTPD, LF_CPANEL, LF_EXIMSYNTAX. That covers the surfaces cPanel exposes.
  2. If you must run fail2ban for a custom app:
    • Install with the distro package
    • Disable every jail you do not need in /etc/fail2ban/jail.local
    • Keep sshd, cpanel, exim, dovecot jails off — LFD owns those
    • Only enable jails for log files LFD does not understand
  3. Use a separate iptables chain for fail2ban (f2b-* is the default) and leave CSF’s chains alone. Do not have fail2ban write to a CSF chain.
  4. Coordinate whitelists: any management IP whitelisted in CSF must also be in /etc/fail2ban/jail.local’s ignoreip. The two systems do not share allow lists.
  5. Quarterly audit: review fail2ban-client status and csf -td together. If one jail has not banned anyone in 90 days and the other one bans 50/day on the same surface, kill the dormant one.

Stack Harbor evaluates the fail2ban/CSF overlap at takeover under cPanel server management.