{"id":1621,"date":"2017-06-13T22:01:04","date_gmt":"2017-06-13T16:31:04","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1621"},"modified":"2026-09-14T14:10:12","modified_gmt":"2026-09-14T08:40:12","slug":"install-fail2ban-centos-7","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/install-fail2ban-centos-7\/","title":{"rendered":"Install Fail2ban on Centos 7"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is a security service that helps protect Linux servers from repeated unsuccessful login attempts and other suspicious activity. It monitors log files for failed authentication attempts and can temporarily ban the IP addresses responsible for those attempts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will explain how to <strong>install and configure Fail2ban on a CentOS 7 server<\/strong> and enable protection for SSH login attempts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, make sure you have:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A CentOS 7 server.<\/li>\n\n\n\n<li>Root or sudo access to the server.<\/li>\n\n\n\n<li>EPEL repository configured.<\/li>\n\n\n\n<li>Basic knowledge of Linux commands.<\/li>\n\n\n\n<li>SSH access to the server.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install the EPEL Repository<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is available through the <strong>EPEL (Extra Packages for Enterprise Linux)<\/strong> repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If EPEL is not already installed, install it using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum install epel-release<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Update the package repository:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum update<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Install Fail2ban<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Install the Fail2ban package using <code>yum<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum -y install fail2ban<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Enable Fail2ban at Boot<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the Fail2ban service so that it starts automatically after a server reboot:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl enable fail2ban<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Configure Fail2ban<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create or edit the <code>jail.local<\/code> configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/etc\/fail2ban\/jail.local<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[DEFAULT]\n\n# Ban hosts for one hour\nbantime = 3600\n\n# Use iptables for banning\nbanaction = iptables-multiport<\/pre>\n\n\n<p>[sshd]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">enabled = true<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the above configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>bantime = 3600<\/code> blocks an offending IP address for one hour.<\/li>\n\n\n\n<li><code>banaction<\/code> specifies the action used to block the IP address.<\/li>\n\n\n\n<li><code>[sshd]<\/code> enables Fail2ban protection for SSH.<\/li>\n\n\n\n<li><code>enabled = true<\/code> activates the SSH jail.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Start Fail2ban<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start the Fail2ban service:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl start fail2ban<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also verify the service status using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl status fail2ban<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Check the Fail2ban Jails<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To view the currently configured Fail2ban jails, run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fail2ban-client status<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output should be similar to:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Status\n|- Number of jail: 1\n`- Jail list: sshd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To get detailed information about the SSH jail, run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fail2ban-client status sshd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This displays information such as the number of currently banned IP addresses and the total number of failed attempts detected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we explained how to <strong>install and configure Fail2ban on CentOS 7<\/strong>. We configured Fail2ban to monitor SSH login attempts and temporarily ban IP addresses that make repeated unsuccessful authentication attempts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban provides an additional layer of protection against automated brute-force attacks on services such as SSH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is Fail2ban?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is a security tool that monitors system logs for repeated failed authentication attempts and can temporarily block the associated IP addresses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Where is Fail2ban available on CentOS 7?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is available through the <strong>EPEL repository<\/strong>. If EPEL is not installed, install the <code>epel-release<\/code> package first.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. How long will an IP address be banned?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this configuration, the ban time is set to <strong>3600 seconds<\/strong>, which is one hour:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bantime = 3600<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. How can I check whether Fail2ban is running?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl status fail2ban<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Related Article<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-install-and-configure-fail2ban-on-ubuntu-18-04-server\/\">How to Install and Configure Fail2ban on Ubuntu 18.04 Server &#8211; Pheonix Solutions<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/install-configure-fail2ban-ubuntu-16-04\/\">Install-configure-fail2ban-ubuntu-16-04<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Have a technology challenge or looking for the right solution for your business? Our team can help you with&nbsp;<strong>cloud, DevOps, development, infrastructure, design, and more<\/strong>. Feel free to reach out to our experts&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Fail2ban is a security service that helps protect Linux servers from repeated unsuccessful login attempts and other suspicious activity. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[161,348,261],"class_list":["post-1621","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-centos","tag-fail2ban","tag-linux","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-q9","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1621"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1621\/revisions"}],"predecessor-version":[{"id":11753,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1621\/revisions\/11753"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}