When a cPanel server sits behind Cloudflare, its firewall has to trust Cloudflare’s edge, the proxy servers your visitors actually connect through. On most cPanel servers that firewall is CSF (ConfigServer Security & Firewall). Its companion LFD (Login Failure Daemon) watches the logs and bans addresses that misbehave. The edge needs two things from them. It must be allowed to reach your web ports, and LFD must never ban it, because thousands of your visitors share each edge address.
The safe way to do both is to add Cloudflare’s ranges to /etc/csf/csf.allow with entries limited to ports 80 and 443. A bare IP there would open every port, SSH included. The same ranges go in /etc/csf/csf.ignore so LFD leaves them alone. Both files accept Include lines, so a small generated file and a weekly cron job keep everything current.
What’s happening
CSF and LFD play different roles and need different entries. csf.allow feeds iptables: an entry there admits traffic, and a bare IP or CIDR admits it on every port, sailing past all your port blocks. The advanced syntax (tcp|in|d=443|s=range) scopes the permission to a protocol, direction, and destination port — for Cloudflare, ports 80 and 443, and nothing else, because the edge never legitimately connects to SSH, SMTP, or FTP.
csf.ignore feeds LFD, the log-watching daemon that turns Apache and ModSecurity noise into bans. Behind a proxy, per-IP hit counts aggregate entire cities of visitors onto single edge addresses, and sooner or later LFD’s thresholds fire and it bans one — after which Cloudflare serves 522 errors to whoever routes through that address while every other path works. An ignore entry tells LFD those source addresses are infrastructure, not clients.
The ranges themselves change rarely — but they change. Cloudflare publishes the current list at cloudflare.com/ips, with machine-readable endpoints at /ips-v4 and /ips-v6. A hand-pasted list from a 2019 forum thread is how servers end up half-trusting the edge.
What to check first
Look at what is already in place: stale hand-added entries, bare-IP allows from previous admins, and — the live-fire symptom — edge addresses already sitting in the deny list. Overlapping old and new entries make later debugging miserable, so inventory before adding.
How to verify
# What does CSF currently know about a Cloudflare edge IP?
csf -g 172.70.10.10
# Any existing Cloudflare references in the config files?
grep -ri cloudflare /etc/csf/csf.allow /etc/csf/csf.ignore /etc/csf/csf.deny
# Has LFD been banning edge addresses?
grep -iE "blocked|modsec" /var/log/lfd.log | tail -20
csf -g prints any matching allow, deny, or temporary-ban rule for the address — the single most useful command in this whole area. Edge ranges showing up in csf.deny or csf.tempban confirm LFD has been shooting at the proxy.
The fix
- Generate the lists instead of pasting them. Create
/etc/cron.weekly/cloudflare-csf-refresh(mode 0755):
#!/bin/sh
# Refresh Cloudflare ranges for CSF/LFD
TMP=$(mktemp) || exit 1
curl -fsS https://www.cloudflare.com/ips-v4 -o "$TMP" || exit 1
echo "" >> "$TMP"
curl -fsS https://www.cloudflare.com/ips-v6 >> "$TMP" || exit 1
# Port-scoped allow entries: web ports only
awk 'NF { print "tcp|in|d=80|s=" $1; print "tcp|in|d=443|s=" $1 }' \
"$TMP" > /etc/csf/cloudflare_allow.txt
# Plain CIDRs for the LFD ignore list
awk 'NF' "$TMP" > /etc/csf/cloudflare_ignore.txt
rm -f "$TMP"
csf -ra
- Reference the generated files with Include lines. Add to
/etc/csf/csf.allow:
Include /etc/csf/cloudflare_allow.txt
And to /etc/csf/csf.ignore:
Include /etc/csf/cloudflare_ignore.txt
- Run the script once by hand and confirm the reload was clean:
csf -raoutput should end without errors, andcsf -g 172.70.10.10should now show the port-scoped allow. - Clear any existing edge bans.
csf -dr <ip>for permanent entries,csf -tr <ip>for temporary ones. LFD will not re-add them once the ignore list is live. - Decide whether you are allowing or locking down. The entries above admit Cloudflare; they do not exclude anyone else. If the goal is an origin reachable only through the proxy, additionally remove 80 and 443 from
TCP_INin/etc/csf/csf.confand restart — the full context for that decision is in origin IP exposure on cPanel servers. - Optionally, wire LFD to block attackers at the edge. CSF ships an optional Cloudflare integration (
CF_ENABLEincsf.conf) that lets LFD push blocks of real client IPs to Cloudflare’s firewall via API for configured domains — useful once mod_remoteip is restoring those client IPs in your logs. Treat it as a refinement, not a requirement.
When this fix is wrong
If the server does not actually sit behind Cloudflare — the zone is DNS-only — none of this applies, and allow entries for ranges that never connect are just clutter. If another CDN or load balancer fronts some sites, its ranges need the same treatment and Cloudflare’s list does nothing for it. And if you were reaching for csf.ignore to stop LFD from banning your own office IP, that is what a scoped entry in csf.allow plus csf.ignore for the single address is for — do not widen infrastructure lists to solve a personal-access problem. A server that has locked everyone out entirely is a different emergency: see recovering when CSF locked the world out.
Common mistakes
Bare CIDR lines in csf.allow, granting the entire Cloudflare network access to every port — including SSH — and remember that arbitrary customers’ Workers egress from those same ranges. Allowlisting the edge for mail ports “just in case” — Cloudflare never initiates SMTP to you. Pasting ranges once and never refreshing. Adding ranges to csf.ignore only, then wondering why a lockdown config still blocks the proxy (ignore prevents bans; it does not open ports). Editing the generated files by hand so the next cron run silently reverts your change.
Prevention
Let the cron own the lists and keep humans out of the generated files. After each quarterly review, run csf -g against one address from each newly published range and diff /etc/csf/cloudflare_allow.txt against the live list at cloudflare.com/ips. Pair this firewall-side list with the Apache-side trusted-proxy list so both refresh from the same source on the same schedule.
Running Cloudflare in front of cPanel/WHM is a stack Stack Harbor operates daily as an official cPanel NOC partner — cPanel/WHM management covers the DNS, mail, SSL, and firewall plumbing, and you can start a conversation any time.