今天看postfix日志,发现日志中报大量的NOQUEUE:reject:RCPTfromunknown[183.60.103.208]:5045.5.2,而且在不停的换IP,频率很高,一分钟能收到2000左右的连接,虽然postfix已经拒绝了请求,但是这也很浪费服务器资源。决定扼杀在萌芽状态。于是想起了fail2ban。
首先安装,yum安装,需要epel源
yuminstallfail2ban-y
cd/etc/fail2ban
vijail.conf
#[postfix-tcpwrapper]
[POSTFIX]
enabled=ture
port=smtp
filter=postfix
logpath=/var/log/zimbra.log##日志
action=iptables[name=Postfix,port=25,protocol=tcp]##调用iptables拒绝ip
ignoreip=127.0.0.1192.168.2.0/16##忽略的ip地址,或者是信任的ip地址
bantime=86400#####禁止其访问的时间(秒)
findtime=60
maxretry=5###最大尝试次数
vifilter.d/postfix.conf
failregex=warning:(.*)\[<HOST>\]:SASLLOGINauthenticationfailed:
reject:RCPTfrom(.*)\[<HOST>\]:5505.1.1
reject:RCPTfrom(.*)\[<HOST>\]:4504.7.1
reject:RCPTfrom(.*)\[<HOST>\]:5545.7.1
reject:RCPTfrom(.*)\[<HOST>\]:5545.5.2
reject:RCPTfrom(.*)\[<HOST>\]:5045.5.2###过滤规则,上面4条默认有,我另外加了两条
然后启动服务:servicefail2banstart
查看状态:
fail2ban-clientstatusPOSTFIX
Statusforthejail:POSTFIX
|-filter
||-Filelist:/var/log/zimbra.log
||-Currentlyfailed:0
|`-Totalfailed:8
`-action
|-Currentlybanned:1
|`-IPlist:120.197.131.6
`-Totalbanned:1
已经有IP地址了
iptables-L
Chainfail2ban-Postfix(1references)
targetprotoptsourcedestination
DROPall--120.197.131.6anywhere
RETURNall--anywhereanywhere
世界终于安静多了