{"id":7226,"date":"2019-05-28T11:27:09","date_gmt":"2019-05-28T08:27:09","guid":{"rendered":"http:\/\/unihost.com\/help\/?p=7226"},"modified":"2026-11-06T12:50:48","modified_gmt":"2026-11-06T09:50:48","slug":"how-to-protect-a-server-with-fail2ban","status":"publish","type":"post","link":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/","title":{"rendered":"How to Protect a Server with Fail2Ban (SSH, Nginx, Apache)"},"content":{"rendered":"<div class=\"unihost-help-article\" lang=\"en\" style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Fail2Ban protects Linux servers against repeated login failures by reading service logs and banning abusive IP addresses through the firewall. Install it using apt on Ubuntu or Debian, or dnf with EPEL on Rocky Linux or AlmaLinux. Configure SSH, Nginx and Apache in \/etc\/fail2ban\/jail.local, then check active bans with fail2ban-client status sshd.<\/p>\n<p style=\"margin: 0 0 14px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\"><strong>Tested on \/ compatibility:<\/strong> Ubuntu, Debian, Rocky Linux and AlmaLinux; Fail2Ban supplied by distribution repositories. Documentation reviewed: November 6, 2026.<\/p>\n<h2 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 18pt; line-height: 1.3; margin: 22px 0 9px; font-weight: bold; color: #222;\">Requirements<\/h2>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">A Linux server with root or sudo access, running SSH, a supported firewall and readable service logs. Nginx or Apache is needed only if you want to protect a web server. Keep console access available before changing SSH protection.<\/p>\n<h2 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 18pt; line-height: 1.3; margin: 22px 0 9px; font-weight: bold; color: #222;\">Steps<\/h2>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Step 1. Install Fail2Ban<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Ubuntu \/ Debian:<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo apt update\r\nsudo apt install -y fail2ban python3-systemd<\/pre>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Rocky Linux \/ AlmaLinux (EPEL):<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo dnf install -y epel-release\r\nsudo dnf install -y fail2ban fail2ban-systemd fail2ban-firewalld<\/pre>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">On Rocky\/AlmaLinux 9, enable CRB if required before installing EPEL. If using firewalld, keep its SSH rules and firewall integration working.<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo systemctl enable --now fail2ban\r\nfail2ban-client --version<\/pre>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Step 2. Configure jail.local<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Keep local changes in \/etc\/fail2ban\/jail.local, not jail.conf, because package updates can replace default configuration files. Create or edit the local file:<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo nano \/etc\/fail2ban\/jail.local<\/pre>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">[DEFAULT]\r\nignoreip = 127.0.0.1\/8 ::1\r\nbantime = 1h\r\nfindtime = 10m\r\nmaxretry = 5\r\nbantime.increment = true\r\nbantime.maxtime = 1w\r\n\r\n[sshd]\r\nenabled = true\r\nport = ssh\r\nfilter = sshd\r\nbackend = systemd<\/pre>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">These settings control when addresses are blocked:<\/p>\n<table style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border-collapse: collapse; width: 100%; margin: 10px 0 17px;\">\n<thead>\n<tr>\n<th style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; text-align: left; border: 1px solid #d9d9d9; padding: 8px; background: #f2f2f2;\">Parameter<\/th>\n<th style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; text-align: left; border: 1px solid #d9d9d9; padding: 8px; background: #f2f2f2;\">Purpose<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">bantime<\/td>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">Ban duration, here 1 hour<\/td>\n<\/tr>\n<tr>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">findtime<\/td>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">Time window for counting failures, here 10 minutes<\/td>\n<\/tr>\n<tr>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">maxretry<\/td>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">Number of failures before a ban, here 5<\/td>\n<\/tr>\n<tr>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">ignoreip<\/td>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">Trusted addresses excluded from bans<\/td>\n<\/tr>\n<tr>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">bantime.increment<\/td>\n<td style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; border: 1px solid #d9d9d9; padding: 8px; vertical-align: top;\">Increase bans for repeat offenders<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Five matching SSH failures within ten minutes trigger a one-hour ban. Replace 203.0.113.10 with your own trusted management IP only if you need an exception. An unlimited ban uses bantime = -1.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Step 3. Enable SSH protection<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">The standard sshd filter can read authentication events directly from systemd-journald. If SSH uses a custom port, set port to that number. On Rocky\/AlmaLinux, install the fail2ban-systemd integration as shown above.<\/p>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">For SSH, use the actual SSH port in the jail configuration; do not expose administration ports unnecessarily.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Step 4. Enable Nginx or Apache protection<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Enable only the jail for the web server actually installed. The following standard filters detect HTTP authentication failures, not ordinary page views.<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">[nginx-http-auth]\r\nenabled = true\r\nport = http,https\r\nfilter = nginx-http-auth\r\nlogpath = \/var\/log\/nginx\/error.log\r\nbackend = auto\r\nmaxretry = 5\r\n\r\n[apache-auth]\r\nenabled = true\r\nport = http,https\r\nfilter = apache-auth\r\nlogpath = \/var\/log\/apache2\/error.log\r\nbackend = auto\r\nmaxretry = 5<\/pre>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">For Apache on Rocky\/AlmaLinux, use \/var\/log\/httpd\/error_log instead of \/var\/log\/apache2\/error.log. Confirm that each log file exists before enabling its jail. Do not use the old http-get-dos regex that matches every GET or POST request.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Step 5. Apply the configuration<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Check the syntax, restart Fail2Ban and list the active jails:<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo fail2ban-client -t\r\nsudo systemctl restart fail2ban\r\nsudo fail2ban-client status<\/pre>\n<h2 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 18pt; line-height: 1.3; margin: 22px 0 9px; font-weight: bold; color: #222;\">Verify<\/h2>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Check the SSH jail, unban an address if necessary and test that filters match the expected log records:<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo fail2ban-client status sshd\r\nsudo fail2ban-client set sshd unbanip 203.0.113.10\r\nsudo fail2ban-regex systemd-journal sshd<\/pre>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">For Nginx or Apache, replace the file path and filter with the corresponding error log and filter name. Zero matches may simply mean no relevant errors have been logged.<\/p>\n<pre style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.45; margin: 8px 0 16px; padding: 11px 13px; background: #f4f5f6; color: #1d1d1d; border: 1px solid #e3e3e3; border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;\">sudo fail2ban-regex \/var\/log\/nginx\/error.log nginx-http-auth\r\nsudo fail2ban-regex \/var\/log\/apache2\/error.log apache-auth<\/pre>\n<h2 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 18pt; line-height: 1.3; margin: 22px 0 9px; font-weight: bold; color: #222;\">Troubleshooting<\/h2>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Fail2Ban does not start<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Run fail2ban-client -t and inspect journalctl -u fail2ban -n 50. Check the syntax and whether configured log files exist.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">SSH failures are not detected<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Check backend = systemd, the systemd integration package and the SSH journal entries.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">IP addresses are not banned<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Check the jail status, ignoreip, firewall action and whether the actual events match the filter.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Your IP was banned<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Use your provider console and run fail2ban-client set sshd unbanip with your IP address.<\/p>\n<h2 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 18pt; line-height: 1.3; margin: 22px 0 9px; font-weight: bold; color: #222;\">FAQ<\/h2>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">What do bantime, findtime and maxretry mean?<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">bantime sets how long an IP remains blocked, findtime defines the observation window, and maxretry sets the failure threshold.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">How do I unban an IP address?<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Run sudo fail2ban-client set sshd unbanip 203.0.113.10, replacing the sample address with the blocked IP.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">How do I make bans permanent?<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Set bantime = -1 in the applicable jail. Use permanent bans carefully to avoid locking out legitimate users.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Does Fail2Ban work with Docker containers?<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Yes, but the host must have access to container logs and the ban action must affect container traffic, often in Docker forwarding chains.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Fail2Ban or a firewall: do I need both?<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Use both. A firewall enforces network rules, while Fail2Ban reads logs and dynamically creates bans through the firewall.<\/p>\n<h2 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 18pt; line-height: 1.3; margin: 22px 0 9px; font-weight: bold; color: #222;\">Related Articles<\/h2>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\"><a href=\"https:\/\/unihost.com\/help\/protect-your-windows-rdp-from-brute-force\/\">Protect Windows RDP from Brute Force<\/a>; <a href=\"https:\/\/github.com\/fail2ban\/fail2ban\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Official Fail2Ban documentation<\/a>.<\/p>\n<h3 style=\"font-family: Ubuntu,Arial,sans-serif; font-size: 14pt; line-height: 1.3; margin: 17px 0 9px; font-weight: bold; color: #222;\">Protect your Linux server with Unihost<\/h3>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\">Choose a VPS for your application or use managed server administration for ongoing security maintenance.<\/p>\n<p style=\"margin: 0 0 12px; font-family: Ubuntu,Arial,sans-serif; font-size: 12pt; line-height: 1.55; color: #242424;\"><a href=\"https:\/\/unihost.com\/vps\/\">VPS Hosting<\/a> | <a href=\"https:\/\/unihost.com\/management\/\">Server Management<\/a><\/p>\n<\/div>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"headline\":\"How to Protect a Server with Fail2Ban (SSH, Nginx, Apache)\",\"inLanguage\":\"en\",\"description\":\"Fail2Ban protects Linux servers against repeated login failures by reading service logs and banning abusive IP addresses through the firewall. Install it using apt on Ubuntu or Debian, or dnf with EPEL on Rocky Linux or AlmaLinux. Configure SSH, Nginx and Apache in \/etc\/fail2ban\/jail.local, then check active bans with fail2ban-client status sshd.\",\"author\":{\"@type\":\"Organization\",\"name\":\"Unihost\"},\"publisher\":{\"@type\":\"Organization\",\"name\":\"Unihost\",\"url\":\"https:\/\/unihost.com\/\"},\"dateModified\":\"2026-11-06\"},{\"@type\":\"FAQPage\",\"inLanguage\":\"en\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What do bantime, findtime and maxretry mean?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"bantime sets how long an IP remains blocked, findtime defines the observation window, and maxretry sets the failure threshold.\"}},{\"@type\":\"Question\",\"name\":\"How do I unban an IP address?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Run sudo fail2ban-client set sshd unbanip 203.0.113.10, replacing the sample address with the blocked IP.\"}},{\"@type\":\"Question\",\"name\":\"How do I make bans permanent?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Set bantime = -1 in the applicable jail. Use permanent bans carefully to avoid locking out legitimate users.\"}},{\"@type\":\"Question\",\"name\":\"Does Fail2Ban work with Docker containers?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, but the host must have access to container logs and the ban action must affect container traffic, often in Docker forwarding chains.\"}},{\"@type\":\"Question\",\"name\":\"Fail2Ban or a firewall: do I need both?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use both. A firewall enforces network rules, while Fail2Ban reads logs and dynamically creates bans through the firewall.\"}}]}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fail2Ban protects Linux servers against repeated login failures by reading service logs and banning abusive IP addresses through the firewall. Install it using apt on Ubuntu or Debian, or dnf with EPEL on Rocky Linux or AlmaLinux. Configure SSH, Nginx and Apache in \/etc\/fail2ban\/jail.local, then check active bans with fail2ban-client status sshd. Tested on \/ [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[447,457,499],"class_list":["post-7226","post","type-post","status-publish","format-standard","hentry","category-dedicated-servers","tag-apache-2","tag-centos-2","tag-fail2ban"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Install and Configure Fail2Ban on Ubuntu, Debian and Rocky Linux | Unihost<\/title>\n<meta name=\"description\" content=\"Protect SSH and web servers with Fail2Ban: install it, create jail.local, set bantime, findtime and maxretry, check banned IPs and unban addresses.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install and Configure Fail2Ban on Ubuntu, Debian and Rocky Linux | Unihost\" \/>\n<meta property=\"og:description\" content=\"Protect SSH and web servers with Fail2Ban: install it, create jail.local, set bantime, findtime and maxretry, check banned IPs and unban addresses.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/\" \/>\n<meta property=\"og:site_name\" content=\"Unihost.FAQ\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/unihost\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-28T08:27:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-06T09:50:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/unihost.com\/help\/minio.php?.\/unihost-logo-alt.png\" \/>\n\t<meta property=\"og:image:width\" content=\"250\" \/>\n\t<meta property=\"og:image:height\" content=\"141\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Unihost Support\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@unihost\" \/>\n<meta name=\"twitter:site\" content=\"@unihost\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Unihost Support\" \/>\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:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/\"},\"author\":{\"name\":\"Unihost Support\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#\\\/schema\\\/person\\\/bb5ae95f38577c920e6a7507888b715a\"},\"headline\":\"How to Protect a Server with Fail2Ban (SSH, Nginx, Apache)\",\"datePublished\":\"2019-05-28T08:27:09+00:00\",\"dateModified\":\"2026-11-06T09:50:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/\"},\"wordCount\":698,\"publisher\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#organization\"},\"keywords\":[\"Apache\",\"CentOS\",\"fail2ban\"],\"articleSection\":[\"02. Dedicated servers\"],\"inLanguage\":\"en\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/\",\"url\":\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/\",\"name\":\"How to Install and Configure Fail2Ban on Ubuntu, Debian and Rocky Linux | Unihost\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#website\"},\"datePublished\":\"2019-05-28T08:27:09+00:00\",\"dateModified\":\"2026-11-06T09:50:48+00:00\",\"description\":\"Protect SSH and web servers with Fail2Ban: install it, create jail.local, set bantime, findtime and maxretry, check banned IPs and unban addresses.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/how-to-protect-a-server-with-fail2ban\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Unihost\",\"item\":\"https:\\\/\\\/unihost.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Help\",\"item\":\"https:\\\/\\\/unihost.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Protect a Server with Fail2Ban (SSH, Nginx, Apache)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/unihost.com\\\/help\\\/\",\"name\":\"Unihost.FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/unihost.com\\\/help\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#organization\",\"name\":\"Unihost\",\"alternateName\":\"Unihost\",\"url\":\"https:\\\/\\\/unihost.com\\\/help\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/unihost.com\\\/help\\\/minio.php?2026\\\/01\\\/minio.png\",\"contentUrl\":\"https:\\\/\\\/unihost.com\\\/help\\\/minio.php?2026\\\/01\\\/minio.png\",\"width\":300,\"height\":300,\"caption\":\"Unihost\"},\"image\":{\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/unihost\\\/\",\"https:\\\/\\\/x.com\\\/unihost\",\"https:\\\/\\\/www.instagram.com\\\/unihost\\\/?hl=en\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/unihost-com\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCITKsxMDnslQY8brN3advgw\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/unihost.com\\\/help\\\/#\\\/schema\\\/person\\\/bb5ae95f38577c920e6a7507888b715a\",\"name\":\"Unihost Support\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0c9db17c2a0d93e8a0d5ac123f8c5db750ad4d3d5657369c0c4e480f5af77b8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0c9db17c2a0d93e8a0d5ac123f8c5db750ad4d3d5657369c0c4e480f5af77b8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0c9db17c2a0d93e8a0d5ac123f8c5db750ad4d3d5657369c0c4e480f5af77b8?s=96&d=mm&r=g\",\"caption\":\"Unihost Support\"},\"sameAs\":[\"https:\\\/\\\/unihost.com\\\/\"],\"url\":\"https:\\\/\\\/unihost.com\\\/help\\\/author\\\/support\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Install and Configure Fail2Ban on Ubuntu, Debian and Rocky Linux | Unihost","description":"Protect SSH and web servers with Fail2Ban: install it, create jail.local, set bantime, findtime and maxretry, check banned IPs and unban addresses.","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:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/","og_locale":"en_US","og_type":"article","og_title":"How to Install and Configure Fail2Ban on Ubuntu, Debian and Rocky Linux | Unihost","og_description":"Protect SSH and web servers with Fail2Ban: install it, create jail.local, set bantime, findtime and maxretry, check banned IPs and unban addresses.","og_url":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/","og_site_name":"Unihost.FAQ","article_publisher":"https:\/\/www.facebook.com\/unihost\/","article_published_time":"2019-05-28T08:27:09+00:00","article_modified_time":"2026-11-06T09:50:48+00:00","og_image":[{"width":250,"height":141,"url":"https:\/\/unihost.com\/help\/minio.php?.\/unihost-logo-alt.png","type":"image\/png"}],"author":"Unihost Support","twitter_card":"summary_large_image","twitter_creator":"@unihost","twitter_site":"@unihost","twitter_misc":{"Written by":"Unihost Support","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/#article","isPartOf":{"@id":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/"},"author":{"name":"Unihost Support","@id":"https:\/\/unihost.com\/help\/#\/schema\/person\/bb5ae95f38577c920e6a7507888b715a"},"headline":"How to Protect a Server with Fail2Ban (SSH, Nginx, Apache)","datePublished":"2019-05-28T08:27:09+00:00","dateModified":"2026-11-06T09:50:48+00:00","mainEntityOfPage":{"@id":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/"},"wordCount":698,"publisher":{"@id":"https:\/\/unihost.com\/help\/#organization"},"keywords":["Apache","CentOS","fail2ban"],"articleSection":["02. Dedicated servers"],"inLanguage":"en"},{"@type":"WebPage","@id":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/","url":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/","name":"How to Install and Configure Fail2Ban on Ubuntu, Debian and Rocky Linux | Unihost","isPartOf":{"@id":"https:\/\/unihost.com\/help\/#website"},"datePublished":"2019-05-28T08:27:09+00:00","dateModified":"2026-11-06T09:50:48+00:00","description":"Protect SSH and web servers with Fail2Ban: install it, create jail.local, set bantime, findtime and maxretry, check banned IPs and unban addresses.","breadcrumb":{"@id":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/unihost.com\/help\/how-to-protect-a-server-with-fail2ban\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Unihost","item":"https:\/\/unihost.com\/"},{"@type":"ListItem","position":2,"name":"Help","item":"https:\/\/unihost.com\/help\/"},{"@type":"ListItem","position":3,"name":"How to Protect a Server with Fail2Ban (SSH, Nginx, Apache)"}]},{"@type":"WebSite","@id":"https:\/\/unihost.com\/help\/#website","url":"https:\/\/unihost.com\/help\/","name":"Unihost.FAQ","description":"","publisher":{"@id":"https:\/\/unihost.com\/help\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/unihost.com\/help\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/unihost.com\/help\/#organization","name":"Unihost","alternateName":"Unihost","url":"https:\/\/unihost.com\/help\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/unihost.com\/help\/#\/schema\/logo\/image\/","url":"https:\/\/unihost.com\/help\/minio.php?2026\/01\/minio.png","contentUrl":"https:\/\/unihost.com\/help\/minio.php?2026\/01\/minio.png","width":300,"height":300,"caption":"Unihost"},"image":{"@id":"https:\/\/unihost.com\/help\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/unihost\/","https:\/\/x.com\/unihost","https:\/\/www.instagram.com\/unihost\/?hl=en","https:\/\/www.linkedin.com\/company\/unihost-com","https:\/\/www.youtube.com\/channel\/UCITKsxMDnslQY8brN3advgw"]},{"@type":"Person","@id":"https:\/\/unihost.com\/help\/#\/schema\/person\/bb5ae95f38577c920e6a7507888b715a","name":"Unihost Support","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/secure.gravatar.com\/avatar\/a0c9db17c2a0d93e8a0d5ac123f8c5db750ad4d3d5657369c0c4e480f5af77b8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a0c9db17c2a0d93e8a0d5ac123f8c5db750ad4d3d5657369c0c4e480f5af77b8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a0c9db17c2a0d93e8a0d5ac123f8c5db750ad4d3d5657369c0c4e480f5af77b8?s=96&d=mm&r=g","caption":"Unihost Support"},"sameAs":["https:\/\/unihost.com\/"],"url":"https:\/\/unihost.com\/help\/author\/support\/"}]}},"_links":{"self":[{"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/posts\/7226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/comments?post=7226"}],"version-history":[{"count":14,"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/posts\/7226\/revisions"}],"predecessor-version":[{"id":20478,"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/posts\/7226\/revisions\/20478"}],"wp:attachment":[{"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/media?parent=7226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/categories?post=7226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unihost.com\/help\/wp-json\/wp\/v2\/tags?post=7226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}