Repository navigation
Deployment Runbooks
Home · Start Here · Configuration Guide
Scenario-specific CSF deployment guides. Each runbook walks through prerequisites, baseline configuration, command sequence, validation, and rollback for a specific server role.
Important: These runbooks are starting points. Final values must match your actual services, threat model, and operational requirements. Always keep
TESTING="1"until access is verified. Command compatibility note: command blocks assume Linux servers with GNUsed. If your environment differs, editcsf.confmanually or adapt commands accordingly. Placeholder note: replace sample values (for example203.0.113.10, domains, and hostnames) before execution.
On this page: At a glance · Runbook 1: Single VPS (Web Only) · Runbook 2: Web + Mail Server · Runbook 3: Behind Cloudflare · Runbook 4: cPanel Host · Runbook 5: Database Server Hardening · Quick-reference config profiles · General rollback principles
Scenario: A standalone VPS running a web server (Nginx or Apache) with SSH access. No mail, no panel.
- Root or sudo access.
- SSH access confirmed from a known IP.
- CSF installed (
bash <(curl -sL https://csf.black.host)). - Kernel module support verified (
perl /etc/csf/csftest.pl).
Open only SSH + HTTP/HTTPS inbound. Restrict outbound to DNS, NTP, HTTP/S, and SSH. No UI. No mail ports.
⚠️ Lockout Warning: Ensure your current IP is allowed (csf -a) before switchingTESTINGto0. If you lose connectivity, use your provider's console to runcsf -x.
# 1. Back up current config
cp /etc/csf/csf.conf /etc/csf/csf.conf.pre-runbook
# 2. Set port policy
sed -i 's/^TCP_IN = .*/TCP_IN = "22,80,443"/' /etc/csf/csf.conf
sed -i 's/^TCP_OUT = .*/TCP_OUT = "22,53,80,443"/' /etc/csf/csf.conf
sed -i 's/^UDP_IN = .*/UDP_IN = ""/' /etc/csf/csf.conf
sed -i 's/^UDP_OUT = .*/UDP_OUT = "53,123"/' /etc/csf/csf.conf
# 3. Keep testing mode on
sed -i 's/^TESTING = .*/TESTING = "1"/' /etc/csf/csf.conf
# 4. Set deny list limits
sed -i 's/^DENY_IP_LIMIT = .*/DENY_IP_LIMIT = "200"/' /etc/csf/csf.conf
sed -i 's/^DENY_TEMP_IP_LIMIT = .*/DENY_TEMP_IP_LIMIT = "200"/' /etc/csf/csf.conf
# 5. Disable UI
sed -i 's/^UI = .*/UI = "0"/' /etc/csf/csf.conf
# 6. Allow your admin IP
csf -a 203.0.113.10 Admin IP - runbook deploy
# 7. Reload
csf -ra-
csf -racompletes without errors. - SSH access from admin IP still works.
-
curl -I http://server-ipreturns expected response. -
csf -g 203.0.113.10shows the allow entry. -
/var/log/lfd.logshows no unexpected blocks. - From an unallowed IP, non-permitted ports are unreachable.
cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
csf -raIf locked out, use provider console: csf -f to flush all rules.
See also: Cheatsheet: Example Configs · Troubleshooting Decision Trees
Scenario: A server running web services plus Exim/Postfix with Dovecot (SMTP, IMAP, POP3). Common on cPanel/shared hosting.
- Root access with verified SSH.
- CSF installed and
csftest.plpassing. - Mail services (Exim/Postfix + Dovecot) running and confirmed.
- DNS MX records pointing to this server.
Open web + all standard mail ports inbound and outbound. Enable login tracking for brute-force defense on mail protocols.
# 1. Back up
cp /etc/csf/csf.conf /etc/csf/csf.conf.pre-runbook
# 2. Port policy — web + mail
sed -i 's/^TCP_IN = .*/TCP_IN = "22,25,80,110,143,443,465,587,993,995"/' /etc/csf/csf.conf
sed -i 's/^TCP_OUT = .*/TCP_OUT = "22,25,53,80,110,143,443,465,587,993,995"/' /etc/csf/csf.conf
sed -i 's/^UDP_IN = .*/UDP_IN = "53"/' /etc/csf/csf.conf
sed -i 's/^UDP_OUT = .*/UDP_OUT = "53,123"/' /etc/csf/csf.conf
# 3. Testing mode
sed -i 's/^TESTING = .*/TESTING = "1"/' /etc/csf/csf.conf
# 4. Enable login tracking (conservative thresholds)
sed -i 's/^LT_POP3D = .*/LT_POP3D = "60"/' /etc/csf/csf.conf
sed -i 's/^LT_IMAPD = .*/LT_IMAPD = "120"/' /etc/csf/csf.conf
# 5. Allow admin IP
csf -a 203.0.113.10 Admin IP - web+mail runbook
# 6. Reload
csf -ra- SSH, HTTP, HTTPS accessible from admin IP.
-
telnet server-ip 25connects (SMTP banner visible). - Mail client connects to IMAP (993) and POP3 (995) with TLS.
-
csf -tshows no unexpected temporary blocks. -
/var/log/lfd.logshows login tracking active. - Outbound mail delivery works (send test email to external address).
cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
csf -raSee also: Cheatsheet: Example Configs · Troubleshooting Decision Trees
Scenario: Web server sits behind Cloudflare reverse proxy. Real visitor IPs appear as Cloudflare edge IPs unless restored.
- CSF installed and
csftest.plpassing. - Cloudflare active on the domain (DNS proxied).
-
mod_remoteip,mod_cloudflare, or equivalent configured to restore real client IPs in web logs. - Cloudflare API credentials available if using the CSF Cloudflare integration.
Allow web ports. Whitelist all Cloudflare edge IP ranges in csf.ignore and csf.allow to prevent accidental blocking of proxy traffic. Optionally enable CSF Cloudflare integration for synchronized block actions.
⚠ Cloudflare IP ranges change periodically. The IP ranges used in this runbook are examples only and may be outdated. Always verify against the authoritative sources before deployment:
Recommended: use the dynamic-fetch alternative shown in the command comments below instead of hardcoded ranges. Consider scheduling periodic re-sync (e.g., weekly cron) to catch upstream changes.
# 1. Back up
cp /etc/csf/csf.conf /etc/csf/csf.conf.pre-runbook
cp /etc/csf/csf.allow /etc/csf/csf.allow.pre-runbook
cp /etc/csf/csf.ignore /etc/csf/csf.ignore.pre-runbook
# 2. Port policy
sed -i 's/^TCP_IN = .*/TCP_IN = "22,80,443"/' /etc/csf/csf.conf
sed -i 's/^TCP_OUT = .*/TCP_OUT = "22,53,80,443"/' /etc/csf/csf.conf
sed -i 's/^UDP_IN = .*/UDP_IN = ""/' /etc/csf/csf.conf
sed -i 's/^UDP_OUT = .*/UDP_OUT = "53,123"/' /etc/csf/csf.conf
# 3. Testing mode
sed -i 's/^TESTING = .*/TESTING = "1"/' /etc/csf/csf.conf
# 4. Add Cloudflare IPv4 ranges to csf.allow and csf.ignore
#
# ⚠ STALENESS WARNING: Cloudflare IP ranges change periodically.
# The ranges below are examples only — verify current ranges before use.
# Always fetch the authoritative list from: https://www.cloudflare.com/ips-v4
#
# Recommended: use a dynamic fetch instead of hardcoded values:
# curl -s https://www.cloudflare.com/ips-v4 | while read ip; do
# grep -q "$ip" /etc/csf/csf.allow 2>/dev/null || echo "$ip # Cloudflare edge" >> /etc/csf/csf.allow
# grep -q "$ip" /etc/csf/csf.ignore 2>/dev/null || echo "$ip # Cloudflare edge" >> /etc/csf/csf.ignore
# done
#
# Example (static — verify current before use):
for ip in 173.245.48.0/20 103.21.244.0/22 103.22.200.0/22 103.31.4.0/22 \
141.101.64.0/18 108.162.192.0/18 190.93.240.0/20 188.114.96.0/20 \
197.234.240.0/22 198.41.128.0/17 162.158.0.0/15 104.16.0.0/13 \
104.24.0.0/14 172.64.0.0/13 131.0.72.0/22; do
grep -q "$ip" /etc/csf/csf.allow 2>/dev/null || echo "$ip # Cloudflare edge" >> /etc/csf/csf.allow
grep -q "$ip" /etc/csf/csf.ignore 2>/dev/null || echo "$ip # Cloudflare edge" >> /etc/csf/csf.ignore
done
# 5. Add Cloudflare IPv6 ranges (same staleness warning applies)
# Authoritative source: https://www.cloudflare.com/ips-v6
for ip in 2400:cb00::/32 2606:4700::/32 2803:f800::/32 2405:b500::/32 \
2405:8100::/32 2a06:98c0::/29 2c0f:f248::/32; do
grep -q "$ip" /etc/csf/csf.allow 2>/dev/null || echo "$ip # Cloudflare edge IPv6" >> /etc/csf/csf.allow
grep -q "$ip" /etc/csf/csf.ignore 2>/dev/null || echo "$ip # Cloudflare edge IPv6" >> /etc/csf/csf.ignore
done
# 6. Allow admin IP
csf -a 203.0.113.10 Admin IP - cloudflare runbook
# 7. Reload
csf -ra- SSH still accessible from admin IP.
- Website loads through Cloudflare (proxied DNS).
-
csf -gon a Cloudflare edge IP shows it in the allow list. - Web logs show real visitor IPs (not Cloudflare edges) — confirms
mod_remoteipis working. -
/var/log/lfd.logshows no blocks on Cloudflare IP ranges. - LFD login tracking triggers use real client IPs, not edge IPs.
cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
cp /etc/csf/csf.allow.pre-runbook /etc/csf/csf.allow
cp /etc/csf/csf.ignore.pre-runbook /etc/csf/csf.ignore
csf -raSee also: CloudFlare · Cheatsheet: Example Configs · Troubleshooting Decision Trees
Scenario: A cPanel/WHM server with standard services (web, mail, DNS, FTP, cPanel ports).
- Root WHM access.
- CSF installed via the standard cPanel method (WHM > Plugins, or CLI installer).
-
csftest.plpassing. - Familiarity with cPanel's port requirements.
Open standard cPanel service ports. Enable CSF UI through WHM. Tune login tracking and process tracking for the cPanel service profile.
# 1. Back up
cp /etc/csf/csf.conf /etc/csf/csf.conf.pre-runbook
# 2. cPanel-standard port policy
sed -i 's/^TCP_IN = .*/TCP_IN = "22,25,53,80,110,143,443,465,587,993,995,2077,2078,2082,2083,2086,2087,2095,2096"/' /etc/csf/csf.conf
sed -i 's/^TCP_OUT = .*/TCP_OUT = "22,25,37,43,53,80,110,113,443,465,587,873,993,995,2077,2078,2082,2083,2086,2087,2089,2095,2096"/' /etc/csf/csf.conf
sed -i 's/^UDP_IN = .*/UDP_IN = "53"/' /etc/csf/csf.conf
sed -i 's/^UDP_OUT = .*/UDP_OUT = "53,113,123"/' /etc/csf/csf.conf
# 3. Testing mode
sed -i 's/^TESTING = .*/TESTING = "1"/' /etc/csf/csf.conf
# 4. FTP passive port range (match Pure-FTPd config)
sed -i 's/^TCP_IN = "\(.*\)"/TCP_IN = "\1,49152:65534"/' /etc/csf/csf.conf
# 5. Add process tracking ignores for cPanel services
cat >> /etc/csf/csf.pignore << 'PEOF'
exe:/usr/local/cpanel/3rdparty/bin/dnsadmin
exe:/usr/local/cpanel/3rdparty/perl/536/bin/perl
cmd:lfd - sleeping
PEOF
# 6. Allow admin IP
csf -a 203.0.113.10 Admin IP - cpanel runbook
# 7. Reload
csf -ra- SSH access works from admin IP.
- WHM (2087) and cPanel (2083) accessible via HTTPS.
- Webmail (2096) accessible.
- Mail client connects on IMAP/POP3/SMTP ports.
- FTP passive connections work (test with an FTP client).
-
perl /etc/csf/csftest.plstill passes. -
/var/log/lfd.logshows clean startup, no false blocks on cPanel services.
cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
csf -raSee also: A note about FTP Connection Issues · Cheatsheet: Example Configs · Troubleshooting Decision Trees
Scenario: A dedicated database server (MySQL/MariaDB or PostgreSQL) that only accepts connections from known application servers. No web, no mail.
- Root or sudo access with verified SSH.
- CSF installed and
csftest.plpassing. - Known application server IPs that need database access.
- Database listening port confirmed (default 3306 for MySQL, 5432 for PostgreSQL).
Minimal attack surface: SSH + database port only, with database port restricted to specific source IPs via advanced allow filters. No web, mail, or UI ports.
# 1. Back up
cp /etc/csf/csf.conf /etc/csf/csf.conf.pre-runbook
cp /etc/csf/csf.allow /etc/csf/csf.allow.pre-runbook
# 2. Minimal port policy — SSH only in global open ports
sed -i 's/^TCP_IN = .*/TCP_IN = "22"/' /etc/csf/csf.conf
sed -i 's/^TCP_OUT = .*/TCP_OUT = "22,53,80,443"/' /etc/csf/csf.conf
sed -i 's/^UDP_IN = .*/UDP_IN = ""/' /etc/csf/csf.conf
sed -i 's/^UDP_OUT = .*/UDP_OUT = "53,123"/' /etc/csf/csf.conf
# 3. Testing mode
sed -i 's/^TESTING = .*/TESTING = "1"/' /etc/csf/csf.conf
# 4. Disable UI
sed -i 's/^UI = .*/UI = "0"/' /etc/csf/csf.conf
# 5. Allow database port ONLY from specific app servers (advanced filter)
# MySQL example — repeat for each app server IP:
echo "tcp|in|d=3306|s=10.0.1.10 # App server 1 - MySQL" >> /etc/csf/csf.allow
echo "tcp|in|d=3306|s=10.0.1.11 # App server 2 - MySQL" >> /etc/csf/csf.allow
# For PostgreSQL, replace 3306 with 5432:
# echo "tcp|in|d=5432|s=10.0.1.10 # App server 1 - PostgreSQL" >> /etc/csf/csf.allow
# 6. Allow admin IP
csf -a 203.0.113.10 Admin IP - database runbook
# 7. Reload
csf -ra- SSH access works from admin IP.
- Database connection succeeds from allowed app server IPs.
- Database connection is refused from any other IP.
-
csf -g 10.0.1.10shows the advanced allow filter entry. - No web or mail ports respond to external probes.
-
/var/log/lfd.logshows no unexpected blocks on app server IPs.
cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
cp /etc/csf/csf.allow.pre-runbook /etc/csf/csf.allow
csf -raSee also: Advanced Allow/Deny Filters · Cheatsheet: Example Configs · Troubleshooting Decision Trees
For condensed csf.conf starter templates by server role (without the full step-by-step walkthrough), see Cheatsheet: Example Configs. The profiles there map directly to these runbooks:
| Runbook | Matching config profile |
|---|---|
| Runbook 1: Single VPS | Profile A: Minimal web node |
| Runbook 2: Web + Mail | Profile B: Web + mail node |
| Runbook 4: cPanel Host | — (cPanel-specific; see runbook details) |
| Runbook 5: Database Server | Profile D: Database server |
- Always back up
csf.conf,csf.allow,csf.deny, andcsf.ignorebefore changes. - Keep
TESTING="1"until access is fully verified — it auto-flushes rules after 5 minutes if you lose access. - If locked out entirely, use provider console/IPMI and run
csf -fto flush all rules. - Restore the backup config and
csf -rato return to the previous state.
See also: Troubleshooting & Recovery · Troubleshooting Decision Trees
Last reviewed: 2026-02-27
- Security Features Guide
- Cloud & Container Hardening
- Automation & IaC
- IPv6 Deployment & Hardening
- IP Block Lists
- Reference Map
- Introduction
- csf Principles
- lfd Principles
- csf CLI Options
- lfd CLI Options
- Login Tracking
- Regex Custom Cookbook
- Script Email Alerts
- Process Tracking
- Directory Watching
- Advanced Filters
- Multiple Ethernet
- Generic Linux
- FTP Issues
- Messenger Service
- Block Reporting
- Port Flood
- Pre/Post Scripts
- Port Knocking
- Connection Limit
- Port/IP Redirect
- Integrated UI
- RESTRICT_SYSLOG
- Exim SMTP AUTH
- UI Skinning
- InterWorx
- CentOS Web Panel