{"id":357,"date":"2019-05-14T14:32:23","date_gmt":"2019-05-14T14:32:23","guid":{"rendered":"https:\/\/blog.iabsolute.com\/?p=357"},"modified":"2019-05-14T14:32:23","modified_gmt":"2019-05-14T21:32:23","slug":"fail2ban-install-on-fedora-9","status":"publish","type":"post","link":"https:\/\/blog.iabsolute.com\/?p=357","title":{"rendered":"fail2ban install on fedora 9"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Preventing Brute Force Attacks With Fail2ban On Fedora 9<\/h2>\n\n\n\n<p>Version 1.0<br>\nAuthor: Falko Timme &lt;ft [at] falkotimme [dot] com&gt;<br>\nLast edited 08\/08\/2008<\/p>\n\n\n\n<p>In this article I will show how to install and configure <a href=\"http:\/\/www.fail2ban.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">fail2ban<\/a> on a Fedora 9 system. Fail2ban is a tool that observes login attempts to various services, e.g. SSH, FTP, SMTP, Apache, etc., and if it finds failed login attempts again and again from the same IP address or host, fail2ban stops further login attempts from that IP address\/host by blocking it with an iptables firewall rule.<\/p>\n\n\n\n<p>This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1 Preliminary Note<\/h3>\n\n\n\n<p>Fail2ban is similar to <a href=\"http:\/\/denyhosts.sourceforge.net\/\" target=\"_blank\" rel=\"noreferrer noopener\">DenyHosts<\/a> which I covered in this tutorial: <a href=\"http:\/\/www.howtoforge.com\/preventing_ssh_dictionary_attacks_with_denyhosts\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.howtoforge.com\/preventing_ssh_dictionary_attacks_with_denyhosts<\/a>, but unlike DenyHosts which focuses on SSH, fail2ban can be configured to monitor any service that writes login attempts to a log file, and instead of using \/etc\/hosts.deny only to block IP addresses\/hosts, fail2ban can use iptables and \/etc\/hosts.deny.<\/p>\n\n\n\n<p>In this example I will configure fail2ban to monitor login attempts to the SSH server, the Proftpd server, login attempts to .htaccess\/.htpasswd protected web sites, to Courier POP3 and Courier IMAP, and to SASL (for sending emails). I will install the fail2ban package that is available for Fedora 9. It comes with a default configuration, but unfortunately that configuration doesn\u2019t quite work for most of the aforementioned services. Therefore I will create a customized fail2ban configuration that I have tested and that works for me.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2 Installing fail2ban<\/h3>\n\n\n\n<p>Fail2ban can be installed as follows:<\/p>\n\n\n\n<p>yum install fail2ban<\/p>\n\n\n\n<p>Then we must create the system startup links for fail2ban and start it:<\/p>\n\n\n\n<p>chkconfig \u2013levels 235 fail2ban on<br>\n\/etc\/init.d\/fail2ban start<\/p>\n\n\n\n<p>You will find all fail2ban configuration files in the \/etc\/fail2ban directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3 Configuring fail2ban<\/h3>\n\n\n\n<p>The default behaviour of fail2ban is configured in the file \/etc\/fail2ban\/jail.conf. Take a look at it, it\u2019s not hard to understand. There\u2019s a [DEFAULT] section that applies to all other sections unless the default options are overriden in the other sections.<\/p>\n\n\n\n<p>I explain some of the configuration options here:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ignoreip: This is a space-separated list of IP addresses that cannot be blocked by fail2ban. For example, if the computer from which you\u2019re connecting to the server has a static IP address, you might want to list it here.<\/li><li>bantime: Time in seconds that a host is blocked if it was caught by fail2ban (600 seconds = 10 minutes).<\/li><li>maxretry: Max. number of failed login attempts before a host is blocked by fail2ban.<\/li><li>filter: Refers to the appropriate filter file in \/etc\/fail2ban\/filter.d.<\/li><li>action: Refers to the appropriate action file in \/etc\/fail2ban\/action.d.<\/li><li>logpath: The log file that fail2ban checks for failed login attempts.<\/li><\/ul>\n\n\n\n<p>This is what my \/etc\/fail2ban\/jail.conf file looks like:<\/p>\n\n\n\n<p>vi \/etc\/fail2ban\/jail.conf<\/p>\n\n\n\n<p>\u2013<\/p>\n\n\n\n<p># Fail2Ban configuration file<br>\n#<br>\n# Author: Cyril Jaquier<br>\n#<br>\n# $Revision: 617 $<br>\n#<\/p>\n\n\n\n<p># The DEFAULT allows a global definition of the options. They can be override<br>\n# in each jail afterwards.<\/p>\n\n\n\n<p>[DEFAULT]<\/p>\n\n\n\n<p># \u201cignoreip\u201d can be an IP address, a CIDR mask or a DNS host. Fail2ban will not<br>\n# ban a host which matches an address in this list. Several addresses can be<br>\n# defined using space separator.<br>\nignoreip = 127.0.0.1 192.168.0.99<\/p>\n\n\n\n<p># \u201cbantime\u201d is the number of seconds that a host is banned.<br>\nbantime&nbsp; = 600<\/p>\n\n\n\n<p># A host is banned if it has generated \u201cmaxretry\u201d during the last \u201cfindtime\u201d<br>\n# seconds.<br>\nfindtime&nbsp; = 600<\/p>\n\n\n\n<p># \u201cmaxretry\u201d is the number of failures before a host get banned.<br>\nmaxretry = 3<\/p>\n\n\n\n<p># \u201cbackend\u201d specifies the backend used to get files modification. Available<br>\n# options are \u201cgamin\u201d, \u201cpolling\u201d and \u201cauto\u201d. This option can be overridden in<br>\n# each jail too (use \u201cgamin\u201d for a jail and \u201cpolling\u201d for another).<br>\n#<br>\n# gamin:&nbsp;&nbsp; requires Gamin (a file alteration monitor) to be installed. If Gamin<br>\n#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is not installed, Fail2ban will use polling.<br>\n# polling: uses a polling algorithm which does not require external libraries.<br>\n# auto:&nbsp;&nbsp;&nbsp; will choose Gamin if available and polling otherwise.<br>\nbackend = auto<\/p>\n\n\n\n<p>[ssh-iptables]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nfilter&nbsp;&nbsp; = sshd<br>\naction&nbsp;&nbsp; = iptables[name=SSH, port=ssh, protocol=tcp]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=SSH, dest=you@mail.com, sender=fail2ban@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nmaxretry = 5<\/p>\n\n\n\n<p>[proftpd-iptables]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nfilter&nbsp;&nbsp; = proftpd<br>\naction&nbsp;&nbsp; = iptables[name=ProFTPD, port=ftp, protocol=tcp]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=ProFTPD, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nmaxretry = 6<\/p>\n\n\n\n<p>[sasl-iptables]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nfilter&nbsp;&nbsp; = sasl<br>\nbackend&nbsp; = polling<br>\naction&nbsp;&nbsp; = iptables[name=sasl, port=smtp, protocol=tcp]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=sasl, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/maillog<\/p>\n\n\n\n<p>[apache-tcpwrapper]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nfilter&nbsp;&nbsp; = apache-auth<br>\naction&nbsp;&nbsp; = hostsdeny<br>\nlogpath&nbsp; = \/var\/log\/httpd\/*error_log<br>\nmaxretry = 6<\/p>\n\n\n\n<p>[postfix-tcpwrapper]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nfilter&nbsp;&nbsp; = postfix<br>\naction&nbsp;&nbsp; = hostsdeny<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail[name=Postfix, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/maillog<br>\nbantime&nbsp; = 300<\/p>\n\n\n\n<p>[courierpop3]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nport&nbsp;&nbsp;&nbsp;&nbsp; = pop3<br>\nfilter&nbsp;&nbsp; = courierlogin<br>\naction&nbsp;&nbsp; = iptables[name=%(__name__)s, port=%(port)s]<br>\nlogpath&nbsp; = \/var\/log\/maillog<br>\nmaxretry = 5<\/p>\n\n\n\n<p>[courierimap]<\/p>\n\n\n\n<p>enabled&nbsp; = true<br>\nport&nbsp;&nbsp;&nbsp;&nbsp; = imap2<br>\nfilter&nbsp;&nbsp; = courierlogin<br>\naction&nbsp;&nbsp; = iptables[name=%(__name__)s, port=%(port)s]<br>\nlogpath&nbsp; = \/var\/log\/maillog<br>\nmaxretry = 5<\/p>\n\n\n\n<p>[ssh-tcpwrapper]<\/p>\n\n\n\n<p>enabled&nbsp;&nbsp;&nbsp;&nbsp; = false<br>\nfilter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = sshd<br>\naction&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = hostsdeny<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=SSH, dest=you@mail.com]<br>\nignoreregex = for myuser from<br>\nlogpath&nbsp;&nbsp;&nbsp;&nbsp; = \/var\/log\/secure<\/p>\n\n\n\n<p>[vsftpd-notification]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = vsftpd<br>\naction&nbsp;&nbsp; = sendmail-whois[name=VSFTPD, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nmaxretry = 5<br>\nbantime&nbsp; = 1800<\/p>\n\n\n\n<p>[vsftpd-iptables]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = vsftpd<br>\naction&nbsp;&nbsp; = iptables[name=VSFTPD, port=ftp, protocol=tcp]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=VSFTPD, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nmaxretry = 5<br>\nbantime&nbsp; = 1800<\/p>\n\n\n\n<p>[apache-badbots]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = apache-badbots<br>\naction&nbsp;&nbsp; = iptables-multiport[name=BadBots, port=&#8221;http,https&#8221;]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-buffered[name=BadBots, lines=5, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/httpd\/*access_log<br>\nbantime&nbsp; = 172800<br>\nmaxretry = 1<\/p>\n\n\n\n<p>[apache-shorewall]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = apache-noscript<br>\naction&nbsp;&nbsp; = shorewall<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail[name=Apache, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/httpd\/error_log<\/p>\n\n\n\n<p>[ssh-ipfw]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = sshd<br>\naction&nbsp;&nbsp; = ipfw[localhost=192.168.0.1]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=&#8221;SSH,IPFW&#8221;, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nignoreip = 168.192.0.1<\/p>\n\n\n\n<p>[named-refused-udp]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = named-refused<br>\naction&nbsp;&nbsp; = iptables-multiport[name=Named, port=&#8221;domain,953&#8243;, protocol=udp]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=Named, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nignoreip = 168.192.0.1<\/p>\n\n\n\n<p>[named-refused-tcp]<\/p>\n\n\n\n<p>enabled&nbsp; = false<br>\nfilter&nbsp;&nbsp; = named-refused<br>\naction&nbsp;&nbsp; = iptables-multiport[name=Named, port=&#8221;domain,953&#8243;, protocol=tcp]<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendmail-whois[name=Named, dest=you@mail.com]<br>\nlogpath&nbsp; = \/var\/log\/secure<br>\nignoreip = 168.192.0.1<\/p>\n\n\n\n<p>\u2013<\/p>\n\n\n\n<p>My client computer has the static IP address 192.168.0.99, and because I don\u2019t want to be locked out, I\u2019ve added it to the ignoreip list.<\/p>\n\n\n\n<p>I want to control login attempts to SSH, Apache, Proftpd, Courier-POP3, Courier-IMAP, and Sasl, so I\u2019ve set enabled to true for these services and to false for all other services. Please note that some services such as SSH can be blocked either by iptables or by TCPWrappers (\/etc\/hosts.deny). Decide for yourself which method you prefer.<\/p>\n\n\n\n<p>Make sure to replace the email address you@mail.com with your own email address so that you get notified when someone gets blocked by fail2ban.<\/p>\n\n\n\n<p>If you compare the file with the default \/etc\/fail2ban\/jail.conf, you\u2019ll also notice that I\u2019ve changed some log files because the log files in the default \/etc\/fail2ban\/jail.conf are not correct for Fedora 9.<\/p>\n\n\n\n<p>Whenever we modify the fail2ban configuration, we must restart fail2ban, so this is what we do now:<\/p>\n\n\n\n<p>\/etc\/init.d\/fail2ban restart<\/p>\n\n\n\n<p>That\u2019s it already. Fail2ban logs to \/var\/log\/fail2ban.log, so you can check that file to find out if\/what hosts got blocked. If a host got blocked by fail2ban, it looks like this:<\/p>\n\n\n\n<p>2008-08-08 17:49:09,466 fail2ban.actions: WARNING [apache-tcpwrapper] Ban 1.2.3.4<br>\n2008-08-08 18:08:33,213 fail2ban.actions: WARNING [sasl-iptables] Ban 1.2.3.4<br>\n2008-08-08 18:26:37,769 fail2ban.actions: WARNING [courierlogin] Ban 1.2.3.4<br>\n2008-08-08 18:39:06,765 fail2ban.actions: WARNING [courierimap] Ban 1.2.3.4<\/p>\n\n\n\n<p>You can also check your firewall to see if any hosts are currently blocked. Simply run<\/p>\n\n\n\n<p>iptables -L<\/p>\n\n\n\n<p>For services that use TCPWrappers to block hosts, take a look at \/etc\/hosts.deny.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Links<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Fail2ban: <a href=\"http:\/\/www.fail2ban.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.fail2ban.org<\/a><\/li><li>Fedora: <a href=\"http:\/\/fedoraproject.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/fedoraproject.org<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Preventing Brute Force Attacks With Fail2ban On Fedora 9 Version 1.0 Author: Falko Timme &lt;ft [at] falkotimme [dot] com&gt; Last edited 08\/08\/2008 In this article I will show how to install and configure fail2ban on a Fedora 9 system. Fail2ban &hellip; <a href=\"https:\/\/blog.iabsolute.com\/?p=357\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-fail2ban"],"_links":{"self":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":1,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":358,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions\/358"}],"wp:attachment":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}