Config Server Firewall (CSF) is a free and advanced firewall supported by most Linux distributions. In addition to the basic functionality of a firewall (filtering packets) CSF includes other security features, such as login/intrusion/flood detections.
The full list of supported operating systems and features can be found on ConfigServer’s website.
This article covers some useful CSF SSH Command Line Commands, that might be useful, in a “cheat sheet” format.
|csf -s||Start the firewall rules||[email protected][~]# csf -s|
|csf -f||Flush/Stop firewall rules (note: lfd may restart csf)
||[email protected][~]# csf -f|
|csf -r||Restart the firewall rules||[email protected][~]# csf -r|
|csf -a [IP.add.re.ss] [comment]||Allow an IP and add to /etc/csf/csf.allow
||[email protected][~]# csf -a 126.96.36.199 Home IP Address|
|csf -tr [IP.add.re.ss]||Remove an IP from the temporary IP ban or allow list.
||[email protected][~]# csf -tr 188.8.131.52|
|csf -tf||Flush all IPs from the temporary IP entries
||[email protected][~]# csf -tf|
|csf -d [IP.add.re.ss] [comment]||Deny an IP and add to /etc/csf/csf.deny||[email protected][~]# csf -d 184.108.40.206 Blocked This Guy|
|csf -dr [IP.add.re.ss]||Unblock an IP and remove from /etc/csf/csf.deny||[email protected][~]# csf -dr 220.127.116.11|
|csf -df||Remove and unblock all entries in /etc/csf/csf.deny||[email protected][~]# csf -df|
|csf -g [IP.add.re.ss]||Search the iptables and ip6tables rules for a match (e.g. IP, CIDR, Port Number)||[email protected][~]# csf -g 18.104.22.168|
|csf -t||Displays the current list of temporary allow and deny IP entries with their TTL and comment||[email protected][~]# csf -t|
In order to prevent a specific IP from being blocked, even for a temporary deny, you need to list their IP address in the files csf.ignore and csf.allow. The first step is to enable IGNORE_ALLOW in /etc/csf/csf.conf. The value for IGNORE_ALLOW will appear as “0”, you will need to adjust it to “1” and restart csf and lfd.
This will allow lfd to reference csf.ignore. If you add an IP address to csf.ignore, the IP address will no longer be checked by lfd and failed login attempts will not trigger temporary denies.
CSF is a very powerful tool, worth exploring, to take advantage of all the security measures it has to offer. These are only a few of the most used commands, but it is recommended that you delve deep into all the settings inside csf.conf in order to extract the most out of this piece of software.