<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://alteeve.com/w/index.php?action=history&amp;feed=atom&amp;title=HOWTO_fail2ban</id>
	<title>HOWTO fail2ban - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://alteeve.com/w/index.php?action=history&amp;feed=atom&amp;title=HOWTO_fail2ban"/>
	<link rel="alternate" type="text/html" href="https://alteeve.com/w/index.php?title=HOWTO_fail2ban&amp;action=history"/>
	<updated>2026-05-03T01:28:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://alteeve.com/w/index.php?title=HOWTO_fail2ban&amp;diff=6882&amp;oldid=prev</id>
		<title>Nyz: /* TL;DR - Configuring fail2ban from a fresh install */</title>
		<link rel="alternate" type="text/html" href="https://alteeve.com/w/index.php?title=HOWTO_fail2ban&amp;diff=6882&amp;oldid=prev"/>
		<updated>2016-06-06T19:07:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;TL;DR - Configuring fail2ban from a fresh install&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:07, 6 June 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l55&quot;&gt;Line 55:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 55:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==TL;DR - Configuring fail2ban from a fresh install==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==TL;DR - Configuring fail2ban from a fresh install==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Copy any pre-written jails out of jail.conf and into an appropriately named jail.d/*.conf file&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Add &lt;/ins&gt;&quot;enable = true&quot; to each &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;relevant entry in &lt;/ins&gt;jail.conf.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# add &lt;/del&gt;&quot;enable = true&quot; to each jail.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;d/ &lt;/del&gt;conf &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;file&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# (Optional) Edit fail2ban.conf and change logtarget to /var/log/fail2ban.log, if you want fail2ban to log to it&amp;#039;s own file rather than syslog.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# (Optional) Edit fail2ban.conf and change logtarget to /var/log/fail2ban.log, if you want fail2ban to log to it&amp;#039;s own file rather than syslog.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Create the file jail&lt;/del&gt;.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;d/customisation.local&lt;/del&gt;, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;add &lt;/del&gt;the line &quot;ignoreip = $trustedIPs&quot;. This is critical, to prevent locking yourself out.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Edit fail2ban&lt;/ins&gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;conf&lt;/ins&gt;, &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;change &lt;/ins&gt;the line &quot;ignoreip = $trustedIPs&quot;. This is critical, to prevent locking yourself out.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# /etc/init.d/fail2ban start&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# /etc/init.d/fail2ban start&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key an_wiki-mediawiki-:diff:1.41:old-6876:rev-6882:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Nyz</name></author>
	</entry>
	<entry>
		<id>https://alteeve.com/w/index.php?title=HOWTO_fail2ban&amp;diff=6876&amp;oldid=prev</id>
		<title>Nyz: Created page with &quot;{{howto_header}}  Fail2ban is a package available in the EPEL repository. It provides a mechanism to ban access via iptables to any service that have log files available to be...&quot;</title>
		<link rel="alternate" type="text/html" href="https://alteeve.com/w/index.php?title=HOWTO_fail2ban&amp;diff=6876&amp;oldid=prev"/>
		<updated>2016-06-02T21:11:25Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{howto_header}}  Fail2ban is a package available in the EPEL repository. It provides a mechanism to ban access via iptables to any service that have log files available to be...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Páàjì titun&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{howto_header}}&lt;br /&gt;
&lt;br /&gt;
Fail2ban is a package available in the EPEL repository. It provides a mechanism to ban access via iptables to any service that have log files available to be grepped.&lt;br /&gt;
&lt;br /&gt;
The advantage of using Fail2ban over no intrusion prevention is that brute force or denial-of-service attacks are more easily countered, and are done so in an automated fashion. The advantages of fail2ban over a solution such as denyhosts is twofold:&lt;br /&gt;
# It uses iptables rather than the /etc/hosts.deny file, which allows for a broader level of scripting for response actions, as well as more flexibility in ban listing&lt;br /&gt;
# fail2ban can look at a large number of different logfiles for various services, from SQL databases and httpd-secure, to ssh and whatever else you might have. Denyhosts is solely focused on ssh. &lt;br /&gt;
&lt;br /&gt;
=Installation=&lt;br /&gt;
&lt;br /&gt;
Easy peasy on any Centos/RHEL 6.x machine.&lt;br /&gt;
&lt;br /&gt;
 yum install epel-release &amp;amp;&amp;amp; yum clean all&lt;br /&gt;
&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
 yum install fail2ban&lt;br /&gt;
&lt;br /&gt;
=Configuration=&lt;br /&gt;
&lt;br /&gt;
The typical fail2ban installation tree looks something like this:&lt;br /&gt;
&lt;br /&gt;
 (source: http://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Configuration)&lt;br /&gt;
 /etc/fail2ban/&lt;br /&gt;
 ├── action.d&lt;br /&gt;
 │   ├── dummy.conf&lt;br /&gt;
 │   ├── hostsdeny.conf&lt;br /&gt;
 │   ├── iptables.conf&lt;br /&gt;
 │   ├── mail-whois.conf&lt;br /&gt;
 │   ├── mail.conf&lt;br /&gt;
 │   └── shorewall.conf&lt;br /&gt;
 ├── fail2ban.conf&lt;br /&gt;
 ├── fail2ban.local&lt;br /&gt;
 ├── filter.d&lt;br /&gt;
 │   ├── apache-auth.conf&lt;br /&gt;
 │   ├── apache-noscript.conf&lt;br /&gt;
 │   ├── couriersmtp.conf&lt;br /&gt;
 │   ├── postfix.conf&lt;br /&gt;
 │   ├── proftpd.conf&lt;br /&gt;
 │   ├── qmail.conf&lt;br /&gt;
 │   ├── sasl.conf&lt;br /&gt;
 │   ├── sshd.conf&lt;br /&gt;
 │   └── vsftpd.conf&lt;br /&gt;
 ├── jail.conf&lt;br /&gt;
 └── jail.local&lt;br /&gt;
&lt;br /&gt;
 NOTE: fail2ban by default looks for and uses &amp;#039;.local&amp;#039; files over &amp;#039;.conf&amp;#039; files in /etc/fail2ban/. It assumes that if a .local exists, that .conf is used as the &amp;#039;default&amp;#039; file provided by the rpm, and is being retained for reference. If no &amp;#039;.local&amp;#039; exists, .conf is used.&lt;br /&gt;
&lt;br /&gt;
Key files to note are:&lt;br /&gt;
* fail2ban.local	- General settings&lt;br /&gt;
* jail.local 		- &amp;#039;Jail&amp;#039; settings, where services to be monitored are enabled&lt;br /&gt;
* filter.d/		- Contains the files which define the regex calls to run on target logfiles. Any jail must have a corrosponding file here.&lt;br /&gt;
* jail.d/		- A folder for jail settings, an alternative and frankly better method than managing a jail.local file.&lt;br /&gt;
&lt;br /&gt;
==TL;DR - Configuring fail2ban from a fresh install==&lt;br /&gt;
&lt;br /&gt;
# Copy any pre-written jails out of jail.conf and into an appropriately named jail.d/*.conf file&lt;br /&gt;
# add &amp;quot;enable = true&amp;quot; to each jail.d/ conf file.&lt;br /&gt;
# (Optional) Edit fail2ban.conf and change logtarget to /var/log/fail2ban.log, if you want fail2ban to log to it&amp;#039;s own file rather than syslog.&lt;br /&gt;
# Create the file jail.d/customisation.local, add the line &amp;quot;ignoreip = $trustedIPs&amp;quot;. This is critical, to prevent locking yourself out.&lt;br /&gt;
# /etc/init.d/fail2ban start&lt;br /&gt;
&lt;br /&gt;
=Management=&lt;br /&gt;
&lt;br /&gt;
==Frequently Used Commands==&lt;br /&gt;
&lt;br /&gt;
Fail2ban management can be done entirely via textfiles (namely your logfiles and iptables), but life is made infinitely easier by using the built in commands.&lt;br /&gt;
&lt;br /&gt;
These commands are:&lt;br /&gt;
* fail2ban-client&lt;br /&gt;
* fail2ban-server&lt;br /&gt;
And, though not part of the fail2ban package, a primary method of looking at what IPs have currently been banned:&lt;br /&gt;
* iptables -L&lt;br /&gt;
&lt;br /&gt;
==What&amp;#039;s been banned?==&lt;br /&gt;
&lt;br /&gt;
For the most part, fail2ban operates through denying access from an ip via iptables. It does this through a series of chained iptables rulesets, one per active jail.&lt;br /&gt;
Conceptually, the logic looks something like:&lt;br /&gt;
 Incoming packets&lt;br /&gt;
 └── jail 1&lt;br /&gt;
     └── bans from jail1 get dropped, else return to main chain&lt;br /&gt;
 └── jail 2&lt;br /&gt;
     └── drop any more bans, then return&lt;br /&gt;
 └── the rest of your iptables setup. &lt;br /&gt;
&lt;br /&gt;
 Note: But what about IPs we trust? Fail2ban can be set up to IGNORE trusted IPs. Those IPs, CIDR addresses, URLs, etc, will /never/ be jailed.&lt;br /&gt;
&lt;br /&gt;
The actual iptables rules are beyond the scope of a howto document, and are covered in the fail2ban documentation found at TODO&lt;br /&gt;
&lt;br /&gt;
So, how do we see what&amp;#039;s actually been banned? The simplest method is simply to run &amp;quot;iptables -L&amp;quot;.&lt;br /&gt;
Scroll through the various jales, and you&amp;#039;ll see any banned hosts listed there.&lt;br /&gt;
&lt;br /&gt;
==Managing bans==&lt;br /&gt;
&lt;br /&gt;
Unbanning IPs (say, if you forgot your password) can be managed through the fail2ban-client command&lt;br /&gt;
&lt;br /&gt;
 fail2ban-client set &amp;lt;jail&amp;gt; unbanip x.x.x.x&lt;/div&gt;</summary>
		<author><name>Nyz</name></author>
	</entry>
</feed>