阻止来自maillog的发件人域

在我们的邮件服务器,我们正在采取大量的命中。 在maillog中有很多这样的:

Apr 23 04:35:13 mail1 postfix/smtpd[31700]: NOQUEUE: reject: RCPT from unknown[119.153.14.231]: 554 <[email protected]>: Recipient address rejected: User unknown in local recipient table; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<localhost> 

我有一个脚本,searchIP和阻止这些。 当我阻止RCPT IP时,出现问题。 相反,我想阻止发件人域,就像这个例子:shareme.com。 我应该在脚本中修改哪些内容?

 #!/bin/bash IPT=/sbin/iptables LIMIT=10 cd /admin # first get one minute of log grep "`date +"%b %d %H:%M:" --date="1 minutes ago"`" /var/log/maillog > minutelog # now extract the rejected attempts, sort and count uniq ip cat minutelog | grep "reject:" | cut -d" " -f10 | cut -d"[" -f2 | cut -d"]" -f 1 | sort | uniq -c | sort -n | sed 's/^[ \t]*//' > tmp1 # for each line in result while read line do MYCOUNT=`echo $line | cut -d" " -f1` MYIP=`echo $line | cut -d" " -f2` if [ $MYCOUNT -lt $LIMIT ] ; then echo $MYIP is ok: $MYCOUNT attempts else echo blocking the spammer at $MYIP with $MYCOUNT attempts $IPT -I INPUT -i eth0 --proto tcp -s $MYIP --destination-port 25 -j DROP echo $MYIP >> blocked.smtp fi done < tmp1 rm -f minutelog rm -f tmp1 

因为使用给定域的电子邮件可能来自任何IP,所以仅使用IP筛选器阻止SMTP发件人域是不可能的。 此外,根据发件人域名封锁是非常危险的,因为任何人都可以欺骗发件人的电子邮件,并发送多个邮件,如[email protected],您的脚本将愉快地阻止来自gmail的所有stream量。

为了解决您的问题,我build议您在http://www.postfix.org/TUNING_README.html中查看“针对连接太多的客户端的措施”部&#x5206;

最好尝试Fail2ban: http : //www.fail2ban.org/

Fail2ban扫描日志文件,如/ var / log / pwdfail或/ var / log / apache / error_log,并禁止IP,导致太多的密码失败。 它更新防火墙规则以拒绝IP地址。