Install and Configure CSF (ConfigServer Firewall) on Centos7 64bit

ConfigServer Firewall on Centos7


ConfigServer Firewall, also known as CSF, is a firewall configuration script created to provide better security for your server while giving you an easy to use, advanced interface for managing your firewall settings. CSF configures your server’s firewall to lock down public access to services and only allow certain connections, such as logging in to FTP, checking your email, or loading your websites.

This tutorial is done on a Centos7 64bit server for web services. All the succeeding commands should be executed with root permissions by logging in as root. The server that I have is configured for IPV4, if your server is configured for IPV6 you should protect both IPV4 & IPV6 at the same time.


Some of the features CSF can provide are:

  • Straight-forward SPI iptables firewall script
  • Daemon process that checks for login authentication failures for:
    • Courier imap, Dovecot, uw-imap, Kerio
    • openSSH
    • cPanel, WHM, Webmail (cPanel servers only)
    • Pure-ftpd, vsftpd, Proftpd
    • Mod_security failures (v1 and v2)
    • Exim SMTP AUTH
    • Custom login failures with separate log file and regular expression matching
  • SSH login notification
  • Excessive connection blocking
  • SU login notification
  • Server Security Check
  • IDS (Intrusion Detection System)

...and many more.


We will need the following to be able to successfully setup CSF:
- An CentOS 7 x64 VPS server
- Root Access to the server
- An SSH client (You can download Putty[1] or Bitvise[2] depends on your operating system and liking)

When you have all this ingredients we can now start setting up CSF. Please follow the guide carefully, remember, you can always copy and paste the commands below for ease of installation and configuration.

Installing CSF

To install CSF we will try to update or server first.

sudo yum update

And install the dependencies and CSF itself

sudo yum install wget vim perl-libwww-perl.noarch perl-Time-HiRes
cd /usr/src/

Extract the .tar file and enter the folder.

tar -xzf csf.tgz
cd csf

If all is installed properly you should get the following information.

Don't forget to:
1. Configure the following options in the csf configuration to suite your server: TCP_*, UDP_*
2. Restart csf and lfd
3. Set TESTING to 0 once you're happy with the firewall, lfd will not run until you do so

Adding current SSH session IP address to the csf whitelist in csf.allow:
Adding to csf.allow only while in TESTING mode (not iptables ACCEPT)
*WARNING* TESTING mode is enabled - do not forget to disable it in the configuration

Installation Completed

Now we will check if CSF is really working on this server. We will do a test to verify.

cd /usr/local/csf/bin/

If you see the result as shown below then CSF should function without any problems on your server.

Testing ip_tables/iptable_filter...OK
Testing ipt_LOG...OK
Testing ipt_multiport/xt_multiport...OK
Testing ipt_REJECT...OK
Testing ipt_state/xt_state...OK
Testing ipt_limit/xt_limit...OK
Testing ipt_recent...OK
Testing xt_connlimit...OK
Testing ipt_owner/xt_owner...OK
Testing iptable_nat/ipt_REDIRECT...OK
Testing iptable_nat/ipt_DNAT...OK

RESULT: csf should function on this server

Configuring CSF

CentOS7 has a built in firewall called firewalld. We need to stop and disable it before activating CSF.

systemctl stop firewalld
systemctl disable firewalld

Then we shall go to the CSF configuration file and edit to change testing to production phase. Go to "/etc/csf/" and edit the file "csf.conf".

cd /etc/csf/
nano csf.conf

Change TESTING to 0.


Save and exit the file.
You can now run CSF and LFD by the below commands.

systemctl start csf
systemctl start lfd

Then enable CSF and LFD to be started at boot.

systemctl enable csf
systemctl enable lfd

Basics of CSF

To see list of rules.

csl -l

To restart CSF.

csf -r

Allowing an ip in csf.allow.

csf -a

Will output the following response from CSF:

Adding to csf.allow and iptables ACCEPT...
ACCEPT  all opt -- in !lo out *  ->
ACCEPT  all opt -- in * out !lo  ->
You have new mail in /var/spool/mail/root

Removing an ip from csf.allow.

csf -ar

Will result in:

Removing rule...
ACCEPT  all opt -- in !lo out *  ->
ACCEPT  all opt -- in * out !lo  ->

Denying an ip and adding it to csf.deny.

csf -d

Will result in:

Adding to csf.deny and iptables DROP...
DROP  all opt -- in !lo out *  ->
LOGDROPOUT  all opt -- in * out !lo  ->
You have new mail in /var/spool/mail/root

Removing an ip from csf.deny.

csf -dr

Results in:

Removing rule...
DROP  all opt -- in !lo out *  ->
LOGDROPOUT  all opt -- in * out !lo  ->

Remove all entries in csf.deny.

csf -df

Will output:

csf: all entries removed from csf.deny

Advanced CSF Setup

Let us go back to CSF configuration file.

cd /etc/csf/
nano csf.conf

Blocking or allowing only certain countries from connecting to your server by entering the country code in CC_DENY or CC_ALLOW.


Limit the number of IP's kept in the /etc/csf/csf.deny file.


Enable SYN Flood Protection. This option configures iptables to offer some protection from tcp SYN packet DOS attempts.


Port Flood Protection. This option configures iptables to offer protection from DOS attacks against specific ports.

PORTFLOOD = 22;tcp;5;300,80;tcp;20;1

Means: 5 connections per IP-address per 300 seconds to the ssh server; and 20 connections per IP-address per second to the httpd server

This option allows access from the following countries to specific ports listed in CC_ALLOW_PORTS_TCP and CC_ALLOW_PORTS_UDP.


This option denies access from the following countries to specific ports listed in CC_DENY_PORTS_TCP and CC_DENY_PORTS_UDP

CC_DENY_PORTS_TCP = "22, 327"

Don't Block IP addresses that are in the csf.allow files.


Allow Incoming and Outgoing ICMP.

ICMP_IN = "1"
ICMP_OUT = "1"

Send the Su and SSH Login log by Email.

LF_ALERT_TO = "mymail@mydomain.tld"

CSF is a feature rich firewall application, if configured right it will do excellent to protect your server, make sure you understand most of the setup and you'll be fine and protected.


comments (1)

  • 38116

    - 6 years ago


    I just wanted to "CC_DENY_PORTS_TCP = "22, 327""

    what is meaning of DENY TCP Port 327 ? how this will help?