Skip to content

Deployment Runbooks

Heisenbug edited this page Mar 5, 2026 · 1 revision

Home · Start Here · Configuration Guide

At a glance

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 GNU sed. If your environment differs, edit csf.conf manually or adapt commands accordingly. Placeholder note: replace sample values (for example 203.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

Runbook 1: Single VPS (Web Only)

Scenario: A standalone VPS running a web server (Nginx or Apache) with SSH access. No mail, no panel.

Prerequisites

  • 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).

Baseline config intent

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 switching TESTING to 0. If you lose connectivity, use your provider's console to run csf -x.

Command sequence

# 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

Validation checklist

  • csf -ra completes without errors.
  • SSH access from admin IP still works.
  • curl -I http://server-ip returns expected response.
  • csf -g 203.0.113.10 shows the allow entry.
  • /var/log/lfd.log shows no unexpected blocks.
  • From an unallowed IP, non-permitted ports are unreachable.

Rollback

cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
csf -ra

If locked out, use provider console: csf -f to flush all rules.

See also: Cheatsheet: Example Configs · Troubleshooting Decision Trees


Runbook 2: Web + Mail Server

Scenario: A server running web services plus Exim/Postfix with Dovecot (SMTP, IMAP, POP3). Common on cPanel/shared hosting.

Prerequisites

  • Root access with verified SSH.
  • CSF installed and csftest.pl passing.
  • Mail services (Exim/Postfix + Dovecot) running and confirmed.
  • DNS MX records pointing to this server.

Baseline config intent

Open web + all standard mail ports inbound and outbound. Enable login tracking for brute-force defense on mail protocols.

Command sequence

# 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

Validation checklist

  • SSH, HTTP, HTTPS accessible from admin IP.
  • telnet server-ip 25 connects (SMTP banner visible).
  • Mail client connects to IMAP (993) and POP3 (995) with TLS.
  • csf -t shows no unexpected temporary blocks.
  • /var/log/lfd.log shows login tracking active.
  • Outbound mail delivery works (send test email to external address).

Rollback

cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
csf -ra

See also: Cheatsheet: Example Configs · Troubleshooting Decision Trees


Runbook 3: Behind Cloudflare

Scenario: Web server sits behind Cloudflare reverse proxy. Real visitor IPs appear as Cloudflare edge IPs unless restored.

Prerequisites

  • CSF installed and csftest.pl passing.
  • 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.

Baseline config intent

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.

Command sequence

# 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

Validation checklist

  • SSH still accessible from admin IP.
  • Website loads through Cloudflare (proxied DNS).
  • csf -g on a Cloudflare edge IP shows it in the allow list.
  • Web logs show real visitor IPs (not Cloudflare edges) — confirms mod_remoteip is working.
  • /var/log/lfd.log shows no blocks on Cloudflare IP ranges.
  • LFD login tracking triggers use real client IPs, not edge IPs.

Rollback

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 -ra

See also: CloudFlare · Cheatsheet: Example Configs · Troubleshooting Decision Trees


Runbook 4: cPanel Host

Scenario: A cPanel/WHM server with standard services (web, mail, DNS, FTP, cPanel ports).

Prerequisites

  • Root WHM access.
  • CSF installed via the standard cPanel method (WHM > Plugins, or CLI installer).
  • csftest.pl passing.
  • Familiarity with cPanel's port requirements.

Baseline config intent

Open standard cPanel service ports. Enable CSF UI through WHM. Tune login tracking and process tracking for the cPanel service profile.

Command sequence

# 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

Validation checklist

  • 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.pl still passes.
  • /var/log/lfd.log shows clean startup, no false blocks on cPanel services.

Rollback

cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
csf -ra

See also: A note about FTP Connection Issues · Cheatsheet: Example Configs · Troubleshooting Decision Trees


Runbook 5: Database Server Hardening

Scenario: A dedicated database server (MySQL/MariaDB or PostgreSQL) that only accepts connections from known application servers. No web, no mail.

Prerequisites

  • Root or sudo access with verified SSH.
  • CSF installed and csftest.pl passing.
  • Known application server IPs that need database access.
  • Database listening port confirmed (default 3306 for MySQL, 5432 for PostgreSQL).

Baseline config intent

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.

Command sequence

# 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

Validation checklist

  • 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.10 shows the advanced allow filter entry.
  • No web or mail ports respond to external probes.
  • /var/log/lfd.log shows no unexpected blocks on app server IPs.

Rollback

cp /etc/csf/csf.conf.pre-runbook /etc/csf/csf.conf
cp /etc/csf/csf.allow.pre-runbook /etc/csf/csf.allow
csf -ra

See also: Advanced Allow/Deny Filters · Cheatsheet: Example Configs · Troubleshooting Decision Trees


Quick-reference config profiles

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

General rollback principles

  1. Always back up csf.conf, csf.allow, csf.deny, and csf.ignore before changes.
  2. Keep TESTING="1" until access is fully verified — it auto-flushes rules after 5 minutes if you lose access.
  3. If locked out entirely, use provider console/IPMI and run csf -f to flush all rules.
  4. Restore the backup config and csf -ra to return to the previous state.

See also: Troubleshooting & Recovery · Troubleshooting Decision Trees

Last reviewed: 2026-02-27


← Troubleshooting Decision Trees · FAQ →

Clone this wiki locally