{"id":55108,"date":"2022-05-19T14:59:19","date_gmt":"2022-05-19T14:59:19","guid":{"rendered":"\/tutorials\/?p=55108"},"modified":"2025-07-07T11:45:37","modified_gmt":"2025-07-07T11:45:37","slug":"fail2ban-configuration","status":"publish","type":"post","link":"\/tutorials\/fail2ban-configuration","title":{"rendered":"How to secure your Linux server with Fail2Ban configuration"},"content":{"rendered":"<p>Fail2Ban is arguably the best software to secure a Linux server and protect it against automated attacks. When enabled, it offers many customizable rules to ban source addresses that may try to gain access to your machine. Fail2Ban works hand in hand with a firewall, so we recommend you to install and enable them as separate security layers.<\/p><p>In this article, we will explain what Fail2Ban is and its use cases. We will also show you how to install and set up Fail2Ban.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/public\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><\/div><p>\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-fail2ban-and-what-is-it-used-for\">What Is Fail2Ban and What Is It Used For?<\/h2><p>Fail2Ban is a log-parsing application that protects <a href=\"\/vps\/linux-hosting\">Linux virtual server host<\/a> against many security threats, such as dictionary, DoS, DDoS, and brute-force attacks. It works by monitoring system logs for any malicious activity and scanning files for any entries matching identified patterns.<\/p><p>If Fail2Ban detects a spike of failed login attempts, it will automatically add new firewall rules to your iptables and block the source address for a specified time or indefinitely.<\/p><p>Installing Fail2Ban helps server owners mitigate any illegitimate activity automatically. It also alerts them via email whenever an attack is occurring.<\/p><p>A similar tool to Fail2Ban is <strong>Suricata<\/strong>, an intrusion detection and prevention system (IDS\/IPS). Instead of login attempts, this tool monitors your VPS network and notifies users about potentially malicious traffic.<\/p><p>If you want to set up the tool, check out our other tutorial to learn <a href=\"\/tutorials\/how-to-install-suricata-on-ubuntu\">how to install Suricata on Ubuntu<\/a>. <\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-install-fail2ban\">How to Install Fail2Ban<\/h2><p>To install the Fail2Ban service, connect to your server with root access using an SSH client like Terminal (macOS and Linux) or <a href=\"\/tutorials\/how-to-use-putty-ssh\">PuTTY<\/a> (Windows).<\/p><h3 class=\"wp-block-heading\" id=\"h-ubuntu\">Ubuntu:<\/h3><p>Here&rsquo;s how to install Fail2Ban on <a href=\"\/tutorials\/what-is-ubuntu\">Ubuntu<\/a>:<\/p><ol class=\"wp-block-list\">\n<li>Before installing a new package, we recommend to update the system repository and software. Run the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">apt-get update &amp;&amp; apt-get upgrade<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Install the Fail2Ban package by running the command below:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">apt-get install fail2ban<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>If you want to add email support for the Fail2Ban service, insert the following command and press <strong>Enter<\/strong>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">apt-get install sendmail<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Verify Fail2Ban status using the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo systemctl status fail2ban<\/pre><p>Hostinger VPS customers can also use <strong>Kodee <\/strong>AI Assistant to confirm Fail2ban&rsquo;s status post-installation. Access it via your VPS dashboard&rsquo;s left sidebar and ask it a question like the following example:<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\"><img decoding=\"async\" width=\"2322\" height=\"748\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/public\" alt=\"Kodee responds to a question about Fail2ban's status\" class=\"wp-image-124621\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=2322,fit=scale-down 2322w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/hpanel-vps-kodee-systemctl.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2322px) 100vw, 2322px\" \/><\/a><\/figure><\/div><p>You can also ask Kodee to restart Fail2Ban by simply entering, &ldquo;Restart Fail2Ban on my VPS.&rdquo;<\/p><h3 class=\"wp-block-heading\" id=\"h-centos\">CentOS:<\/h3><p>Follow these steps to install Fail2Ban on <a href=\"\/tutorials\/what-is-centos\">CentOS<\/a>:<\/p><ol class=\"wp-block-list\">\n<li>Fail2Ban for CentOS7 is included in the Extra Packages for Enterprise Linux (EPEL) repository. Download it by running the command below:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo yum install epel-release<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Once that is done, install Fail2Ban by inputting the following command and pressing <strong>Enter<\/strong>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo yum install fail2ban<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Enable and start the service by running these commands:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo systemctl enable fail2ban<\/pre><pre class=\"wp-block-preformatted\">sudo systemctl start fail2ban<\/pre><h3 class=\"wp-block-heading\" id=\"h-debian\">Debian:<\/h3><p>Here&rsquo;s how to install Fail2Ban on Debian:<\/p><ol class=\"wp-block-list\">\n<li>Update and upgrade your system repository by typing in the command below and pressing <strong>Enter<\/strong>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">apt-get update &amp;&amp; apt-get upgrade -y<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Proceed with the Fail2Ban installation using the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">apt-get install fail2ban<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>If you want to add email support, install Sendmail by running this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">apt-get install sendmail-bin sendmail<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Here&rsquo;s how to check Fail2Ban&rsquo;s status:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">systemctl status fail2ban<\/pre><h3 class=\"wp-block-heading\" id=\"h-fedora\">Fedora:<\/h3><p>Follow these instructions to install Fail2Ban on Fedora:<\/p><ol class=\"wp-block-list\">\n<li>Update your system repository by inserting the command below and pressing <strong>Enter<\/strong>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">dnf update<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Install Fail2Ban using this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">dnf install fail2ban<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>If you want to install Sendmail, type in the following command and press <strong>Enter<\/strong>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">dnf install sendmail<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Start and enable the Fail2Ban service by running the following commands:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">systemctl start fail2ban<\/pre><pre class=\"wp-block-preformatted\">systemctl enable fail2ban<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>If you&rsquo;ve added Sendmail, run the following to start and enable it:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">systemctl start sendmail<\/pre><pre class=\"wp-block-preformatted\">systemctl enable sendmail<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-set-up-fail2ban\">How to Set Up Fail2Ban<\/h2><p>After installing Fail2Ban, consider configuring it. In this section, we will explore how to do it using the <strong>fail2ban.local<\/strong> and <strong>jail.local<\/strong> files.<\/p><h3 class=\"wp-block-heading\" id=\"h-edit-the-default-settings-with-fail2ban-local-optional\">Edit the Default Settings with fail2ban.local (Optional)<\/h3><p>The <strong>fail2ban.conf<\/strong> file houses Fail2Ban&rsquo;s basic configuration. It contains the global settings that should not be modified.<\/p><p>If you want to make any changes, we recommend creating a local file. Make a copy of <strong>fail2ban.conf <\/strong>and rename it to <strong>fail2ban.local<\/strong> to override the default configuration profile.<\/p><p>Here&rsquo;s how to change the name of the copy and setup the settings on fail2ban.local file:<\/p><ol class=\"wp-block-list\">\n<li>Rename the file to <strong>fail2ban.local<\/strong> by running the command below. Keep in mind that it will not produce any output:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">cp \/etc\/fail2ban\/fail2ban.conf \/etc\/fail2ban\/fail2ban.local<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Type in the following command and press <strong>Enter <\/strong>to open the file:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo nano \/etc\/fail2ban\/fail2ban.local<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Now you can edit the definitions inside the file.<\/li>\n<\/ol><p>Let&rsquo;s go over the options and the values they can take.<\/p><pre class=\"wp-block-preformatted\">loglevel = INFO<\/pre><p>Define the log output level as:<\/p><ul class=\"wp-block-list\">\n<li><strong>CRITICAL <\/strong>&ndash; emergency conditions that should be investigated immediately.<\/li>\n\n\n\n<li><strong>ERROR <\/strong>&ndash; something goes wrong but is not critical.<\/li>\n\n\n\n<li><strong>WARNING <\/strong>&ndash; a potentially harmful condition.<\/li>\n\n\n\n<li><strong>NOTICE <\/strong>&ndash; a normal but significant condition.<\/li>\n\n\n\n<li><strong>INFO <\/strong>&ndash; informational messages that can be ignored.<\/li>\n\n\n\n<li><strong>DEBUG <\/strong>&ndash; debug-level messages.<\/li>\n<\/ul><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-loglevel-option.png\"><img decoding=\"async\" width=\"316\" height=\"197\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-loglevel-option.png\/public\" alt=\"An excerpt from the fail2ban.local config file talking about the loglevel option\" class=\"wp-image-55109\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-loglevel-option.png\/w=316,fit=scale-down 316w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-loglevel-option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-loglevel-option.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 316px) 100vw, 316px\" \/><\/a><\/figure><\/div><pre class=\"wp-block-preformatted\">logtarget = STDERR<\/pre><p>Log actions in a specific target socket, which can be:<\/p><ul class=\"wp-block-list\">\n<li><strong>FILE <\/strong>&ndash; output to a file socket.<\/li>\n\n\n\n<li><strong>SYSLOG<\/strong> &ndash; output to a message-based log file.<\/li>\n\n\n\n<li><strong>STDERR <\/strong>&ndash; output as a standard error.<\/li>\n\n\n\n<li><strong>STDOUT <\/strong>&ndash; standard output.<\/li>\n<\/ul><pre class=\"wp-block-preformatted\">syslogsocket = auto<\/pre><p>Set the syslog socket file to <strong>auto<\/strong> or <strong>file<\/strong> (if you&rsquo;ve set <strong>logtarget<\/strong> as <strong>SYSLOG<\/strong>).<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-syslogsocket-option.png\"><img decoding=\"async\" width=\"536\" height=\"95\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-syslogsocket-option.png\/public\" alt=\"An excerpt from the fail2ban.local config file talking about the syslogsocket option\" class=\"wp-image-55110\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-syslogsocket-option.png\/w=536,fit=scale-down 536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-syslogsocket-option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-syslogsocket-option.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 536px) 100vw, 536px\" \/><\/a><\/figure><\/div><pre class=\"wp-block-preformatted\">socket = \/var\/run\/fail2ban\/fail2ban.sock<\/pre><p>Set the socket file to communicate with the daemon. The default location is <strong>\/var\/run\/fail2ban\/fail2ban.sock<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-socket-option.png\"><img decoding=\"async\" width=\"580\" height=\"123\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-socket-option.png\/public\" alt=\"An excerpt from the fail2ban.local config file talking about the socket option\" class=\"wp-image-55111\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-socket-option.png\/w=580,fit=scale-down 580w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-socket-option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-socket-option.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><\/figure><\/div><pre class=\"wp-block-preformatted\">pidfile = \/var\/run\/fail2ban\/fail2ban.pid<\/pre><p>Set the PID file to store the process ID of the Fail2Ban server. The default location is <strong>\/var\/run\/fail2ban\/fail2ban.pid<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-pidfile-option.png\"><img decoding=\"async\" width=\"533\" height=\"108\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-pidfile-option.png\/public\" alt=\"An excerpt from the fail2ban.local config file talking about the pidfile option\" class=\"wp-image-55112\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-pidfile-option.png\/w=533,fit=scale-down 533w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-pidfile-option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-fail2ban.local-config-file-talking-about-the-pidfile-option.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-setting-up-the-jail-local-configuration-file\">Setting Up the jail.local Configuration File<\/h3><p>Fail2Ban has another configuration file named <strong>jail.conf<\/strong> which includes <strong>jails<\/strong> &ndash; filters with actions. However, users shouldn&rsquo;t directly modify this file as it contains the basic rule set for the software.<\/p><p>Instead, make a copy of the original file and name it <strong>jail.local<\/strong>. Using it, you&rsquo;ll be able to customize and setup filters and actions, such as <strong>ignoreip<\/strong>, <strong>bantime<\/strong>, <strong>findtime<\/strong>, <strong>maxretry<\/strong>, and <strong>backend<\/strong>.<\/p><p><strong>ignoreip<\/strong><\/p><p>This feature requires you to specify trusted IP addresses, DNS hosts, or CIDR masks that Fail2Ban should <strong>ignore<\/strong>. This parameter permits all traffic coming from the specified sources. You can add multiple addresses and separate them with a space.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-talking-about-the-ignoreip-option.png\"><img decoding=\"async\" width=\"586\" height=\"78\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-talking-about-the-ignoreip-option.png\/public\" alt=\"An excerpt from the jail.local config file talking about the ignoreip option\" class=\"wp-image-55113\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-talking-about-the-ignoreip-option.png\/w=586,fit=scale-down 586w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-talking-about-the-ignoreip-option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-talking-about-the-ignoreip-option.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/a><\/figure><\/div><p><strong>bantime<\/strong><\/p><p>This parameter sets the length of time that a client will be banned for after failed authentication. The ban period is measured in seconds, and the default number is 600 or 10 minutes.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-bantime-parameter..png\"><img decoding=\"async\" width=\"437\" height=\"48\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-bantime-parameter..png\" alt=\"An excerpt from the jail.local config file with the bantime parameter.\" class=\"wp-image-55114\" srcset=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-bantime-parameter..png 437w, https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-bantime-parameter.-300x33.png 300w, https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-bantime-parameter.-150x16.png 150w\" sizes=\"(max-width: 437px) 100vw, 437px\" \/><\/a><\/figure><\/div><p><strong>findtime<\/strong><\/p><p>This setting determines the time period for failed login attempts. If a host fails authentication a certain number of times (based on the <strong>maxretry<\/strong> setting) during the set period, its IP address will be banned.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-findtime-parameter..png\"><img decoding=\"async\" width=\"561\" height=\"63\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-findtime-parameter..png\" alt=\"An excerpt from the jail.local config file with the findtime parameter.\" class=\"wp-image-55115\" style=\"width:552px;height:62px\" srcset=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-findtime-parameter..png 561w, https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-findtime-parameter.-300x34.png 300w, https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-findtime-parameter.-150x17.png 150w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/a><\/figure><\/div><p><strong>maxretry<\/strong><\/p><p><strong>maxretry<\/strong> works together with <strong>findtime<\/strong> &ndash; it sets the maximum number of unsuccessful login attempts within the defined time window. The default value is 5.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-maxretry-parameter.png\"><img decoding=\"async\" width=\"463\" height=\"44\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-maxretry-parameter.png\/public\" alt=\"An excerpt from the jail.local config file with the maxretry parameter\" class=\"wp-image-55116\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-maxretry-parameter.png\/w=463,fit=scale-down 463w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-maxretry-parameter.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-maxretry-parameter.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/a><\/figure><\/div><p><strong>backend<\/strong><\/p><p>This feature allows you to specify the backend configuration for file modification. The default value is <strong>auto<\/strong>, but if you use CentOS or Fedora, it needs to be <strong>systemd<\/strong>.<\/p><p>Here are the available values you can choose from:<\/p><ul class=\"wp-block-list\">\n<li><strong>pynotify<\/strong> &ndash; monitors file system changes in real time and requires a file alteration monitor to be installed.<\/li>\n\n\n\n<li><strong>gamin<\/strong> &ndash; same as <strong>pynotify<\/strong> but requires a Gamin tool.<\/li>\n\n\n\n<li><strong>polling<\/strong> &ndash; uses a polling algorithm that doesn&rsquo;t require external libraries.<\/li>\n\n\n\n<li><strong>systemd<\/strong> &ndash; uses the <strong>systemd<\/strong> python library to access the <strong>systemd<\/strong> journal.<\/li>\n\n\n\n<li><strong>auto<\/strong> &ndash; will use the previous values in this order &ndash; <strong>pyinotify<\/strong>, <strong>gamin<\/strong>, and <strong>polling<\/strong>.<\/li>\n<\/ul><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-backend-parameter..png\"><img decoding=\"async\" width=\"686\" height=\"86\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-backend-parameter..png\" alt=\"An excerpt from the jail.local config file with the backend parameter\" class=\"wp-image-55117\" srcset=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-backend-parameter..png 686w, https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-backend-parameter.-300x38.png 300w, https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/05\/An-excerpt-from-the-jail.local-config-file-with-the-backend-parameter.-150x19.png 150w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/a><\/figure><\/div><p>You can also setup additional configurations in the <strong>jail.local<\/strong> file, including <strong>SSH<\/strong> and <strong>iptables<\/strong> settings. The available options include:<\/p><ul class=\"wp-block-list\">\n<li><strong>banaction<\/strong> &ndash; defines which default action to use when the <strong>maxretry<\/strong> threshold is reached. If you use <strong>firewalld<\/strong>, set the value to <strong>firewallcmd-ipset<\/strong>. However, if you&rsquo;ve set up UFW as your firewall, change it to <strong>ufw<\/strong>.<\/li>\n\n\n\n<li><strong>banaction_allports<\/strong> &ndash; allows you to label and block IP addresses on every port. If you use <strong>firewalld<\/strong>, set the value to <strong>firewallcmd-ipset<\/strong>.<\/li>\n\n\n\n<li><strong>port<\/strong> &ndash; the value should correspond to the set service. If you use the default port, change the value to the service name. If you use non-traditional port, input its number here.<\/li>\n\n\n\n<li><strong>filter<\/strong> &ndash; the file name located in <strong>\/etc\/fail2ban\/filter.d<\/strong> contains the <strong>failregex<\/strong> information used to parse log files.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Fail2Ban is log-parsing software that helps protect Linux-based web servers against cyber attacks.<\/p><p>This article has demonstrated howto install Fail2Ban on popular operating systems, such as Ubuntu, CentOS, Debian, and Fedora. We have also explained how to edit <strong>fail2ban.local<\/strong> and <strong>jail.local<\/strong>, the software&rsquo;s configuration files.<\/p><p>We hope this article has helped you set up Fail2Ban on your Linux server. If you have any questions or suggestions, leave them in the comments section below.<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Learn other VPS security best practices<\/h4>\n                    <p><a href=\"\/tutorials\/iptables-tutorial\">Complete Iptables Tutorial<\/a><br>\n<a href=\"\/tutorials\/how-to-set-up-a-linux-vpn-server-with-openvpn\/\">How to Setup OpenVPN on Linux<\/a><br>\n<a href=\"\/tutorials\/how-to-configure-firewall-on-ubuntu-using-ufw\/\">How to Configure UFW Firewall on Ubuntu<\/a><br>\n<a href=\"\/tutorials\/how-to-install-clamav-centos7\">How to Install ClamAV on CentOS<\/a><\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-fail2ban-configuration-faq\">Fail2Ban Configuration FAQ<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1652972277327\"><h3 class=\"schema-faq-question\">Do I Need Fail2Ban?<\/h3> <p class=\"schema-faq-answer\">Yes, it is an essential part of your server&rsquo;s security infrastructure. Fail2Ban will help secure your machine from cyber attacks that try to meddle with your login credentials.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1652972290704\"><h3 class=\"schema-faq-question\">Does Fail2Ban Work with UFW?<\/h3> <p class=\"schema-faq-answer\">UFW is an additional security layer to protect your VPS from port-scanning attacks. While Fail2Ban uses iptables as the default firewall system, you can customize the software and enable UFW instead.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1652972303718\"><h3 class=\"schema-faq-question\">Does Fail2Ban Prevent DDoS Attacks?<\/h3> <p class=\"schema-faq-answer\">A DDoS attack is a malicious attempt to interrupt the operation of a targeted server or service by flooding it with fake requests. Using the jail configuration file of Fail2Ban, you can create customized rules to detect excessive requests and block their sources.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1652972318819\"><h3 class=\"schema-faq-question\">Does Fail2Ban Work Out of the Box?<\/h3> <p class=\"schema-faq-answer\">Fail2Ban is active and running as soon as you enable it. Users don&rsquo;t need to modify its configuration as the software actually provides reasonable protection right off the bat.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Fail2Ban is arguably the best software to secure a Linux server and protect it against automated attacks. When enabled, it [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/fail2ban-configuration\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":298,"featured_media":71564,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Fail2Ban Configuration Guide for Hardening Your Linux Server","rank_math_description":"Fail2Ban can protect your server from brute-force, dictionary, DDoS, and DOS attacks. Read on to learn how to install and configure it.","rank_math_focus_keyword":"fail2ban configuration","footnotes":""},"categories":[22648,22644],"tags":[],"class_list":["post-55108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/fail2ban-configuration","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/fail2ban-configuration","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-secure-your-linux-server-with-fail2ban-configuration","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-secure-your-linux-server-with-fail2ban-configuration","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/fail2ban-configuration","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/fail2ban-configuration","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/fail2ban-configuration","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/fail2ban-configuration","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/55108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/298"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=55108"}],"version-history":[{"count":14,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/55108\/revisions"}],"predecessor-version":[{"id":131010,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/55108\/revisions\/131010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/71564"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=55108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=55108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=55108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}