{
  "created": "2015-12-20T19:56:34Z",
  "hierarchy": [
    {
      "name": "ROOT",
      "type": "folder",
      "uri": "/ROOT"
    },
    {
      "name": "Fail2Ban for Dovecot",
      "type": "article",
      "uri": "Fail2Ban_for_Dovecot"
    }
  ],
  "html": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\"/>\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>\n    <meta property=\"og:image\" content=\"/img/logo512.png\"/>\n    <meta property=\"og:site_name\" content=\"Nikhil's Personal Wiki\"/>\n    <link rel=\"og:image\" href=\"/img/logo512.png\"/>\n    <link rel=\"icon\" href=\"/img/favicon.png\"/>\n    <link rel=\"apple-touch-icon\" href=\"/img/logo192.png\"/>\n    <link rel=\"stylesheet\" href=\"/css/styles.css\"/>\n    <link rel=\"stylesheet\" href=\"/css/highlight.css\"/>\n    <title>Fail2Ban for Dovecot &ndash; Nikhil's Personal Wiki</title>\n    <script type=\"text/javascript\" id=\"MathJax-script\" defer src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js\"></script>\n    <script defer data-domain=\"wiki.nikhil.io\" src=\"https://plausible.io/js/plausible.js\"></script>\n  </head>\n  <body>\n    <noscript>\n      👉 A few things won&#8217;t work if you have JavaScript disabled.\n    </noscript>\n    <div class=\"container article\">\n      <header>\n        <nav>\n          <ul>\n            <li>\n              <a href=\"/archive\"  title=\"Archive\">\n                <span>Archive</span>\n              </a>\n            </li>\n            <li>\n              <a href=\"/Home\"  title=\"Home\">\n                <span>Home</span>\n              </a>\n            </li>\n            <li>\n              <a href=\"/random\"  title=\"See a random article\">\n                <span>Random</span>\n              </a>\n            </li>\n            \n            \n              \n                <li>\n                  <a href=\"/Fail2Ban_for_Dovecot/raw.txt\"  title=\"View Source\">\n                    <span>Raw</span>\n                  </a>\n                </li>\n              \n              \n            \n            \n            \n            \n              \n                <li>\n                  <a href=\"/Fail2Ban_for_Dovecot/revisions\" >\n                    <span>Revisions</span>\n                  </a>\n                </li>\n              \n            \n            \n              \n                \n                  <li>\n                    <a href=\"/Fail2Ban_for_Dovecot/index.json\" title=\"View JSON Object\">\n                      <span>JSON</span>\n                    </a>\n                  </li>\n                \n              \n            \n          </ul>\n        </nav>\n      </header>\n      <main>\n        \n  <nav>\n  <ul>\n    \n      <li>\n        <a data-entity-type=\"folder\" href=\"/ROOT\" title=\"ROOT\">Root</a>\n      </li>\n    \n      <li>\n        <a data-entity-type=\"article\" href=\"/Fail2Ban_for_Dovecot\" title=\"Fail2Ban for Dovecot\">Fail2Ban for Dovecot</a>\n      </li>\n    \n    \n    \n    \n    \n  </ul>\n</nav>\n\n  <h1>Fail2Ban for Dovecot\n    \n  </h1>\n  <h2>Installation</h2>\n<pre><code>yum install fail2ban\nchkconfig fail2ban on\n</code></pre>\n<h2>Configuration</h2>\n<p>Now add this to <code>/etc/fail2ban/jail.conf</code>. Change the <code>sender</code> email.</p>\n<pre><code>[dovecot]\nenabled  = true\nfilter   = dovecot\naction   = iptables-multiport[name=dovecot, port=&quot;pop3,pop3s,imap,imaps&quot;, protocol=tcp]\n           sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]\nlogpath  = /var/log/maillog\nmaxretry = 10\nfindtime = 1200\nbantime  = -10\n</code></pre>\n<p>See <a href=\"http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options\">the manual</a> for an explanation of the options. In this configuration, anyone attempting to authenticate unsuccessfully 10 times will be banned permanently.</p>\n<p>Fail2Ban will try looking for a configuration/filter file called &ldquo;<code>dovecot.conf</code>&rdquo; in the filters directory, <code>/etc/fail2ban/filters.d</code>.<br />\nCreate it and add this if it doesn&rsquo;t exist for some reason:</p>\n<pre><code>[Definition]\nfailregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P&lt;host&gt;\\S*),.*\nignoreregex =\n</code></pre>\n<h2>Testing</h2>\n<p>Fail2Ban comes with a handy-dandy regex testing tool.</p>\n<pre><code>fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf\n</code></pre>\n<p>You should issue <code>iptables -L</code> to verify that there&rsquo;s a Fail2Ban chain. Now <code>telnet</code> to the POP3 port from another machine and try logging in with some junk.</p>\n<pre><code>Trying 198.81.129.107...\nConnected to example.com (198.81.129.107).\nEscape character is '^]'.\n+OK Hello. Please be nice.\nuser hahahaha**\n-ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.\n</code></pre>\n<p>You&rsquo;ll see a bunch of these in <code>/var/log/maillog</code>:</p>\n<pre><code>Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107\n</code></pre>\n<p>When you see 10 of them, wait a bit. You&rsquo;ll see an email from Fail2Ban informing you that it&rsquo;s blocked an IP. To verify, issue <code>iptables -L -n</code>. You&rsquo;ll see this somewhere:</p>\n<pre><code>Chain fail2ban-dovecot (1 references)\ntarget     prot opt source               destination\nDROP       all  --  72.21.81.85        0.0.0.0/0\n</code></pre>\n<p>Nice. To unban, just remove the rule from the chain:</p>\n<pre><code>iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP\n</code></pre>\n<h2>Using the Service</h2>\n<pre><code>service fail2ban start\n</code></pre>\n<p>Check its status</p>\n<pre><code>[root@example ~]# service fail2ban status\nFail2ban (pid 15919) is running...\nStatus\n|- Number of jail:  1\n`- Jail list:       dovecot\n</code></pre>\n<p>You should have gotten an email from the service with the subject &ldquo;<strong>[Fail2Ban] dovecot: started</strong>&rdquo;. Check <code>/var/log/messages</code> for banned IPs</p>\n\n\n      </main>\n      <footer>\n        <p>\n          \n        </p>\n        <ul>\n          \n  <li>2,823 bytes</li>\n  \n    <li>Created on Sunday, 20 December 2015 at 19:56 UTC</li>\n    <li>Modified on Thursday, 28 May 2026 at 13:06 UTC</li>\n    <br/>\n    <li>\n      <a\n        href=\"https://github.com/afreeorange/wiki.nikhil.io.articles/edit/master/Fail2Ban for Dovecot.md\"\n        title=\"Edit this article\">Edit this article</a>\n    </li>\n  \n\n          <li>\n            <a href=\"https://github.com/afreeorange/bock\" title=\"View the project that generates this wiki on Github\">bock\n            5.3.0-beta</a>\n          </li>\n        </ul>\n      </footer>\n    </div>\n    \n    \n      <script type=\"text/javascript\">\n        /**\n         * Quick shortcut to take me to the search box which is 90% of how I navigate\n         * this wiki anyway.\n         */\n        document.body.addEventListener(\n          \"keypress\", (e) => e.key === \"f\"\n          ? window.location.assign(\"/archive\")\n          : null);\n        window.MathJax = {\n          tex: {\n            inlineMath: [\n              [\n                '$', '$'\n              ],\n              [\n                '\\\\(', '\\\\)'\n              ]\n            ]\n          },\n          svg: {\n            fontCache: 'global'\n          }\n        };\n      </script>\n    \n  </body>\n</html></head></html>\n",
  "id": "448203f8-53ec-5de9-b2e5-6ef7057413d2",
  "modified": "2026-05-28T13:06:15Z",
  "revisions": [
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-05-28T13:06:15Z",
      "id": "1ca86bf1fad132291ed7a42e4d2afbdd711ddfe8",
      "shortId": "1ca86bf1",
      "subject": "Formatting fixes -- Claude\n",
      "content": "## Installation\n\n    yum install fail2ban\n    chkconfig fail2ban on\n\n## Configuration\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n    [dovecot]\n    enabled  = true\n    filter   = dovecot\n    action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]\n               sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]\n    logpath  = /var/log/maillog\n    maxretry = 10\n    findtime = 1200\n    bantime  = -10\n\nSee [the manual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options) for an explanation of the options. In this configuration, anyone attempting to authenticate unsuccessfully 10 times will be banned permanently.\n\nFail2Ban will try looking for a configuration/filter file called \"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n    [Definition]\n    failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P<host>\\S*),.*\n    ignoreregex =\n\n## Testing\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n    fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf\n\nYou should issue `iptables -L` to verify that there's a Fail2Ban chain. Now `telnet` to the POP3 port from another machine and try logging in with some junk.\n\n    Trying 198.81.129.107...\n    Connected to example.com (198.81.129.107).\n    Escape character is '^]'.\n    +OK Hello. Please be nice.\n    user hahahaha**\n    -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.\n\nYou'll see a bunch of these in `/var/log/maillog`:\n\n    Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107\n\nWhen you see 10 of them, wait a bit. You'll see an email from Fail2Ban informing you that it's blocked an IP. To verify, issue `iptables -L -n`. You'll see this somewhere:\n\n    Chain fail2ban-dovecot (1 references)\n    target     prot opt source               destination\n    DROP       all  --  72.21.81.85        0.0.0.0/0\n\nNice. To unban, just remove the rule from the chain:\n\n    iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP\n\n## Using the Service\n\n    service fail2ban start\n\nCheck its status\n\n    [root@example ~]# service fail2ban status\n    Fail2ban (pid 15919) is running...\n    Status\n    |- Number of jail:  1\n    `- Jail list:       dovecot\n\nYou should have gotten an email from the service with the subject \"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for banned IPs\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-01-13T18:47:28Z",
      "id": "2436477560f26e23d00a24add1cbfeafdca4af78",
      "shortId": "24364775",
      "subject": "No compression\n",
      "content": "Installation\n------------\n\n    yum install fail2ban  \n    chkconfig fail2ban on\n\nConfiguration\n-------------\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n    [dovecot]  \n    enabled  = true  \n    filter   = dovecot  \n    action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]  \n               sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]  \n    logpath  = /var/log/maillog  \n    maxretry = 10  \n    findtime = 1200  \n    bantime  = -10\n\nSee [the manual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options)\nfor an explanation of the options. In this configuration, anyone\nattempting to authenticate unsuccessfully 10 times will be banned\npermanently.\n\nFail2Ban will try looking for a configuration/filter file called\n\"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n    [Definition]  \n    failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P<host>\\S*),.*  \n    ignoreregex =\n\nTesting\n-------\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n    fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf\n\nYou should issue `iptables -L` to verify that there's a Fail2Ban chain.\nNow `telnet` to the POP3 port from another machine and try logging in\nwith some junk.\n\n    Trying 198.81.129.107...  \n    Connected to example.com (198.81.129.107).  \n    Escape character is '^]'.  \n    +OK Hello. Please be nice.  \n    user hahahaha**  \n    -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.\n\nYou'll see a bunch of these in `/var/log/maillog`:\n\n    Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107\n\nWhen you see 10 of them, wait a bit. You'll see an email from Fail2Ban\ninforming you that it's blocked an IP. To verify, issue\n`iptables -L -n`. You'll see this somewhere:\n\n    Chain fail2ban-dovecot (1 references)  \n    target     prot opt source               destination  \n    DROP       all  --  72.21.81.85        0.0.0.0/0\n\nNice. To unban, just remove the rule from the chain:\n\n    iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP\n\nUsing the Service\n-----------------\n\n    service fail2ban start\n\nCheck its status\n\n    [root@example ~]# service fail2ban status  \n    Fail2ban (pid 15919) is running...  \n    Status  \n    |- Number of jail:  1  \n    `- Jail list:       dovecot \n\nYou should have gotten an email from the service with the subject\n\"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for\nbanned IPs\n\n\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-27T07:27:56Z",
      "id": "1aa29105a45aa67523ffb61e73bcc415f935a47e",
      "shortId": "1aa29105",
      "subject": "Fix Markdown conversion\n\nSaw half a season of The Office\n",
      "content": "Installation\n------------\n\n    yum install fail2ban  \n    chkconfig fail2ban on\n\nConfiguration\n-------------\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n    [dovecot]  \n    enabled  = true  \n    filter   = dovecot  \n    action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]  \n               sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]  \n    logpath  = /var/log/maillog  \n    maxretry = 10  \n    findtime = 1200  \n    bantime  = -10\n\nSee [the manual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options)\nfor an explanation of the options. In this configuration, anyone\nattempting to authenticate unsuccessfully 10 times will be banned\npermanently.\n\nFail2Ban will try looking for a configuration/filter file called\n\"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n    [Definition]  \n    failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P<host>\\S*),.*  \n    ignoreregex =\n\nTesting\n-------\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n    fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf\n\nYou should issue `iptables -L` to verify that there's a Fail2Ban chain.\nNow `telnet` to the POP3 port from another machine and try logging in\nwith some junk.\n\n    Trying 198.81.129.107...  \n    Connected to example.com (198.81.129.107).  \n    Escape character is '^]'.  \n    +OK Hello. Please be nice.  \n    user hahahaha**  \n    -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.\n\nYou'll see a bunch of these in `/var/log/maillog`:\n\n    Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107\n\nWhen you see 10 of them, wait a bit. You'll see an email from Fail2Ban\ninforming you that it's blocked an IP. To verify, issue\n`iptables -L -n`. You'll see this somewhere:\n\n    Chain fail2ban-dovecot (1 references)  \n    target     prot opt source               destination  \n    DROP       all  --  72.21.81.85        0.0.0.0/0\n\nNice. To unban, just remove the rule from the chain:\n\n    iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP\n\nUsing the Service\n-----------------\n\n    service fail2ban start\n\nCheck its status\n\n    [root@example ~]# service fail2ban status  \n    Fail2ban (pid 15919) is running...  \n    Status  \n    |- Number of jail:  1  \n    `- Jail list:       dovecot \n\nYou should have gotten an email from the service with the subject\n\"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for\nbanned IPs\n\n\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-21T02:30:47Z",
      "id": "d658e80d1ecb97b196531c7b15a0f9af709c05de",
      "shortId": "d658e80d",
      "subject": "Incremental\n",
      "content": "Installation\n------------\n\n`   yum install fail2ban`  \n`   chkconfig fail2ban on`\n\nConfiguration\n-------------\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n`   [dovecot]`  \n`   enabled  = true`  \n`   filter   = dovecot`  \n`   action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]`  \n`              sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]`  \n`   logpath  = /var/log/maillog`  \n`   maxretry = 10`  \n`   findtime = 1200`  \n`   bantime  = -10`\n\nSee [the\nmanual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options)\nfor an explanation of the options. In this configuration, anyone\nattempting to authenticate unsuccessfully 10 times will be banned\npermanently.\n\nFail2Ban will try looking for a configuration/filter file called\n\"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n`   [Definition]`  \n`   failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P`<host>`\\S*),.*`  \n`   ignoreregex =`\n\nTesting\n-------\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n`   fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf`\n\nYou should issue `iptables -L` to verify that there's a Fail2Ban chain.\nNow `telnet` to the POP3 port from another machine and try logging in\nwith some junk.\n\n`   Trying 198.81.129.107...`  \n`   Connected to example.com (198.81.129.107).`  \n`   Escape character is '^]'.`  \n`   +OK Hello. Please be nice.`  \n`   `**`user` `hahahaha`**  \n`   -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.`\n\nYou'll see a bunch of these in `/var/log/maillog`:\n\n`   Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107`\n\nWhen you see 10 of them, wait a bit. You'll see an email from Fail2Ban\ninforming you that it's blocked an IP. To verify, issue\n`iptables -L -n`. You'll see this somewhere:\n\n`   Chain fail2ban-dovecot (1 references)`  \n`   target     prot opt source               destination`  \n`   DROP       all  --  72.21.81.85        0.0.0.0/0`\n\nNice. To unban, just remove the rule from the chain:\n\n`   iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP`\n\nUsing the Service\n-----------------\n\n`   service fail2ban start`\n\nCheck its status\n\n`   [root@example ~]# service fail2ban status`  \n`   Fail2ban (pid 15919) is running...`  \n`   Status`  \n`   |- Number of jail:  1`  \n``    `- Jail list:       dovecot ``\n\nYou should have gotten an email from the service with the subject\n\"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for\nbanned IPs\n\n\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-20T19:56:35Z",
      "id": "9d7ba8bb8870e1d9afa51436c52f2a0335cfaaa3",
      "shortId": "9d7ba8bb",
      "subject": "Fail2Ban for Dovecot : v2\n",
      "content": "Installation\n------------\n\n`   yum install fail2ban`  \n`   chkconfig fail2ban on`\n\nConfiguration\n-------------\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n`   [dovecot]`  \n`   enabled  = true`  \n`   filter   = dovecot`  \n`   action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]`  \n`              sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]`  \n`   logpath  = /var/log/maillog`  \n`   maxretry = 10`  \n`   findtime = 1200`  \n`   bantime  = -10`\n\nSee [the\nmanual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options)\nfor an explanation of the options. In this configuration, anyone\nattempting to authenticate unsuccessfully 10 times will be banned\npermanently.\n\nFail2Ban will try looking for a configuration/filter file called\n\"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n`   [Definition]`  \n`   failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P`<host>`\\S*),.*`  \n`   ignoreregex =`\n\nTesting\n-------\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n`   fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf`\n\nYou should issue `iptables -L` to verify that there's a Fail2Ban chain.\nNow `telnet` to the POP3 port from another machine and try logging in\nwith some junk.\n\n`   Trying 198.81.129.107...`  \n`   Connected to example.com (198.81.129.107).`  \n`   Escape character is '^]'.`  \n`   +OK Hello. Please be nice.`  \n`   `**`user` `hahahaha`**  \n`   -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.`\n\nYou'll see a bunch of these in `/var/log/maillog`:\n\n`   Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107`\n\nWhen you see 10 of them, wait a bit. You'll see an email from Fail2Ban\ninforming you that it's blocked an IP. To verify, issue\n`iptables -L -n`. You'll see this somewhere:\n\n`   Chain fail2ban-dovecot (1 references)`  \n`   target     prot opt source               destination`  \n`   DROP       all  --  72.21.81.85        0.0.0.0/0`\n\nNice. To unban, just remove the rule from the chain:\n\n`   iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP`\n\nUsing the Service\n-----------------\n\n`   service fail2ban start`\n\nCheck its status\n\n`   [root@example ~]# service fail2ban status`  \n`   Fail2ban (pid 15919) is running...`  \n`   Status`  \n`   |- Number of jail:  1`  \n``    `- Jail list:       dovecot ``\n\nYou should have gotten an email from the service with the subject\n\"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for\nbanned IPs\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Installation Logs](Category:_Installation_Logs \"wikilink\")\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-20T19:56:34Z",
      "id": "9f6890c3ac421eb5f798e66bf20297240036e7bf",
      "shortId": "9f6890c3",
      "subject": "Fail2Ban for Dovecot : First Draft\n",
      "content": "Installation\n------------\n\n`   yum install fail2ban`  \n`   chkconfig fail2ban on`\n\nConfiguration\n-------------\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n`   [dovecot]`  \n`   enabled  = true`  \n`   filter   = dovecot`  \n`   action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]`  \n`              sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]`  \n`   logpath  = /var/log/maillog`  \n`   maxretry = 10`  \n`   findtime = 1200`  \n`   bantime  = -10`\n\nSee [the\nmanual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options)\nfor an explanation of the options. In this configuration, anyone\nattempting to authenticate unsuccessfully 10 times will be banned\npermanently.\n\nFail2Ban will try looking for a configuration/filter file called\n\"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n`   [Definition]`  \n`   failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P`<host>`\\S*),.*`  \n`   ignoreregex =`\n\nTesting\n-------\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n`   fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf`\n\nUsing the Service\n-----------------\n\n`   service fail2ban start`\n\nCheck its status\n\n`   [root@example ~]# service fail2ban status`  \n`   Fail2ban (pid 15919) is running...`  \n`   Status`  \n`   |- Number of jail:  1`  \n``    `- Jail list:       dovecot ``\n\nYou should have gotten an email from the service with the subject\n\"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for\nbanned IPs\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Installation Logs](Category:_Installation_Logs \"wikilink\")\n"
    }
  ],
  "sizeInBytes": 2823,
  "source": "## Installation\n\n    yum install fail2ban\n    chkconfig fail2ban on\n\n## Configuration\n\nNow add this to `/etc/fail2ban/jail.conf`. Change the `sender` email.\n\n    [dovecot]\n    enabled  = true\n    filter   = dovecot\n    action   = iptables-multiport[name=dovecot, port=\"pop3,pop3s,imap,imaps\", protocol=tcp]\n               sendmail-whois[name=dovecot, dest=root, sender=fail2ban@example.com]\n    logpath  = /var/log/maillog\n    maxretry = 10\n    findtime = 1200\n    bantime  = -10\n\nSee [the manual](http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Jail_Options) for an explanation of the options. In this configuration, anyone attempting to authenticate unsuccessfully 10 times will be banned permanently.\n\nFail2Ban will try looking for a configuration/filter file called \"`dovecot.conf`\" in the filters directory, `/etc/fail2ban/filters.d`.\nCreate it and add this if it doesn't exist for some reason:\n\n    [Definition]\n    failregex = .*(?:pop3-login|imap-login):.*(?:Authentication failure|Aborted login \\(auth failed|Aborted login \\(tried to use disabled|Disconnected \\(auth failed).*rip=(?P<host>\\S*),.*\n    ignoreregex =\n\n## Testing\n\nFail2Ban comes with a handy-dandy regex testing tool.\n\n    fail2ban-regex /vaar/log/maillog /etc/fail2ban/filter.d/dovecot.conf\n\nYou should issue `iptables -L` to verify that there's a Fail2Ban chain. Now `telnet` to the POP3 port from another machine and try logging in with some junk.\n\n    Trying 198.81.129.107...\n    Connected to example.com (198.81.129.107).\n    Escape character is '^]'.\n    +OK Hello. Please be nice.\n    user hahahaha**\n    -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.\n\nYou'll see a bunch of these in `/var/log/maillog`:\n\n    Sep 17 15:05:14 user dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=72.21.81.85, lip=198.81.129.107\n\nWhen you see 10 of them, wait a bit. You'll see an email from Fail2Ban informing you that it's blocked an IP. To verify, issue `iptables -L -n`. You'll see this somewhere:\n\n    Chain fail2ban-dovecot (1 references)\n    target     prot opt source               destination\n    DROP       all  --  72.21.81.85        0.0.0.0/0\n\nNice. To unban, just remove the rule from the chain:\n\n    iptables -D fail2ban-dovecot -s 72.21.81.85 -j DROP\n\n## Using the Service\n\n    service fail2ban start\n\nCheck its status\n\n    [root@example ~]# service fail2ban status\n    Fail2ban (pid 15919) is running...\n    Status\n    |- Number of jail:  1\n    `- Jail list:       dovecot\n\nYou should have gotten an email from the service with the subject \"**\\[Fail2Ban\\] dovecot: started**\". Check `/var/log/messages` for banned IPs\n",
  "title": "Fail2Ban for Dovecot",
  "untracked": false,
  "uri": "/Fail2Ban_for_Dovecot",
  "relativePath": "Fail2Ban for Dovecot.md"
}
