fail2ban協助postfix過濾惡意IP 今天看postfix 日誌,發現日誌中報大量的NOQUEUE: reject: RCPT from unknown[183.60.103.208]: 504 5.5.2 ,而且在不停的換IP,頻率很高,一分鐘能收到2000左右的串連,雖然postfix 已經拒絕了請求,但是這也很浪費伺服器資源。決定扼殺在萌芽狀態。於是想起了fail2ban。 首先安裝,yum 安裝,需要epel 源 yum install fail2ban -y cd /etc/fail2ban vi jail.conf #[postfix-tcpwrapper][POSTFIX]enabled = tureport = smtpfilter = postfixlogpath = /var/log/zimbra.log ##日誌action =iptables[name=Postfix, port=25, protocol=tcp] ##調用iptables 拒絕ipignoreip = 127.0.0.1 192.168.2.0/16 ##忽略的ip地址,或者是信任的ip地址bantime = 86400 #####禁止其訪問的時間(秒)findtime = 60 maxretry = 5 ###最大嘗試次數 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 reject: RCPT from (.*)\[<HOST>\]: 504 5.5.2###過濾規則,上面4條預設有,我另外加了兩條 然後啟動服務:service fail2ban start 查看狀態: fail2ban-client status POSTFIXStatus 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 世界終於安靜多了