{"id":13474,"date":"2024-08-21T08:27:48","date_gmt":"2024-08-21T08:27:48","guid":{"rendered":"https:\/\/www.bodhost.com\/kb\/?p=13474"},"modified":"2026-02-26T14:02:10","modified_gmt":"2026-02-26T14:02:10","slug":"how-to-install-fail2ban-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/","title":{"rendered":"Install Fail2ban on Ubuntu"},"content":{"rendered":"<p>This guide explains how to install Fail2ban on Ubuntu 22.04. A strong intrusion prevention software architecture called Fail2Ban protects against SSH brute-force attacks. It is an important tool for server toughening and was created in Python. In order to avoid harmful IP addresses for a predetermined amount of time, Fail2Ban automatically modifies your iptables firewall configuration through the creation of rules.<\/p>\n<p>Fail2Ban is an open-source program that can be used on POSIX systems with a local packet-control system or firewall, such as TCP Wrapper or iptables. It is free of cost. It improves defenses against a range of cyber threats, such as botnet assaults, DDoS attacks, and brute-force attacks.<\/p>\n<p><strong>Now let us begin the installation process:<\/strong><\/p>\n<p><strong>1. To update the server, execute the following command:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>apt update &amp;&amp; apt upgrade -y<\/strong><\/span><\/p><\/blockquote>\n<p><strong>2. Install Fail2ban:<\/strong><\/p>\n<p><strong>Perform the subsequent command to install Fail2ban:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>apt install fail2ban -y<\/strong><\/span><\/p><\/blockquote>\n<p>Since some of its default settings can have unintended consequences, the Fail2ban service is disabled by default.<\/p>\n<p><strong>Configuring Fail2ban<\/strong><\/p>\n<p>In order to set up Fail2ban, we must first copy the jail.conf configuration file, save it as jail.local, and change the jail.local file name. By doing this, we can attempt to test the cloned file while keeping the original configuration file safe. Run the following command to complete this task:<\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>cp \/etc\/fail2ban\/jail.{conf,local}<\/strong><\/span><\/p><\/blockquote>\n<p>Use your favorite editor to make modifications to the copied file now.<\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>vi \/etc\/fail2ban\/jail.local<\/strong><\/span><\/p><\/blockquote>\n<p><strong>Individual Jail Settings<\/strong><\/p>\n<p>Each service can configured separately. Section headers like [sshd] define those. It is necessary to enable each of these parts separately by including an \u201cenabled = true\u201d line beneath the header along with the other options.<\/p>\n<blockquote><p><strong>[jail_to_enable]<\/strong><\/p>\n<p><strong>. . .<\/strong><\/p>\n<p><strong>enabled = true<\/strong><\/p>\n<p><strong>. . .<\/strong><\/p><\/blockquote>\n<p>Locate [sshd] in the jail.local file, then add enabled = true below [sshd] to enable the SSH service.<\/p>\n<p>Save the file after adding it, then close it.<\/p>\n<p><strong>3. Launch and activate Fail2ban:<\/strong><\/p>\n<p><strong>Now, let us start and enable Fail2ban service using following commands:<\/strong><\/p>\n<blockquote><p><strong>systemctl start fail2ban<\/strong><br \/>\n<strong>systemctl enable fail2ban<\/strong><\/p><\/blockquote>\n<p>Use the following solution if, after running the start command, you receive an error:<\/p>\n<p><strong>Open the configuration file for Fail2ban:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>nano \/etc\/fail2ban\/jail.local<\/strong><\/span><\/p><\/blockquote>\n<p><strong>Look up \u201cbackend&#8221; and replace \u201csystemd\u201d with the backend value:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>backend = systemd<\/strong><\/span><\/p><\/blockquote>\n<p><strong>Restart Fail2ban service:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>systemctl restart fail2ban<\/strong><\/span><\/p><\/blockquote>\n<p><strong>Verify the Fail2ban service&#8217;s status:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>systemctl status fail2ban<\/strong><\/span><\/p><\/blockquote>\n<p><strong>We are able to verify the services are operational:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>fail2ban-client status<\/strong><\/span><\/p><\/blockquote>\n<p><strong>Output:<\/strong><\/p>\n<blockquote><p><strong>Status<\/strong><\/p>\n<p><strong>|- Number of jail:\u00a0 1<\/strong><\/p>\n<p><strong>`- Jail list:\u00a0\u00a0 sshd<\/strong><\/p><\/blockquote>\n<p><strong>We can also look up specific jail information:<\/strong><\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>fail2ban-client status sshd<\/strong><\/span><\/p><\/blockquote>\n<p>You have the ability to change a number of variables based on your needs.<\/p>\n<p><strong>Here are a few of the parameters we have listed:<\/strong><\/p>\n<p><strong>1. bantime<br \/>\n<\/strong>The bantime parameter determines how long an IP address will banned after exceeding the allowed number of failed login attempts. By default, this set to 10 minutes.<\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"text-decoration: underline;\"><strong>bantime = 1d<\/strong><\/span><\/p>\n<\/blockquote>\n<p><strong>2. findtime<br \/>\n<\/strong>The findtime parameter specifies the time window during which consecutive failed login attempts are tracked. If multiple failed attempts occur within this period, the IP may banned.<\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>findtime = 10m<\/strong><\/span><\/p><\/blockquote>\n<p><strong>3. maxretry<br \/>\n<\/strong>The maxretry parameter sets the maximum number of failed login attempts allowed within the findtime window. If this limit exceeded, the IP address will banned.<\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>maxretry = 5<\/strong><\/span><\/p><\/blockquote>\n<p><strong>4. ignoreip<br \/>\n<\/strong>The ignoreip parameter is used to whitelist specific IP addresses, exempting them from being banned. To add an IP to this list, modify the ignoreip line by including the IP addresses you want to exempt:<\/p>\n<blockquote><p><span style=\"text-decoration: underline;\"><strong>ignoreip = 127.0.0.1\/8 ::1 222.222.222.222 192.168.0.0\/24<\/strong><\/span><\/p><\/blockquote>\n<p>You should now be able to set up and install fail2ban and give the server an additional degree of protection. However, if you face any difficulty, feel free to contact our support staff.<\/p>\n<p>Also, read more about <a href=\"https:\/\/www.bodhost.com\/kb\/how-to-install-python-3-on-ubuntu-20-04-or-22-04\/\" target=\"_blank\" rel=\"noopener\">How to Install Python 3 on Ubuntu 20.04 or 22.04<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide explains how to install Fail2ban on Ubuntu 22.04. A strong intrusion prevention software architecture called Fail2Ban protects against SSH brute-force attacks. It is an important tool for server&hellip;<\/p>\n<p><a href=\"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1559],"tags":[1560],"class_list":["post-13474","post","type-post","status-publish","format-standard","hentry","category-ubuntu","tag-install-fail2ban-on-ubuntu"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Install Fail2ban on Ubuntu<\/title>\n<meta name=\"description\" content=\"This guide explains how to install Fail2ban on Ubuntu 22.04.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install Fail2ban on Ubuntu\" \/>\n<meta property=\"og:description\" content=\"This guide explains how to install Fail2ban on Ubuntu 22.04.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-21T08:27:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:02:10+00:00\" \/>\n<meta name=\"author\" content=\"Serena\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Serena\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/\"},\"author\":{\"name\":\"Serena\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/ffd3f118493c99471ae5bd4790a55830\"},\"headline\":\"Install Fail2ban on Ubuntu\",\"datePublished\":\"2024-08-21T08:27:48+00:00\",\"dateModified\":\"2026-02-26T14:02:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/\"},\"wordCount\":634,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"keywords\":[\"Install Fail2ban on Ubuntu\"],\"articleSection\":[\"Ubuntu\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/\",\"name\":\"How to Install Fail2ban on Ubuntu\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"datePublished\":\"2024-08-21T08:27:48+00:00\",\"dateModified\":\"2026-02-26T14:02:10+00:00\",\"description\":\"This guide explains how to install Fail2ban on Ubuntu 22.04.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-install-fail2ban-on-ubuntu\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ubuntu\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/ubuntu\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Install Fail2ban on Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"alternateName\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"width\":240,\"height\":240,\"caption\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/ffd3f118493c99471ae5bd4790a55830\",\"name\":\"Serena\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8bf3c9f6220a13a4d46295ad7c38a0c9e351ca3a57d0e417580c8e8b83a12a50?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8bf3c9f6220a13a4d46295ad7c38a0c9e351ca3a57d0e417580c8e8b83a12a50?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8bf3c9f6220a13a4d46295ad7c38a0c9e351ca3a57d0e417580c8e8b83a12a50?s=96&d=mm&r=g\",\"caption\":\"Serena\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/seema\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Install Fail2ban on Ubuntu","description":"This guide explains how to install Fail2ban on Ubuntu 22.04.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How to Install Fail2ban on Ubuntu","og_description":"This guide explains how to install Fail2ban on Ubuntu 22.04.","og_url":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2024-08-21T08:27:48+00:00","article_modified_time":"2026-02-26T14:02:10+00:00","author":"Serena","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Serena","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/"},"author":{"name":"Serena","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/ffd3f118493c99471ae5bd4790a55830"},"headline":"Install Fail2ban on Ubuntu","datePublished":"2024-08-21T08:27:48+00:00","dateModified":"2026-02-26T14:02:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/"},"wordCount":634,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"keywords":["Install Fail2ban on Ubuntu"],"articleSection":["Ubuntu"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/","url":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/","name":"How to Install Fail2ban on Ubuntu","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"datePublished":"2024-08-21T08:27:48+00:00","dateModified":"2026-02-26T14:02:10+00:00","description":"This guide explains how to install Fail2ban on Ubuntu 22.04.","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/how-to-install-fail2ban-on-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Ubuntu","item":"https:\/\/www.bodhost.com\/kb\/category\/ubuntu\/"},{"@type":"ListItem","position":2,"name":"Install Fail2ban on Ubuntu"}]},{"@type":"WebSite","@id":"https:\/\/www.bodhost.com\/kb\/#website","url":"https:\/\/www.bodhost.com\/kb\/","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","description":"","publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"alternateName":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bodhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bodhost.com\/kb\/#organization","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","url":"https:\/\/www.bodhost.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","width":240,"height":240,"caption":"Web Hosting Knowledge Base | bodHOST Hosting FAQ"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/ffd3f118493c99471ae5bd4790a55830","name":"Serena","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/8bf3c9f6220a13a4d46295ad7c38a0c9e351ca3a57d0e417580c8e8b83a12a50?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8bf3c9f6220a13a4d46295ad7c38a0c9e351ca3a57d0e417580c8e8b83a12a50?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8bf3c9f6220a13a4d46295ad7c38a0c9e351ca3a57d0e417580c8e8b83a12a50?s=96&d=mm&r=g","caption":"Serena"},"url":"https:\/\/www.bodhost.com\/kb\/author\/seema\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/13474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=13474"}],"version-history":[{"count":4,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/13474\/revisions"}],"predecessor-version":[{"id":13479,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/13474\/revisions\/13479"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=13474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=13474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=13474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}