This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
computing:fail2ban [2019/11/02 23:04] – created oemb1905 | computing:fail2ban [2024/12/13 16:22] (current) – oemb1905 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | action = %(action_mw)s | + | ------------------------------------------- |
+ | * **fail2ban** | ||
+ | * **Jonathan Haack** | ||
+ | * **Haack' | ||
+ | * **oemb1905@jonathanhaack.com** | ||
- | sudo cp / | + | ------------------------------------------- |
+ | |||
+ | // | ||
+ | |||
+ | ------------------------------------------- | ||
+ | |||
+ | This tutorial is designed to help you install fail2ban and get a basic set of configurations in place. | ||
+ | |||
+ | | ||
+ | sudo nano / | ||
+ | |||
+ | Once inside the configuration file jail.local edit the destination email and the action parameter. Read the conf file and decide which combination of m, w, l is right for your situation. | ||
+ | |||
+ | < | ||
+ | <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 for a week. | ||
+ | |||
+ | [DEFAULT] | ||
+ | bantime | ||
+ | findtime | ||
+ | maxretry = 4 | ||
+ | |||
+ | 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. | ||
+ | |||
+ | [recidive] | ||
+ | enabled = true | ||
+ | logpath | ||
+ | banaction = %(banaction_allports)s | ||
+ | bantime | ||
+ | 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. | ||
+ | |||
+ | sudo nano / | ||
+ | < | ||
+ | |||
+ | Okay, so far, fail2ban is installed, configured, and its service might even be running post-installation, | ||
+ | |||
+ | [sshd] | ||
+ | enabled = true | ||
+ | port = ssh | ||
+ | logpath = %(sshd_log)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. | ||
+ | |||
+ | sudo systemctl restart fail2ban.service | ||
+ | sudo tail -f / | ||
+ | sudo iptables -L f2b-sshd | ||
+ | sudo fail2ban-client status | ||
+ | |||
+ | Hope this helps! | ||
+ | |||
+ | 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 / | ||
+ | sudo rm / | ||
+ | sudo systemctl restart fail2ban | ||
+ | |||
+ | Systemd log issues. Change the sshd jail as follows | ||
+ | |||
+ | sudo nano / | ||
+ | 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 / | ||
+ | ' | ||
+ | |||
+ | --- // |