User Tools

Site Tools


computing:fail2ban

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computing:fail2ban [2019/11/03 01:45] oemb1905computing:fail2ban [2023/12/27 16:08] (current) oemb1905
Line 1: Line 1:
 ------------------------------------------- -------------------------------------------
-  * **apachesurvival** +  * **fail2ban** 
   * **Jonathan Haack**   * **Jonathan Haack**
   * **Haack's Networking**   * **Haack's Networking**
-  * **netcmnd@jonathanhaack.com**+  * **oemb1905@jonathanhaack.com** 
  
 ------------------------------------------- -------------------------------------------
  
-//apachesurvival//      +//fail2ban//      
  
 ------------------------------------------- -------------------------------------------
Line 21: Line 21:
   <action = %(action_mwl)s>   <action = %(action_mwl)s>
  
-If you attempt to log in via ssh and fail within any 4 hour period 4 different times, then you are immediately blocked.+If you attempt to log in via ssh and fail within any 4 hour period 4 different times, then you are immediately blocked for a week.
  
   [DEFAULT]   [DEFAULT]
Line 28: Line 28:
   maxretry = 4   maxretry = 4
  
-The recidive filter below states that the last 3 weeks will be reviewed and if the ip address in question was banned more for 2 or more of those weeks, then the stricter ban of 20 weeks takes effect.  If you plan to review 3 weeks of information, with up to three violations each for a week, then you probably need at least 21 days of data.  I rounded to 30 for slightly more granularity. +TheIf over the last 3 weeks the ip address in question was banned at least twice, then the stricter ban of 20 weeks takes effect.  If you plan to review 3 weeks of information, with up to three violations each for a week, then you probably need at least 21 days of data.  I rounded to 30 for slightly more granularity. 
  
   [recidive]   [recidive]
Line 36: Line 36:
   bantime  = 20w   bantime  = 20w
   findtime = 3w   findtime = 3w
 +  maxretry = 2
  
 In order for this to work, the database purge parameter needs to be adjusted to be greater than or equal to what you specify for the find time in recidive. In order for this to work, the database purge parameter needs to be adjusted to be greater than or equal to what you specify for the find time in recidive.
Line 42: Line 43:
   <dbpurgeage = 30d>     <dbpurgeage = 30d>  
      
-Okay, so far, fail2ban is installed, configured, and its service might even be running post-installation, but it it is not doing anything.  In order for fail2ban to take effect, you need to insert ''enabled = true'' within each element below.+Okay, so far, fail2ban is installed, configured, and its service might even be running post-installation, but it it is not doing anything.  In order for fail2ban to take effect, you need to insert ''enabled = true'' within each element below.  
  
   [sshd]   [sshd]
-  //enabled = true//+  enabled = true
   port    = ssh   port    = ssh
   logpath = %(sshd_log)s   logpath = %(sshd_log)s
   backend = %(sshd_backend)s   backend = %(sshd_backend)s
  
-    +After enabling the elements you are in need of, and once all of your other basic configuration changes are done, restart the service, and then check the logs to verify functionality and debug as needed.  Verify what fail2ban has done to your iptables in order to enact the policies above.
- +
-Once your configuration changes are done, restart the service, and then check the logs to verify functionality and debug as needed.  Verify what fail2ban has done to your iptables in order to enact the policies above.+
      
   sudo systemctl restart fail2ban.service   sudo systemctl restart fail2ban.service
   sudo tail -f /var/log/fail2ban.log   sudo tail -f /var/log/fail2ban.log
   sudo iptables -L f2b-sshd   sudo iptables -L f2b-sshd
 +  sudo fail2ban-client status
  
-Hope this helps!+Hope this helps!  Oh yeah ... here is how to remove a false positive! 
 + 
 +  fail2ban-client set ssh unbanip 10.xx.15x.12x 
 +  fail2ban-client unban --all 
 + 
 +Another method that does more than individual services, and instead zaps all records: 
 + 
 +  sudo systemctl stop fail2ban 
 +  sudo truncate -s 0 /var/log/fail2ban.log 
 +  sudo rm /var/lib/fail2ban/fail2ban.sqlite3 
 +  sudo systemctl restart fail2ban 
 + 
 +Systemd log issues. Change the sshd jail as follows 
 + 
 +  sudo nano /etc/fail2ban/jail.local 
 +  backend = systemd 
 +  #backend = %(sshd_backend)s 
 +   
 +Some recommend adding backend = systemd into jail.conf, but I've found that does nothing. The error over ipv6 not being set and using auto can be removed as follows: 
 +   
 +  sudo nano /etc/fail2ban/fail2ban.conf 
 +  'allowipv6 = auto'
  
- --- //[[oemb1905@jonathanhaack.com|oemb1905]] 2019/11/02 19:20//+ --- //[[jonathan@haacksnetworking.org|oemb1905]] 2023/12/27 16:01//
computing/fail2ban.1572745542.txt.gz · Last modified: 2019/11/03 01:45 by oemb1905