{"id":15787,"date":"2023-05-09T21:59:27","date_gmt":"2023-05-09T21:59:27","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=15787"},"modified":"2023-06-21T08:47:46","modified_gmt":"2023-06-21T08:47:46","slug":"how-to-install-mod_evasive-apache-module","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-mod_evasive-apache-module\/","title":{"rendered":"How to Install mod_evasive Apache Module"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-1024x854.png\" alt=\"protected server\" width=\"1024\" height=\"854\" class=\"alignnone size-large wp-image-15788 rounded shadow lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-1024x854.png 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-300x250.png 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-128x107.png 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-420x350.png 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-540x450.png 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-720x600.png 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-960x800.png 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-1140x951.png 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-1198x999.png 1198w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-864x720.png 864w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server-1295x1080.png 1295w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/protected-server.png 1456w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/854;\" \/><\/p>\n<p>The mod_evasive Apache module is used to protect <a href=\"https:\/\/webhostinggeeks.com\/best\/web-server\/\">web servers<\/a> against <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-a-ddos-attack\/\">DDoS attacks<\/a> and other brute-force attacks. It helps to prevent excessive requests from a single IP address or user agent.<\/p>\n<p>Let&#8217;s say you have a web application running on your <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache web server<\/a>, and a hacker decides to launch a DDoS attack against your server. The attacker uses a botnet of thousands of computers to send a flood of requests to your web application, overwhelming your server and causing it to crash.<\/p>\n<p>With mod_evasive installed and configured, your <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-are-web-servers-and-why-are-they-needed\/\">web server<\/a> can detect the flood of requests and block the offending IP addresses. The DOSPageCount and DOSSiteCount parameters set in the configuration file determine the maximum number of requests allowed from a single IP address or user agent within a certain time interval. If the number of requests exceeds this limit, mod_evasive will block the IP address or user agent for a period of time specified by the DOSBlockingPeriod parameter.<\/p>\n<p>For example, you have set the DOSPageCount to 10 and the DOSSiteCount to 100, which means that no more than 10 requests can be made from a single page and no more than 100 requests can be made from a single site within a 1-second interval. If an IP address or user agent exceeds this limit, mod_evasive will block it for 10 seconds (as specified by the DOSBlockingPeriod parameter).<\/p>\n<p>In this way, mod_evasive can effectively prevent DDoS attacks and other brute-force attacks by limiting the number of requests from a single IP address or user agent within a certain time interval.<\/p>\n<p>In this short tutorial, I will teach you the steps to install mod_evasive on an Apache web server.<\/p>\n<h2>Step 1: Install the Apache Development Libraries<\/h2>\n<p>To install mod_evasive, you need to first install the Apache development libraries. You can do this by using the following command:<\/p>\n<pre>\r\nsudo yum install httpd-devel\r\n<\/pre>\n<p>This will install the required development libraries for Apache.<\/p>\n<h2>Step 2: Download mod_evasive<\/h2>\n<p>The next step is to download mod_evasive from the official website. You can download the latest version of mod_evasive by using the following command:<\/p>\n<pre>\r\nwget https:\/\/github.com\/apache\/httpd\/archive\/refs\/tags\/2.4.51.tar.gz\r\n<\/pre>\n<p>This will download the latest version of mod_evasive as a compressed file.<\/p>\n<h2>Step 3: Extract mod_evasive<\/h2>\n<p>Once the mod_evasive file is downloaded, you can extract it using the following command:<\/p>\n<pre>\r\ntar -xzvf 2.4.51.tar.gz\r\n<\/pre>\n<p>This will extract the mod_evasive files to a new directory called &#8220;httpd-2.4.51&#8221;.<\/p>\n<h2>Step 4: Build and Install mod_evasive<\/h2>\n<p>To build and install mod_evasive, you need to navigate to the &#8220;mod_evasive&#8221; directory inside the extracted &#8220;httpd-2.4.51&#8221; directory. You can do this by using the following command:<\/p>\n<pre>\r\ncd httpd-2.4.51\/modules\/filters\r\n<\/pre>\n<p>Once you are inside the &#8220;filters&#8221; directory, you can build and install mod_evasive using the following commands:<\/p>\n<pre>\r\nsudo apxs -i -c -I \/usr\/include\/libxml2\/ mod_evasive20.c\r\n<\/pre>\n<p>This will build and install mod_evasive on your Apache web server.<\/p>\n<h2>Step 5: Configure mod_evasive<\/h2>\n<p>After installing mod_evasive, you need to configure it by editing the Apache configuration file. You can open the Apache configuration file using the following command:<\/p>\n<pre>\r\nsudo vi \/etc\/httpd\/conf\/httpd.conf\r\n<\/pre>\n<p>Inside the configuration file, you need to add the following lines at the end of the file:<\/p>\n<pre>\r\nLoadModule evasive_module modules\/mod_evasive20.so\r\nDOSHashTableSize 3097\r\nDOSPageCount 10\r\nDOSSiteCount 100\r\nDOSPageInterval 1\r\nDOSSiteInterval 1\r\nDOSBlockingPeriod 10\r\nDOSLogDir \"\/var\/log\/httpd\/mod_evasive\"\r\n<\/pre>\n<p>These lines will load the mod_evasive module and set the necessary parameters to protect your web server against DDoS attacks.<\/p>\n<h2>Step 6: Restart Apache<\/h2>\n<p>After configuring mod_evasive, you need to restart Apache to apply the changes. You can do this by using the following command:<\/p>\n<pre>\r\nsudo service httpd restart\r\n<\/pre>\n<p>This will restart Apache with the mod_evasive module enabled.<\/p>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">sudo<\/span> &#8211; a command that allows users to run programs with the security privileges of another user, typically the superuser.<\/li>\n<li><span class=\"fw-bold\">yum<\/span> &#8211; a package manager for CentOS.<\/li>\n<li><span class=\"fw-bold\">wget<\/span> &#8211; a command-line utility for downloading files from the web.<\/li>\n<li><span class=\"fw-bold\">tar<\/span> &#8211; a command-line utility for manipulating tar archives.<\/li>\n<li><span class=\"fw-bold\">apxs<\/span> &#8211; a tool for building and installing Apache modules.<\/li>\n<li><span class=\"fw-bold\">vi<\/span> &#8211; a text editor for Unix-like operating systems.<\/li>\n<li><span class=\"fw-bold\">service<\/span> &#8211; a command-line utility for managing system services.<\/li>\n<\/ul>\n<h2>Conclusion:<\/h2>\n<p>mod_evasive module is a useful tool for <a href=\"https:\/\/webhostinggeeks.com\/blog\/how-to-protect-an-apache-web-server-from-ddos\/\">protecting Apache web servers against DDoS attacks<\/a> and other brute-force attacks. By limiting the number of requests from a single IP address or user agent within a certain time interval, mod_evasive can prevent the web server from being overwhelmed and crashing.<\/p>\n<p>With the steps outlined in this guide, you can easily install and configure mod_evasive on your Apache web server running on CentOS. By doing so, you can enhance the security of your web application and ensure its availability for legitimate users.<\/p>\n<p>Check out my &#8220;<a href=\"https:\/\/webhostinggeeks.com\/blog\/8-easy-steps-to-safeguard-an-apache-web-server-and-prevent-ddos\/\">8 Easy Steps to Safeguard an Apache Web Server and Prevent DDoS Attacks<\/a>&#8221; for more detailed information on securing your web server and protecting it from DDoS attacks. The tutorial covers important topics such as setting up a firewall, configuring mod_security, and using fail2ban to prevent brute force attacks. It also includes tips for monitoring your server and keeping it up to date with the latest security patches. Whether you are a beginner or an experienced web server administrator, this guide is a valuable resource for anyone looking to improve the security of a Apache web server.<\/p>\n<p>If you have any questions or suggestions, feel free to comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The mod_evasive Apache module is used to protect web servers against DDoS attacks and other brute-force attacks. It helps to prevent excessive requests from a single IP address or user&#8230;<\/p>\n","protected":false},"author":6,"featured_media":15788,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1103,2055],"tags":[1199,2069,2068,1744],"class_list":["post-15787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-centos","tag-apache","tag-ddos","tag-mod_evasive","tag-security"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/15787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=15787"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/15787\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/15788"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=15787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=15787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=15787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}