-
Notifications
You must be signed in to change notification settings - Fork 259
CLI Guide
- Workflow-oriented CLI usage patterns for daily CSF operations.
- Covers service lifecycle, allow/deny, temporary controls, port management, and diagnostics.
- Emphasizes safe procedures, lockout prevention, and operational context.
| Your intent | Go to |
|---|---|
| Step-by-step workflow with context and warnings (you're here) | This page |
| Quick syntax lookup | Cheatsheet: Commands |
| Config file reference, Include support, comment rules | csf Command Line Options |
csf -h # full command help
man csf # manual pageCSF has two independent components: the firewall rule engine (csf) and the log-scanning daemon (lfd). Most operations require restarting both.
| Goal | Command | Notes |
|---|---|---|
| Enable CSF + LFD | csf -e |
First-time activation or re-enable after disable |
| Disable CSF + LFD | csf -x |
Removes all rules; use for major troubleshooting |
| Start/apply rules | csf -s |
Loads current config into iptables |
| Flush all rules | csf -f |
|
| Restart rules | csf -r |
Reloads CSF only |
| Restart rules + LFD | csf -ra |
Recommended after any config change |
⚠️ Lockout warning.csf -fflushes all firewall rules immediately. On a remote server with no console/IPMI access, this can lock you out. Always ensure you have out-of-band access before using flush on a live server.
When to use -r vs -ra: Use csf -ra after any change to csf.conf or LFD-related settings — it restarts both CSF and LFD so all changes take effect. Use csf -r only when you know the change affects firewall rules alone (e.g., editing csf.allow/csf.deny without config changes).
Advanced restart variants:
-
csf -q— tells LFD to schedule a CSF restart shortly (useful from scripts to avoid overlapping restarts). -
csf -sf— forces a CLI restart regardless of theLFDSTARTsetting.
The core IP management cycle: allow trusted IPs, deny bad actors, search for entries.
Adding entries:
csf -a 203.0.113.10 Trusted admin endpoint
csf -d 198.51.100.25 Abuse sourceAlways include a descriptive comment — comments are timestamped automatically and help future operators understand why the entry exists.
Removing entries:
csf -ar 203.0.113.10 # remove from allow list
csf -dr 198.51.100.25 # remove from deny list
csf -df # clear ALL deny entries (use with caution)Searching: Use csf -g to search across all rules, lists, and iptables chains:
csf -g 203.0.113.10 # find an IP in any list or chain
csf -g 22 # find rules affecting port 22Pro-Tip:
csf -g(grep) is your most powerful diagnostic tool. It searchescsf.allow,csf.deny,csf.ignore, temporary lists, and the live iptables/ipset state simultaneously.
⚠️ Lockout warning.csf -fflushes all firewall rules immediately.csf -r/csf -rareloads them. On a remote server with no console/IPMI access, any error in config or a missing allow-entry can lock you out during these operations. Always verify your own IP is incsf.allowbefore reloading.
Tip: For file-level editing (direct edits to
csf.allow/csf.deny), comment syntax differs from CLI syntax. See csf Command Line Options → Comment and rotation behavior for details.
Temporary blocks are the safest approach during active incidents — they expire automatically, preventing accidental permanent blocks from forgotten entries.
Workflow:
- Apply a temporary deny during investigation:
csf -td 198.51.100.25 1h -d in Brute-force burst - Monitor behavior in
/var/log/lfd.log. - If the threat persists, promote to permanent:
csf -d 198.51.100.25 Confirmed abuse. - If resolved, the temp entry expires on its own — or remove early:
csf -tr 198.51.100.25.
Temporary allow (for emergency maintenance windows):
csf -ta 203.0.113.10 30m -d inout Emergency maintenanceManagement commands:
| Action | Command |
|---|---|
| List all temp entries | csf -t |
| Remove specific temp entry | csf -tr 198.51.100.25 |
| Flush all temp entries | csf -tf |
Best practice: Observe temporary blocks before promoting to permanent. Quick promotion without investigation can mask the real issue or block legitimate traffic.
When adding services that need new ports, use the CLI helpers to modify csf.conf port lists safely:
csf --addport TCP_IN:2215 # add port to TCP_IN
csf --removeport TCP_IN:2215 # remove port from TCP_IN
csf --listports # show current port config
csf -p # list all listening portsAfter port changes, always restart: csf -ra.
Before first use or after kernel/network changes:
perl /etc/csf/csftest.pl # validate netfilter modules and capabilitiesInspecting active rules:
csf -l # list IPv4 iptables rules
csf -l6 # list IPv6 ip6tables rulesLog monitoring:
tail -f /var/log/lfd.log # live LFD activity stream
tail -n 100 /var/log/lfd.log # recent 100 entriesThis is the standard procedure for any CSF configuration change:
-
Validate capabilities — run
csftest.plbefore major policy edits or after kernel changes. - Apply changes — edit config files or use CLI commands.
-
Reload — run
csf -rato restart both CSF and LFD. -
Verify — check
/var/log/lfd.logfor errors or unexpected behavior. - Confirm access — verify your own admin access still works (especially after allow/deny changes).
| Pitfall | Impact | Prevention |
|---|---|---|
Using csf -f remotely without fallback access |
Full lockout — all rules flushed | Always have console/IPMI access before flushing |
| Promoting temporary blocks too quickly | Blocks legitimate traffic | Observe first, then promote to permanent |
| Forgetting LFD restart after config change | Config changes don't take effect | Always use csf -ra, not just csf -r
|
| No comments on manual allow/deny entries | Future operators can't understand why entry exists | Always add a descriptive comment |
| Editing files without restarting | Stale rules remain active | Restart after every file edit |
- Cloudflare controls: CloudFlare
- Cluster operations: LFD Clustering
- Temporary block lifecycle/reporting: Block Reporting
- IPv6 rollout and validation: IPv6 Deployment & Hardening
- External hook scripts: External Pre- and Post- Scripts
- Full command syntax reference: Cheatsheet: Commands
- Config file and Include reference: csf Command Line Options
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