今天看postfix 日誌,發現日誌中報大量的NOQUEUE: reject: RCPT from unknown[183.60.103.208]: 504 5.5.2 ,並且在不停的換IP,頻率很高,一分鐘能收到2000左右的鏈接,雖然postfix 已經拒絕了請求,可是這也很浪費服務器資源。決定扼殺在萌芽狀態。因而想起了fail2ban。 服務器
首先安裝,yum 安裝,須要epel 源 app
yum install fail2ban -y tcp
cd /etc/fail2ban post
vi jail.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.1 192.168.2.0/16 ##忽略的ip地址,或者是信任的ip地址
bantime = 86400 #####禁止其訪問的時間(秒)
findtime = 60
maxretry = 5 ###最大嘗試次數 ip
vi filter.d/postfix.conf 資源
failregex = warning: (.*)\[<HOST>\]: SASL LOGIN authentication failed:
reject: RCPT from (.*)\[<HOST>\]: 550 5.1.1
reject: RCPT from (.*)\[<HOST>\]: 450 4.7.1
reject: RCPT from (.*)\[<HOST>\]: 554 5.7.1
reject: RCPT from (.*)\[<HOST>\]: 554 5.5.2 get
reject: RCPT from (.*)\[<HOST>\]: 504 5.5.2###過濾規則,上面4條默認有,我另外加了兩條 io
而後啓動服務:service fail2ban start table
查看狀態:
fail2ban-client status POSTFIX
Status for the jail: POSTFIX
|- filter
| |- File list: /var/log/zimbra.log
| |- Currently failed: 0
| `- Total failed: 8
`- action
|- Currently banned: 1
| `- IP list: 120.197.131.6
`- Total banned: 1
已經有IP地址了
iptables -L
Chain fail2ban-Postfix (1 references)
target prot opt source destination
DROP all -- 120.197.131.6 anywhere
RETURN all -- anywhere anywhere
世界終於安靜多了