自定义filter为Fail2Ban

我已经安装了fail2ban,并试图设置阻止出现在syslog中出现的某个消息中的IP地址。 系统日志中的消息是:

racoon: ERROR: Invalid exchange type 243 from 103.14.62.181[11950]

通常每条消息都有不同的IP地址,括号(端口号)中的数字也不同。 看起来像我可以创build一个自定义筛选器通过执行以下操作:

racoon: ERROR: Invalid exchange type 243 from <HOST>

但我的问题是,我可以在那里停下来,将fail2ban做它的事情,或者我需要指定这样的事情:

racoon: ERROR: Invalid exchange type 243 from <HOST>[IDONTKNOWWHATGOESHERE]

如果我需要指定类似上面的内容,那么应该出现在括号内的有效通配符是什么? 有关OpenVPN的fail2ban文档(最接近的例子)显示了这一点:

http://www.fail2ban.org/wiki/index.php/OpenVPN

* <HOST>:[0-9]{4,5} Connection reset, restarting \[[0-9]{1,2}\]

看起来他们正在使用[0-9] {4,5}作为端口号的通配符。 这对我来说,还是不行?

我完全脱离我的例子为我的filter?

这里的最终目标是让任何一个失败的交换错误都被添加到带有DROP标志的IP表中。 我可能会有更多关于我的filter的问题,以及我在回答最初的问题之后有什么问题。

是的,你可以在那里停下来,fail2ban会做的事情。 您可以使用fail2ban-regex(1)实用程序对此进行testing。 总结是

 fail2ban-regex [OPTIONS] <LOG> <REGEX> [IGNOREREGEX] 

所以使用你所做的工作(请注意,我必须添加date时间到您提供的日志条目的开始,否则它会抱怨。)

 fail2ban-regex "Mar 3 07:36:19 racoon: ERROR: Invalid exchange type 243 from 103.14.62.181[11950]" "racoon: ERROR: Invalid exchange type 243 from <HOST>" Running tests ============= Use regex line : racoon: ERROR: Invalid exchange type 243 from <HOST> Use single line: Mar 3 07:36:19 racoon: ERROR: Invalid exchange ty... Matched time template MONTH Day Hour:Minute:Second Got time using template MONTH Day Hour:Minute:Second Results ======= Failregex: 1 total |- #) [# of hits] regular expression | 1) [1] racoon: ERROR: Invalid exchange type 243 from <HOST> `- Ignoreregex: 0 total Summary ======= Addresses found: [1] 103.14.62.181 (Mon Mar 03 07:36:19 2014) Date template hits: 2 hit(s): MONTH Day Hour:Minute:Second Success, the total number of match is 1