How to Install the CSF Firewall
CSF (ConfigServer Security and Firewall) is a complete firewall for Linux servers. Besides port management, the accompanying LFD service automatically blocks IP addresses after failed login attempts. CSF works on Ubuntu, Debian and AlmaLinux and is prepared for DirectAdmin and cPanel by default. Since the original developer stopped, CSF is developed further as open source on GitHub.
Step 1: install the required packages
On Ubuntu and Debian:
apt update
apt install -y perl wget ipset libcrypt-ssleay-perl libio-socket-inet6-perl libio-socket-ssl-perl libnet-libidn-perl libsocket6-perl libwww-perl On AlmaLinux:
dnf install -y perl wget ipset perl-IO-Socket-INET6 perl-IO-Socket-SSL perl-libwww-perl perl-Net-LibIDN2 perl-Net-SSLeay perl-Socket6 Step 2: download and install CSF
cd /usr/src
wget https://download.configserver.dev/csf.tgz
tar -xzf csf.tgz
cd csf
perl csftest.pl
sh install.sh The test must end with the message that CSF works on this server. Only download CSF via the official source on GitHub.
Step 3: disable other firewalls
CSF manages the firewall itself. So disable UFW or firewalld:
ufw disable
systemctl disable --now firewalld Step 4: set the ports
Open the configuration file and check which ports are open at TCP_IN and TCP_OUT. If you changed the SSH port, add it:
nano /etc/csf/csf.conf TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995"
TCP_OUT = "20,21,22,25,53,80,110,113,443,587" Step 5: disable test mode
After installation CSF is in test mode. If everything works and you can still log in, set TESTING to 0 in the same file and restart CSF and LFD:
TESTING = "0" csf -ra
systemctl enable --now lfd Useful CSF commands
csf -a IP-ADRESadds an IP address to the allow list.csf -d IP-ADRESblocks an IP address.csf -dr IP-ADRESlifts a block.csf -g IP-ADRESsearches for an IP address in all rules.csf -rarestarts CSF and LFD after a change.Locked out?
If you can no longer log in, use the noVNC console in the client area and add your IP address to the allow list with csf -a JOUW-IP.
Related articles
Rent a Linux VPS with root access
Ubuntu, Debian or AlmaLinux with full root access via SSH, enterprise Ceph storage with high availability and hosting in Amsterdam.