Install and Configure CSF Firewall on AlmaLinux 8

In this article, we want to teach you to Install and Configure CSF Firewall on AlmaLinux 8.

Config Server Firewall (or CSF) is a free and advanced firewall for most Linux distributions and Linux-based VPS. In addition to the basic functionality of a firewall – filtering packets – CSF includes other security features, such as login/intrusion/flood detections.

Comprehensive Guide To Install and Configure CSF Firewall on AlmaLinux 8

Before you start to install CSF on AlmaLinux 8, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with AlmaLinux 8.

Now you can follow the steps below to install the CSF firewall on your server.

Step 1 – Install Required Dependencies for CSF on AlmaLinux 8

First, you need to update your local package index with the command below:

sudo dnf update -y

Then, you need to install some dependencies on your AlmaLinux 8 with the following command:

sudo dnf install perl perl-libwww-perl perl-Math-BigInt wget -y

Next, switch to your src directory:

cd /usr/src

Step 2 – Download CSF Installer on AlmaLinux 8

At this point, use the wget command to download the CSF installer script on AlmaLinux 8:

sudo wget https://download.configserver.com/csf.tgz

Extract your downloaded file with the following command:

sudo tar xzf csf.tgz

Move to your CSF directory:

cd csf

Step 3 – Run CSF Installer Script

Finally, run the CSF installer script with the following command:

sudo sh install.sh

When your installation is completed, test that you have required iptables modules:

sudo perl /usr/local/csf/bin/csftest.pl

In your output you will see:

Output
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

Step 4 – Configure CSF on AlmaLinux 8

At this point, that you have CSF installed on your server, you need to edit the CSF configuration file.

Open the file with your favorite text editor, we use vi:

sudo vi /etc/csf/csf.conf

Find the Testing line and change its value to 0.

TESTING = "0"

When you are done, save and close the file.

Step 5 – Start and Enable CSF and LFD Services

Now use the following commands to start and enable the CSF and LFD on AlmaLinux 8:

#sudo systemctl restart csf && sudo systemctl restart lfd
#sudo systemctl enable csf && sudo systemctl enable lfd

Verify that your CSF and LFD are active and running on your server with the commands below:

sudo systemctl status csf && sudo systemctl status lfd
Output
csf.service - ConfigServer Firewall & Security - csf
Loaded: loaded (/usr/lib/systemd/system/csf.service; enabled; vendor preset:>
Active: active (exited) since Wed 2022-01-26 08:27:52 EST; 19s ago
Main PID: 91673 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 11409)
Memory: 0B
CGroup: /system.slice/csf.service
Output
lfd.service - ConfigServer Firewall & Security - lfd
Loaded: loaded (/usr/lib/systemd/system/lfd.service; enabled; vendor preset:>
Active: active (running) since Wed 2022-01-26 08:27:53 EST; 37s ago
Main PID: 91861 (lfd - sleeping)
Tasks: 1 (limit: 11409)
Memory: 118.8M
CGroup: /system.slice/lfd.service
└─91861 lfd - sleeping

You can check your CSF firewall version on AlmaLinux 8 with the command below:

csf -v
Output
csf: v14.15 (generic)

Step 6 – Allow and Deny Incoming Connections with CSF

If you want to allow the incoming connection from an IP address, you can use the following syntax:

csf -a [IP Address]

Otherwise, if you want to deny the incoming connection from an IP address, you can use the following syntax:

csf -d [IP Address]

Step 7 – Uninstall CSF From AlmaLinux 8

Also, if you want to uninstall the CSF firewall from your AlmaLinux 8, you can use the following command:

# cd /etc/csf
# sh uninstall.sh

Conclusion

CSF is able to recognize many attacks, such as port scans, SYN floods, and login brute force attacks on many services. It is configured to temporarily block clients who are detected to be attacking the cloud server.

At this point, you learn to set up and configure the CSF firewall on AlmaLinux 8.

Hope you enjoy it.

May you will be interested in these articles:

Install and Configure Django on AlmaLinux 8

Install and Configure Zabbix on AlmaLinux 8

How To Install Lighttpd on AlmaLinux 8

Install and Configure phpMyAdmin on AlmaLinux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!