Fail2ban 命令詳解 fail2ban-regex


fail2ban-regex是fail2ban提供的用來測試正則表達式的一個小工具,我們可以用它來測試正則表達式是否能夠匹配到日志文件中的要禁止的IP行。
fail2ban-regex默認情況下自動匹配到日期和時間,所以在進行正則匹配的時候如果fail2ban能夠匹配到日期部分,則無需在正則表達式中在匹配日期部分。

語法

fail2ban-regex 日志文件 ‘正則表達式’

示例

root@ubuntu:~# fail2ban-regex auth.log 'fail2ban-regex auth.log '[A-Za-z-_]+ sshd\[\d+\]: Failed password for invalid user [A-Za-z0-9]+ from <HOST> port [0-9]{5} ssh2''
Running tests
=============
Use   failregex line : .*: Failed password for invalid user [A-Za-z]+ fro...
Use         log file : auth.log
Use         encoding : UTF-8

Results(匹配結果)
=======
Failregex: 3932 total(總共匹配到3932條失敗的記錄)
|-  #) [# of hits] regular expression
|   1) [3932] .*: Failed password for invalid user [A-Za-z]+ from <HOST> port [0-9]+ ssh2
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [28039] (?:DAY )?MON Day 24hour:Minute:Second(?:\.Microseconds)?(?: Year)?
`-

Lines: 28039 lines, 0 ignored, 3932 matched, 24107 missed [processed in 1.89 sec] 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM