This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
networking:linux:fail2ban [2013/09/25 18:35] gcooper |
networking:linux:fail2ban [2017/03/15 08:51] (current) gcooper |
||
---|---|---|---|
Line 22: | Line 22: | ||
< | < | ||
yum install fail2ban --enablerepo=epel | yum install fail2ban --enablerepo=epel | ||
- | </ | ||
- | |||
- | ===== Startup ===== | ||
- | |||
- | Enable Fail2Ban to start up automatically and start the service: | ||
- | |||
- | < | ||
- | chkconfig fail2ban on | ||
- | service fail2ban start | ||
- | </ | ||
- | |||
- | ===== Tools ===== | ||
- | |||
- | This shows failed SSH logins by date: | ||
- | |||
- | < | ||
- | cat / | ||
- | </ | ||
- | |||
- | Search for correct log file: | ||
- | |||
- | < | ||
- | grep such / | ||
- | grep ftp / | ||
- | grep -r NOQUEUE /var/log | ||
- | </ | ||
- | |||
- | This should match Postfix bans: | ||
- | |||
- | < | ||
- | grep rejected / | ||
- | </ | ||
- | |||
- | ===== Testing ===== | ||
- | |||
- | < | ||
- | fail2ban-regex / | ||
</ | </ | ||
Line 75: | Line 38: | ||
</ | </ | ||
- | ==== Configure defaults in '' | + | ==== Configure defaults in jail.local ==== |
Add your own IP ranges to keep from getting locked out yourself. | Add your own IP ranges to keep from getting locked out yourself. | ||
< | < | ||
+ | vi / | ||
+ | |||
[DEFAULT] | [DEFAULT] | ||
ignoreip = 127.0.0.1 209.193.64.0/ | ignoreip = 127.0.0.1 209.193.64.0/ | ||
+ | </ | ||
+ | |||
+ | ===== Startup ===== | ||
+ | |||
+ | Enable Fail2Ban to start up automatically and start the service: | ||
+ | |||
+ | < | ||
+ | chkconfig fail2ban on | ||
+ | service fail2ban start | ||
</ | </ | ||
Line 111: | 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 155: | Line 150: | ||
[apache-badbots] | [apache-badbots] | ||
- | enabled | + | enabled |
filter | filter | ||
action | action | ||
| | ||
- | logpath | + | logpath |
+ | / | ||
/ | / | ||
/ | / | ||
maxretry = 1 | maxretry = 1 | ||
+ | bantime | ||
</ | </ | ||
Line 247: | 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 / | ||
</ | </ | ||