CSF and LFD commands cheat sheet

This cheat sheet brings together the commands and settings of CSF (ConfigServer Security & Firewall) and of LFD, the service that detects failed login attempts and blocks the addresses they come from: starting and stopping, ports, allowing and blocking IP addresses, temporary blocks, csf.conf settings, and the allow and deny files. After the commands, you'll find where CSF stands today, now that the company that developed it has stopped development. You can search for a command, filter by topic, and copy it with one click.

Installing and first checks

  • sudo yum install cpanel-csf

    On a cPanel and WHM server with AlmaLinux, CloudLinux, or Rocky Linux: installs the version maintained by WebPros, the company behind cPanel. On a server without cPanel, the installation fails.

  • sudo apt install cpanel-csf

    Installs the same version on a cPanel and WHM server with Ubuntu.

  • sudo systemctl disable --now firewalld

    Stops firewalld and keeps it from starting with the server. CSF doesn't run alongside firewalld, so turn firewalld off before you enable CSF.

  • sudo ufw disable

    Turns off UFW, for the same reason: only one firewall manager runs on a server.

  • sudo csf -v

    Shows the installed version of CSF.

  • sudo csf -l

    Lists the IPv4 firewall rules that CSF loaded. The csf -l6 command lists the IPv6 rules.

  • sudo csf -p

    Shows the ports the server is listening on and the process behind each one. Handy before you decide which ports to open.

Starting, stopping, and reloading

  • sudo csf -s

    Starts the firewall and loads the rules according to the settings.

  • sudo csf -r

    Reloads the firewall rules. Run it after changing the configuration files.

  • sudo csf -ra

    Reloads CSF and then LFD. After a change to csf.conf, csf.allow, csf.deny, or csf.ignore, reload both.

  • sudo csf -f

    Stops the firewall and flushes the rules. Caution: the server is left unfiltered, and LFD may start CSF again.

  • sudo csf -x

    Disables CSF and LFD together until you enable them again. Caution: the server is left without a firewall.

  • sudo csf -e

    Enables CSF and LFD again after they were disabled with csf -x.

LFD: detecting failed login attempts

  • sudo csf --lfd restart

    Restarts LFD. The start, stop, and status actions work the same way.

  • sudo systemctl restart lfd

    Restarts LFD through systemd. The systemctl status lfd command shows whether the service is running and its latest messages.

  • sudo tail -f /var/log/lfd.log

    Shows the LFD log in real time: blocks, unblocks, and alerts.

  • sudo grep 203.0.113.10 /var/log/lfd.log

    Shows all the log entries for a specific address, for example to find out why it was blocked.

  • sudo csf -lr

    Runs a log scanner report through LFD. The command works only when the LOGSCANNER setting is enabled in csf.conf.

Allowing and blocking IP addresses

  • sudo csf -a 203.0.113.10 office

    Allows an IP address and adds it to the csf.allow file, with an optional comment. You can also write a network in CIDR notation.

  • sudo csf -ar 203.0.113.10

    Removes an address from csf.allow and deletes the rule that allowed it.

  • sudo csf -d 198.51.100.7 spam

    Blocks an IP address and adds it to the csf.deny file, with an optional comment.

  • sudo csf -dr 198.51.100.7

    Unblocks a blocked address and removes it from csf.deny.

  • sudo csf -df

    Unblocks all the addresses in csf.deny and empties the file. Caution: attackers' addresses are unblocked too.

  • sudo csf -g 203.0.113.10

    Searches the IPv4 and IPv6 firewall rules for an address, a network, or a port. This is how you check whether an address is blocked or allowed, and by which rule.

Temporary blocks and allows

  • sudo csf -td 198.51.100.7 1h

    Blocks an address temporarily. The duration is written in seconds, or with h for hours, m for minutes, and d for days. The blocks LFD adds are kept in the same list.

  • sudo csf -td 198.51.100.7 30m -p 22

    Blocks an address temporarily on one port only, here port 22.

  • sudo csf -ta 203.0.113.10 2h -p 22

    Allows an address temporarily, for example SSH access for an outside vendor for two hours. By default, the allow applies to both inbound and outbound traffic.

  • sudo csf -t

    Lists all temporary blocks and allows, with the time left for each one and its comment.

  • sudo csf -tr 198.51.100.7

    Removes an address from the temporary block or allow list. This is how you unblock an address that LFD blocked temporarily.

  • sudo csf -trd 198.51.100.7

    Removes an address from the temporary block list only. The csf -tra command removes an address from the temporary allow list only.

  • sudo csf -tf

    Deletes all temporary blocks and allows.

csf.conf: TESTING mode and ports

  • /etc/csf/csf.conf

    The main configuration file of CSF and LFD. After every change to it, run sudo csf -ra.

  • TESTING = "1"

    TESTING mode, which is on after installation: a cron job flushes the firewall rules every few minutes, so a wrong setting won't lock you out of the server. In this mode, LFD doesn't run.

  • TESTING_INTERVAL = "5"

    Sets how often, in minutes, the cron job flushes the rules in TESTING mode.

  • TESTING = "0"

    Turns off TESTING mode, and only then do the firewall and LFD run permanently. Change it to 0 only after you've made sure the ports you need are open and that you can log in over SSH from a new window, and then run sudo csf -ra.

  • TCP_IN = "22,80,443"

    The inbound TCP ports open to everyone, separated by commas. If SSH runs on a different port, add that port before reloading.

  • TCP_OUT = "22,25,53,80,443"

    The outbound TCP ports the server may connect to, for example for DNS, email, and software updates.

  • UDP_IN = "53"

    The inbound UDP ports. Similarly, UDP_OUT sets the outbound ports, for example 53 for DNS and 123 for NTP.

  • TCP_IN = "22,80,443,30000:35000"

    A port range is written with a colon, for example the FTP port range in Passive mode, where the server opens the data connection on a port from the range.

  • IPV6 = "1"

    Enables the firewall for IPv6 too. The ports are set in separate lists: TCP6_IN, TCP6_OUT, UDP6_IN, and UDP6_OUT.

  • ICMP_IN = "1"

    Allows incoming ping to the server. The value 0 blocks it.

  • DENY_IP_LIMIT = "200"

    The maximum number of addresses in csf.deny. When the list is full, the oldest addresses are removed. DENY_TEMP_IP_LIMIT limits temporary blocks in the same way.

  • RESTRICT_SYSLOG = "3"

    Restricts access to syslog, so log lines can't be forged to trigger a block. This is the value the comments in csf.conf recommend.

csf.conf: LFD settings

  • LF_DAEMON = "1"

    Enables LFD. When the value is 0, none of the settings that start with LF_ take effect.

  • LF_TRIGGER = "0"

    A global threshold for all services. With the value 0, each service uses its own threshold, according to the settings below.

  • LF_SSHD = "5"

    The number of failed SSH login attempts after which the address is blocked. The value 0 turns off detection for the service.

  • LF_SSHD_PERM = "1"

    The block type: 1 is a permanent block, and a value greater than 1 is a temporary block for that many seconds, for example 3600 for one hour.

  • LF_FTPD = "10"

    The threshold for failed FTP attempts. LF_SMTPAUTH (authenticated mail sending), LF_POP3D, and LF_IMAPD (receiving mail) work the same way.

  • LF_HTACCESS = "5"

    The threshold for failed attempts on a password-protected folder with htpasswd.

  • LF_MODSEC = "5"

    Blocks an address that triggers ModSecurity rules again and again.

  • LF_PERMBLOCK = "1"

    Makes the block permanent for an address that was temporarily blocked several times. LF_PERMBLOCK_COUNT sets how many temporary blocks, and LF_PERMBLOCK_INTERVAL within how many seconds.

  • CT_LIMIT = "300"

    Blocks an address that opens more simultaneous connections than the number set. The value 0 turns off the check. A value that's too low may block legitimate users, for example a whole office that connects through one address.

  • LF_ALERT_TO = "admin@example.com"

    The email address LFD sends alerts to. When the field is empty, alerts go to the address in the alert templates.

  • LF_EMAIL_ALERT = "0"

    Turns off the alert for every blocked address. LF_PERMBLOCK_ALERT turns off the alert for permanent blocks in the same way. On a busy server, these alerts are very frequent.

  • LF_SSH_EMAIL_ALERT = "1"

    Sends an alert for every successful SSH login, so you learn about an unexpected login right away.

Allow and deny files

  • /etc/csf/csf.allow

    Addresses and networks that are always allowed through the firewall, one address per line. To add a comment, write a space, a hash sign, and a space after the address.

    Example: 203.0.113.10 # office

  • tcp|in|d=22|s=203.0.113.10

    An advanced line in csf.allow: access to TCP port 22 from one address only. This is how you allow SSH only from the office when port 22 isn't in TCP_IN.

  • /etc/csf/csf.deny

    Addresses and networks that are permanently blocked, in the same format as csf.allow. The permanent blocks LFD adds are written here too.

  • /etc/csf/csf.ignore

    Addresses that LFD will never block. The file doesn't open ports in the firewall; it only prevents blocking. Add the static address you connect to the server from here.

  • /etc/csf/csf.pignore

    Users and programs that LFD's process tracking ignores, in lines that start with exe:, user:, or cmd:.

  • Include /etc/csf/office.allow

    A line in csf.allow or csf.deny that includes another file. Write the full path, with no comment after the file name.

  • sudo csf --profile backup before_change

    Saves a backup of csf.conf before you change the settings, in the /var/lib/csf/backup folder. The backup name is made up of a timestamp and the name you chose.

  • sudo csf --profile list

    Lists the saved backups and profiles of csf.conf, with the full name of each backup.

  • sudo csf --profile diff 1767225600_before_change

    Compares a saved backup with the current settings and shows the differences. Write the full name of the backup, as shown by csf --profile list.

  • sudo csf --profile restore 1767225600_before_change

    Restores csf.conf from a saved backup, by its full name. After restoring, run sudo csf -ra.

Where CSF stands today

Way to the Web Ltd, the company that developed CSF under the ConfigServer name, stopped maintaining and supporting the software on August 31, 2025, and released its code under the GPLv3 license.

  • cPanel and WHM servers: WebPros, the company behind cPanel, maintains its own version of CSF for security and stability updates, in the cpanel-csf package. On servers with automatic updates enabled, the existing CSF is replaced with this version automatically. This version is meant for cPanel and WHM servers only, and installing it on any other server fails.
  • Other servers: since the code was released, community projects on GitHub have continued to develop successor versions of CSF. Before you switch to one of them, check that the project is updated regularly.
  • CSF already installed: the firewall keeps working as usual, and the commands and settings on this page stay the same. The difference is in updates: a version that isn't maintained won't get security fixes anymore, so plan a move to a maintained version or to another firewall.
  • The distribution's firewall: a common alternative is firewalld or UFW, together with fail2ban to block failed login attempts, or direct rules in iptables and nftables.

Before enabling CSF on a remote server

  • One firewall manager: CSF doesn't run alongside firewalld, and UFW manages the same rules too. Before you enable CSF, turn off the previous firewall manager, and when you move from CSF to another firewall, disable CSF with sudo csf -x.
  • Your address: add the static address you connect to the server from to csf.allow and to csf.ignore, so the firewall allows it and LFD doesn't block it.
  • The SSH port: if SSH runs on a port other than 22, add the port to TCP_IN before reloading.
  • TESTING mode until everything works: leave TESTING = "1", keep your current SSH session open, and test logging in from a new window. Only then change it to TESTING = "0" and run sudo csf -ra.

The IP addresses on this page, such as 203.0.113.10 and 198.51.100.7, belong to ranges reserved for documentation, so replace them with your real addresses. The default values in csf.conf, such as the port lists, vary between versions and installations, so check them in the file on your server.

Did you know?

On a Linux VPS, you connect over SSH with full root access, and choose and set up the firewall that fits your server with the commands on this page: ports, allowing and blocking IP addresses, and detecting failed login attempts.

Linux VPS plans

CSF and LFD FAQ

What's the difference between CSF and LFD?

CSF is the firewall itself: it builds the server's filtering rules according to the settings in the csf.conf file, opens the ports you set, and blocks the rest. LFD (Login Failure Daemon) is a service that runs in the background, watches the logs of services such as SSH, FTP, and email, and blocks in CSF any address that goes over the set number of failed attempts. Both components are installed together and managed from the same files in the /etc/csf folder.

Can I keep using CSF?

Yes. CSF that's already installed on a server keeps working as usual, and the commands and settings on this page stay the same. The company that developed CSF stopped maintaining it on August 31, 2025, and released the code under the GPLv3 license, so to keep getting security updates, switch to a maintained version: on cPanel and WHM servers, that's the cpanel-csf package from WebPros, and on other servers, a community successor version. Another alternative is the distribution's firewall, firewalld or UFW, together with fail2ban.

How do I unblock an IP address in CSF?

When the address is permanently blocked, run sudo csf -dr with the address, and it's unblocked and removed from csf.deny. When the address was blocked temporarily, for example by LFD, run sudo csf -tr with the address. If you don't know how the address was blocked, the sudo csf -g command with the address shows which rules it appears in. To keep the address from being blocked again, add it to csf.ignore.

How do I open a port in CSF?

Open the /etc/csf/csf.conf file and add the port number to the TCP_IN list, or to the UDP_IN list for a UDP port. Then run sudo csf -ra to reload CSF and LFD. To open a port to one address only, for example SSH from the office, add a line such as tcp|in|d=22|s=203.0.113.10 to csf.allow, with your own address.

What is TESTING mode, and when do I turn it off?

After installation, CSF runs in TESTING mode, a test mode in which a cron job flushes the firewall rules every few minutes, according to TESTING_INTERVAL. This way, even a wrong setting that blocks access to the server undoes itself within minutes. In this mode, LFD doesn't run. After you've made sure the ports you need are open and that you can log in over SSH from a new window, change it to TESTING = "0" and run sudo csf -ra.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement