How to install and configure the CSF Firewall on Virtualmin

How to install and configure the CSF Firewall on Virtualmin

Introduction

Config Server Firewall (CSF) is a free, open-source, and advanced type of Firewall. It supports most of the Linux distribution and Linux-based VPS. CSF includes security features such as intrusion/flood/login detections, and It can easily integrate with cPanel, Webmin, and other panels. Learn How to configure the CSF Firewall on Virtualmin

CSF can easily recognize many attacks on many services such as brute force attacks on login, port scans, SYN floods. It is configured to temporarily block clients which are detected as suspicious.

It also plays an important role to harden your server security. We will go through this together now and install and configure CSF.

Prerequisite

  • Linux Operating System (Ubuntu, CentOS)
  • Virtualmin on the server

Installing and Configuring CSF in Linux

Before starting the installation, Perl and libwww is a prerequisite to install and support the CSF on any distributions (Ubuntu, CentOS, OpenSUSE, Debian, RHEL).

Perl and libwww are installed by default in some OS. If you face any error regarding these packages, install these packages with the help of the below command.

  • Install Perl and libwww Package

For CentOS

yum install perl-libwww-perl

For Ubuntu

apt install libwww-perl
  • Install Wget package

For CentOS

yum install wget

For Ubuntu

apt install wget

Download CSF

  • Change your current working directory
cd /usr/src
  • Download the CSF file
wget https://download.configserver.com/csf.tgz
  • Extract the CSF tar file
 tar xzf csf.tgz
  • Enter in the extract file
cd csf

Run the CSF Installation Script

Script will check and install all the required dependencies and create the necessary directory structure

  • Run the Installation Script
sh install.sh
  • Check the Configuration
perl /usr/local/csf/bin/csftest.pl

You will see the following output for the above command is as follows.

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

Disable Firewall

There is a default Firewall in most distributions. You need to disable the firewall if running and configure CSF.

  • Stop the Firewall.
systemctl stop firewalld
  • To disable the firewall.
systemctl disable firewalld

Configure CSF with Virtualmin

  • Now, Login in to the Virtualmin Panel with Browser.
https://server_ip_address:10000
  • Switch to the Webmin Panel
How to install and configure Config Server Firewall
  • Click on Webmin Option
ConfigServer Security & Firewall
  • Now Click on Webmin Configuration
How to Install and Configure CSF (Config Server Firewall) on
  • Click on Webmin Module
Install CSF Firewall with Virtualmin Module
  • Select the CSF module from the server
How we configure CSF firewall in Webmin and fix related errors

After installation of CSF from cmd, it will create a file named csfwebmin.tgz at ” /usr/local/csf “. You need to select the file. It will create a configuration with Virtualmin.

  • Switch to Virtualmin and click on ConfigServer Security & Firewall
CSF Integration/Administration | Virtualmin
  • Click on setting Button to Set up the CSF Firewall.
Install CSF Firewall Virtualmin Centos7
  • Always remember that TESTING must be ON till you have tested all the configuration. Also test most important port such as SSH port (22), FTP port (21), Webmin Port (10000), Usermin Port (20000).
    If you have not turned the Testing ON, if any unknown things happens then you can loose access from the server.
configure the CSF Firewall on Virtualmin
  • Allow all the port which are required, Like SSH port (22), FTP port (21), Webmin Port (10000), Usermin Port (20000). Click on Save button present at the bottom.
Install CSF Firewall Virtualmin Centos7
  • Click on Firewall Enable to enable the CSF Firewall and then Click on Firewall Restart.
Install CSF Firewall Virtualmin Centos7

Remove CSF Firewall

To remove CSF Firewall completely from the server run the uninstall.sh script located in /etc/csf/uninstall.sh directory.

  • Change your working directory
cd /etc/csf/
  • Run Uninstall script
sh uninstall.sh

The above command will remove the CSF Firewall from the server, And all the files and folders created by CSF.

Conclusion

In this tutorial, we have learned how to install, configure and use the CSF Firewall with the Virtualmin. It’s quite easy to integrate CSF with Virtualmin, as we have already seen above with screenshots. You can try to install CSF on your own server. Configure and tweak the CSF as per your requirement.

If you guys have any queries related to this configure the CSF Firewall on Virtualmin tutorial, let me know in the comments.