This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
networking:linux:fail2ban [2012/06/04 11:12] gcooper |
networking:linux:fail2ban [2017/03/15 08:51] (current) gcooper |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Fail2Ban ====== | ====== Fail2Ban ====== | ||
- | | + | https:// |
+ | |||
+ | | ||
* Fail2Ban is modular in nature so it's easy to get it configured one module at a time. | * Fail2Ban is modular in nature so it's easy to get it configured one module at a time. | ||
* Fail2Ban runs as a daemon and bans an IP address after too many failed login attempts. | * Fail2Ban runs as a daemon and bans an IP address after too many failed login attempts. | ||
Line 8: | Line 10: | ||
See also **[[networking: | See also **[[networking: | ||
- | ===== Installation | + | ===== Installation ===== |
- | [[computing: | + | Fail2Ban is available from either |
- | < | + | See also **[[computing: |
- | yum install fail2ban --enablerepo=epel | + | |
- | </ | + | |
- | ===== Installation on Centos 5 ===== | + | See also **[[computing: |
- | < | + | Install Fail2Ban |
- | wget http:// | + | |
- | tar -xjvf fail2ban-0.8.1.tar.bz2 | + | |
- | cd fail2ban-0.8.1 | + | |
- | python setup.py install | + | |
- | </ | + | |
- | + | ||
- | ===== Installation on SME 7 ===== | + | |
- | + | ||
- | NEEDS Python 2.4!! (NOT CURRENTLY AVAILABLE) | + | |
- | + | ||
- | (SME 7 uses / | + | |
- | + | ||
- | ===== Startup ===== | + | |
- | + | ||
- | If you installed from the tarball, run these two commands. | + | |
< | < | ||
- | cp files/ | + | yum install |
- | chkconfig | + | |
</ | </ | ||
- | Then: | + | ===== Configuration ===== |
- | < | + | Fail2ban is designed so that you can edit local copies of the primary configuration files so they will never be stepped |
- | chkconfig fail2ban | + | |
- | service fail2ban start | + | |
- | </ | + | |
- | ===== Tools ===== | + | * ''/ |
- | + | * overrides '' | |
- | This shows failed SSH logins by date: | + | * ''/ |
+ | * overrides '' | ||
< | < | ||
- | cat /var/log/secure* | grep ' | + | cp -a /etc/fail2ban/jail.conf / |
+ | cp -a / | ||
</ | </ | ||
- | Search for correct log file: | + | ==== Configure defaults in jail.local ==== |
- | < | + | Add your own IP ranges to keep from getting locked out yourself. |
- | grep such / | + | |
- | grep ftp / | + | |
- | grep -r NOQUEUE /var/log | + | |
- | </ | + | |
- | + | ||
- | This should match Postfix bans: | + | |
< | < | ||
- | grep rejected | + | vi /etc/fail2ban/jail.local |
- | </ | + | |
- | ===== Testing ===== | + | [DEFAULT] |
- | + | ignoreip | |
- | < | + | |
- | fail2ban-regex | + | |
</ | </ | ||
- | ===== Configuration | + | ===== Startup |
- | Fail2ban is designed so that you can edit local copies of the primary configuration files so they will never be stepped on by an update. | + | Enable Fail2Ban to start up automatically and start the service: |
- | + | ||
- | * / | + | |
- | * overrides fail2ban.conf | + | |
- | * / | + | |
- | * overrides jail.conf | + | |
< | < | ||
- | vim /etc/fail2ban/jail.conf | + | chkconfig |
- | </ | + | service fail2ban start |
- | + | ||
- | Enable SSH and ProFTP. | + | |
- | + | ||
- | Add your own IP ranges to keep from getting locked out yourself. | + | |
- | + | ||
- | < | + | |
- | [DEFAULT] | + | |
- | ignoreip = 127.0.0.1 209.193.64.0/ | + | |
</ | </ | ||
Line 124: | Line 85: | ||
# Don't know how well other backend options work. | # Don't know how well other backend options work. | ||
backend = polling | backend = polling | ||
+ | |||
+ | [apache-denied] | ||
+ | |||
+ | enabled | ||
+ | filter | ||
+ | action | ||
+ | # sendmail-whois[name=Denied, | ||
+ | logpath | ||
+ | maxretry | ||
+ | bantime | ||
+ | |||
+ | [apache-postflood] | ||
+ | |||
+ | enabled | ||
+ | filter | ||
+ | action | ||
+ | | ||
+ | logpath | ||
+ | findtime = 10 | ||
+ | maxretry = 10 | ||
+ | bantime | ||
[ssh-iptables] | [ssh-iptables] | ||
Line 168: | Line 150: | ||
[apache-badbots] | [apache-badbots] | ||
- | enabled | + | enabled |
filter | filter | ||
action | action | ||
| | ||
- | logpath | + | logpath |
+ | / | ||
/ | / | ||
/ | / | ||
maxretry = 1 | maxretry = 1 | ||
+ | bantime | ||
</ | </ | ||
Line 260: | Line 244: | ||
# Values: | # Values: | ||
# | # | ||
+ | </ | ||
+ | |||
+ | ===== Troubleshooting ===== | ||
+ | |||
+ | **Correctly count login failures**: http:// | ||
+ | |||
+ | < | ||
+ | sudo sed -i ' | ||
+ | sudo service rsyslog restart | ||
+ | sudo service fail2ban restart | ||
+ | </ | ||
+ | |||
+ | :!: If you can test a filter successfully with '' | ||
+ | |||
+ | This shows failed SSH logins by date: | ||
+ | |||
+ | CentOS/ | ||
+ | |||
+ | < | ||
+ | cat / | ||
+ | </ | ||
+ | |||
+ | Debian/ | ||
+ | |||
+ | < | ||
+ | cat / | ||
+ | </ | ||
+ | |||
+ | Search for correct log file: | ||
+ | |||
+ | < | ||
+ | grep such / | ||
+ | grep ftp / | ||
+ | grep -r NOQUEUE /var/log | ||
+ | </ | ||
+ | |||
+ | This should match Postfix bans: | ||
+ | |||
+ | < | ||
+ | grep rejected / | ||
+ | </ | ||
+ | |||
+ | ===== Testing ===== | ||
+ | |||
+ | Count of banned IP addresses: | ||
+ | |||
+ | < | ||
+ | iptables -nL |grep " | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | fail2ban-regex / | ||
</ | </ | ||