fail2ban
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| fail2ban [2009/06/18 07:56] – k2patel | fail2ban [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 31: | Line 31: | ||
| logpath - where fail2ban look for log | logpath - where fail2ban look for log | ||
| </ | </ | ||
| + | |||
| + | Sample Config file | ||
| + | |||
| + | <code bash | / | ||
| + | # Fail2Ban configuration file | ||
| + | # | ||
| + | # Author: Cyril Jaquier | ||
| + | # | ||
| + | # $Revision: 617 $ | ||
| + | # | ||
| + | |||
| + | # The DEFAULT allows a global definition of the options. They can be override | ||
| + | # in each jail afterwards. | ||
| + | |||
| + | [DEFAULT] | ||
| + | |||
| + | # " | ||
| + | # ban a host which matches an address in this list. Several addresses can be | ||
| + | # defined using space separator. | ||
| + | ignoreip = 127.0.0.1 192.168.1.4 | ||
| + | |||
| + | # " | ||
| + | bantime | ||
| + | |||
| + | # A host is banned if it has generated " | ||
| + | # seconds. | ||
| + | findtime | ||
| + | |||
| + | # " | ||
| + | maxretry = 3 | ||
| + | |||
| + | # " | ||
| + | # options are " | ||
| + | # each jail too (use " | ||
| + | # | ||
| + | # gamin: | ||
| + | # is not installed, Fail2ban will use polling. | ||
| + | # polling: uses a polling algorithm which does not require external libraries. | ||
| + | # auto: will choose Gamin if available and polling otherwise. | ||
| + | backend = auto | ||
| + | |||
| + | |||
| + | [ssh-iptables] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | maxretry = 5 | ||
| + | |||
| + | |||
| + | [kernel-iptables] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | maxretry = 2 | ||
| + | |||
| + | |||
| + | |||
| + | [proftpd-iptables] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | maxretry = 6 | ||
| + | |||
| + | |||
| + | [sasl-iptables] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | backend | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | |||
| + | |||
| + | [apache-tcpwrapper] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | logpath | ||
| + | maxretry = 6 | ||
| + | |||
| + | |||
| + | [postfix-tcpwrapper] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | bantime | ||
| + | |||
| + | |||
| + | [courierpop3] | ||
| + | |||
| + | enabled | ||
| + | port = pop3 | ||
| + | filter | ||
| + | action | ||
| + | logpath | ||
| + | maxretry = 5 | ||
| + | |||
| + | |||
| + | [courierimap] | ||
| + | |||
| + | enabled | ||
| + | port = imap2 | ||
| + | filter | ||
| + | action | ||
| + | logpath | ||
| + | maxretry = 5 | ||
| + | |||
| + | |||
| + | [ssh-tcpwrapper] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | sendmail-whois[name=SSH, | ||
| + | ignoreregex = for myuser from | ||
| + | logpath | ||
| + | |||
| + | |||
| + | [vsftpd-notification] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | logpath | ||
| + | maxretry = 5 | ||
| + | bantime | ||
| + | |||
| + | |||
| + | [vsftpd-iptables] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | maxretry = 5 | ||
| + | bantime | ||
| + | |||
| + | |||
| + | [apache-badbots] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | bantime | ||
| + | maxretry = 1 | ||
| + | |||
| + | |||
| + | [apache-shorewall] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | |||
| + | |||
| + | [ssh-ipfw] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | ignoreip = 168.192.0.1 | ||
| + | |||
| + | |||
| + | [named-refused-udp] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | ignoreip = 168.192.0.1 | ||
| + | |||
| + | |||
| + | [named-refused-tcp] | ||
| + | |||
| + | enabled | ||
| + | filter | ||
| + | action | ||
| + | | ||
| + | logpath | ||
| + | ignoreip = 168.192.0.1 | ||
| + | </ | ||
| + | |||
| + | NOTE : In above configuration i am using custom config file for " | ||
| + | which require you to create new file as below. | ||
| + | |||
| + | <code bash | / | ||
| + | # Fail2Ban configuration file | ||
| + | # | ||
| + | # Author: K2patel | ||
| + | # | ||
| + | # $Revision: 1 $ | ||
| + | # | ||
| + | |||
| + | [Definition] | ||
| + | |||
| + | # Option: | ||
| + | # Notes.: | ||
| + | # host must be matched by a group named " | ||
| + | # be used for standard IP/hostname matching and is only an alias for | ||
| + | # (?::: | ||
| + | # Values: | ||
| + | # | ||
| + | failregex = Treason uncloaked! Peer < | ||
| + | |||
| + | # Option: | ||
| + | # Notes.: | ||
| + | # Values: | ||
| + | # | ||
| + | ignoreregex = | ||
| + | </ | ||
| + | |||
| + | |||
| + | Restart service now | ||
| + | |||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | ==== Issue && Fixes ==== | ||
| + | == My server did not get started == | ||
| + | First thing try to run your server from command line.\\ | ||
| + | usually following command will do it.\\ | ||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | this will print the errors on your screen.\\ | ||
| + | resolve error or google it if dont know how to. | ||
| + | |||
| + | == Sock file is not get removed during start == | ||
| + | check if this file exists. | ||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | Your can fix that issue by adding -x in your startup script.\\ | ||
| + | This issue appear if your fail2ban is get started using " | ||
| + | e.g. | ||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | test test test. | ||
| + | |||
| + | |||
| + | ==== How to test regex for logs ==== | ||
| + | |||
| + | As good software it come with good utility called " | ||
| + | which help you to test your regex against your log as well your custom string. | ||
| + | |||
| + | <code bash> | ||
| + | fail2ban-regex / | ||
| + | </ | ||
| + | OR | ||
| + | |||
| + | <code bash> | ||
| + | fail2ban-regex / | ||
| + | </ | ||
| + | |||
| + | which provides you result if your strings match.\\ | ||
| + | |||
| + | ==== Rotate log ==== | ||
| + | |||
| + | As your standard installation from distribution will generate log on the system.\\ | ||
| + | So it is necessary to rotate it to avoid any file limit.\\ | ||
| + | |||
| + | <code bash | / | ||
| + | / | ||
| + | weekly | ||
| + | rotate 7 | ||
| + | missingok | ||
| + | compress | ||
| + | size 4M | ||
| + | postrotate | ||
| + | / | ||
| + | endscript | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | If you do not have init script you can use following code to reload fail2ban as postrotate command. | ||
| + | |||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | NOTE : Path for fail2ban-client need to changed if you are using other than OpenSUSE | ||
| + | |||
| + | ==== Final Words ==== | ||
| + | |||
| + | you can check blocked ip using following command | ||
| + | |||
| + | <code bash> | ||
| + | iptables -L | ||
| + | </ | ||
| + | |||
| + | Hope fully this will help you | ||
fail2ban.1245311761.txt.gz · Last modified: 2020/08/10 02:30 (external edit)