{"id":720,"date":"2026-07-25T23:45:07","date_gmt":"2026-07-25T23:45:07","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=720"},"modified":"2026-07-25T23:45:07","modified_gmt":"2026-07-25T23:45:07","slug":"how-to-configure-fail2ban-for-vps-security","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/","title":{"rendered":"How to Configure Fail2ban for VPS Security"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Configure Fail2ban for VPS Security<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is an intrusion prevention tool that monitors log files for brute-force login attempts and automatically bans offending IP addresses using firewall rules. For any VPS exposed to the internet \u2014 whether running SSH, a web server, or mail services \u2014 fail2ban is a critical first line of defense. This guide covers installation, configuration of common jails, custom rule creation, and monitoring best practices.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Fail2ban<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On Ubuntu or Debian-based systems, installation is a single command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update &amp;&amp; apt install fail2ban -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, copy the default configuration file \u2014 never edit jail.conf directly, as package updates will overwrite it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring the SSH Jail<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SSH brute-force attacks are the most common threat to any VPS. Edit \/etc\/fail2ban\/jail.local and ensure the SSH jail is enabled:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[sshd]\nenabled = true\nport = ssh\nfilter = sshd\nlogpath = \/var\/log\/auth.log\nmaxretry = 5\nbantime = 3600\nfindtime = 600<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration bans an IP for 1 hour after 5 failed login attempts within 10 minutes. For higher-security setups, reduce maxretry to 3 and increase bantime to 86400 (24 hours).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Web Server Protection (Nginx\/Apache)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban ships with jails for common web attacks. Enable the Nginx jail to block bots probing for vulnerable paths:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[nginx-http-auth]\nenabled = true\nport = http,https\nfilter = nginx-http-auth\nlogpath = \/var\/log\/nginx\/error.log\nmaxretry = 3\nbantime = 3600\n\n[nginx-botsearch]\nenabled = true\nport = http,https\nfilter = nginx-botsearch\nlogpath = \/var\/log\/nginx\/access.log\nmaxretry = 10\nbantime = 3600<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Creating Custom Filters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you run a custom application, you can create your own fail2ban filter. For example, to block IPs that hit a non-existent WordPress XML-RPC endpoint repeatedly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/fail2ban\/filter.d\/wp-xmlrpc.conf\n[Definition]\nfailregex = ^&lt;HOST&gt;.*POST .*\/xmlrpc\\.php.* 404\nignoreregex =<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then add a corresponding jail in jail.local and restart fail2ban.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Monitoring and Maintenance<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check the current ban status with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fail2ban-client status\nfail2ban-client status sshd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">View banned IPs in the firewall:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>iptables -L -n | grep f2b<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set up email alerts for bans by adding destemail = you@example.com and action = %(action_mw)s to your jails. Restart fail2ban after any config change: systemctl restart fail2ban.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is a lightweight, highly effective security tool that every VPS should run. Combined with SSH key-only authentication, regular patching, and a well-configured firewall, it dramatically reduces your attack surface. For more VPS security guidance, <a href=\"https:\/\/virtualserversvps.com\/\">see our full security benchmarks<\/a> and recommended configurations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Configure Fail2ban for VPS Security Fail2ban is an intrusion prevention tool that monitors log files for brute-force login attempts and automatically bans offending IP addresses using firewall rules&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-720","post","type-post","status-publish","format-standard","hentry","category-security-compliance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Configure Fail2ban for VPS Security - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure Fail2ban for VPS Security\" \/>\n<meta property=\"og:description\" content=\"How to Configure Fail2ban for VPS Security\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-25T23:45:07+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/\",\"name\":\"How to Configure Fail2ban for VPS Security - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-07-25T23:45:07+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure Fail2ban for VPS Security\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Configure Fail2ban for VPS Security - Virtual Servers VPS Blog","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:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure Fail2ban for VPS Security","og_description":"How to Configure Fail2ban for VPS Security","og_url":"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-07-25T23:45:07+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/","url":"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/","name":"How to Configure Fail2ban for VPS Security - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-07-25T23:45:07+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/how-to-configure-fail2ban-for-vps-security\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Configure Fail2ban for VPS Security"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=720"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/720\/revisions"}],"predecessor-version":[{"id":721,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/720\/revisions\/721"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}