Postfix和PostFWD(Postfix防火墙守护进程) – 集成这两个

我需要一种方法来积极地限制发送到特定域(整个域)的邮件数量,任何超过速率限制的邮件都需要被拒绝丢弃。 不延迟推迟。

我不能使用Exim,所以在这里我们使用Postfix和PostFWD,以及一些问题。

一些版本..

Postfix v2.6.6 PostFWD v1.3.5 CentOS 6.8 x64 

因此,首先,我validation了我的速率限制规则存在于postfwd中,并且从postfwd.cf正确地解释了postfix目录(它是):

 [root@monitoringtest ~]# /usr/local/postfwd/sbin/postfwd -f /etc/postfix/postfwd.cf -C Rule 0: id->"davelimit001"; action->"rate(recipient_domain/3/1800/421 4.7.1 - Sorry, exceeded 3 messages in 30 minutes.)"; recipient_domain->"==;dave-byrne.co.uk" [root@monitoringtest ~]# 

上述速率将所有发往任何@dave-byrne.co.uk的出站邮件限制在30分钟内的3个邮件内。 该域是我自己的testing,但在生产中,这将限制消息绑定到外部电子邮件到短信网关。

快速检查以确保Postfix和PostFWD已启动并正在监听(它们是):

 [root@monitoringtest ~]# netstat -anpl | grep ':10040\|:25' tcp 0 0 127.0.0.1:10040 0.0.0.0:* LISTEN 4093/postfwd.pid tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 4190/master tcp 0 0 :::25 :::* LISTEN 4190/master [root@monitoringtest ~]# 

然后,我在PostFWD服务器上侦听内部端口10040的示例请求。你可以看到PostFWD的通行证(带有它的DUNNO动作)3封邮件,然后将速率限制应用到第4次,并拒绝第421次。完美。 现在只要让Postfix使用PostFWD!

 [root@monitoringtest ~]# nc 127.0.0.1 10040 </usr/local/postfwd/tools/request.sample action=DUNNO [root@monitoringtest ~]# nc 127.0.0.1 10040 </usr/local/postfwd/tools/request.sample action=DUNNO [root@monitoringtest ~]# nc 127.0.0.1 10040 </usr/local/postfwd/tools/request.sample action=DUNNO [root@monitoringtest ~]# nc 127.0.0.1 10040 </usr/local/postfwd/tools/request.sample action=421 4.7.1 - Sorry, exceeded 3 messages in 30 minutes. [root@monitoringtest ~]# 

从/ var / log / maillog摘录显示适用于上述第4条消息的速率限制

 Oct 19 17:15:47 monitoringtest postfwd[25933]: [RULES] rule=0, id=davelimit001, [email protected][168.100.1.7], sender=<[email protected]>, recipient=<[email protected]>, helo=<dave-byrne.co.uk>, proto=ESMTP, state=RCPT, rate=rate/4/21.67s, delay=0.00s, hits=davelimit001, action=421 4.7.1 - Sorry, exceeded 3 messages in 30 minutes. 

所以,为了与Postfix集成,我将以下内容添加到我的postfix main.cf文件中:

 [root@monitoringtest ~]# tail -n 3 /etc/postfix/main.cf 127.0.0.1:10040_time_limit = 3600 smtpd_recipient_restrictions = permit_mynetworks, check_policy_service inet:127.0.0.1:10040 [root@monitoringtest ~]# 

这是根据PostFWD文档。

然后,我在本地使用telnet连接到Postfix并发送邮件给admin [at] dave-byrne.co.uk。 像这样:

 [root@dedweb ~]# telnet <test-server-IP-here> smtp Trying xx.xx.xx.xx... Connected to xx.xx.xx.xx. Escape character is '^]'. 220 monitoringtest.xxxxxxxxx.com ESMTP Postfix HELO dave-byrne.co.uk 250 monitoringtest.xxxxxxxxx.com MAIL FROM: [email protected] 250 2.1.0 Ok RCPT TO: [email protected] 250 2.1.5 Ok DATA 354 End data with <CR><LF>.<CR><LF> test1. . 250 2.0.0 Ok: queued as 946B621C15 

我这样做了4,5,6次,第四次应该像使用netcat在PostFWD上直接开火一样有限制的速度。 但事实并非如此,postfix只是愉快地谈论它的业务转发邮件,因为它认为它应该。 我可以发送一百,甚至不会考虑限速。 在这段时间里,PostFWD没有向日志打印任何东西,它根本没有被打,它什么也不传,它不会阻塞任何东西。 Postfix不使用PostFWD,即使它在smtpd_recipient_restrictions中设置为check_policy_service。

这是我卡住的地方。 3天,我不聪明。 有没有人曾经成功地使用过PostFWD(Postfix防火墙守护进程),使用任何types的规则集,而不考虑速率限制。 我接受很多build议,但是我无法从postfix中更改,我无法更改操作系统,由于安全问题和工作stream程问题,我无法切换到外部中间邮件中继。

谢谢,戴夫。

在问这个问题之后,我立即意识到,postfix收件人的限制是按照他们在main.cf中出现的顺序执行的。 所以我的

 [root@monitoringtest ~]# tail -n 3 /etc/postfix/main.cf 127.0.0.1:10040_time_limit = 3600 smtpd_recipient_restrictions = permit_mynetworks, check_policy_service inet:127.0.0.1:10040 [root@monitoringtest ~]# 

在'permit_mynetworks'返回一个很难的'OK'。 确定将停止处理进一步的限制。

我解决了我的问题,把check_policy_service放在我的smtp收件人限制的顶部。 如果PostFWD传递邮件,它会用“DUNNO”或者“DUNNO / OK”来回复,但是这个通过,但是继续运行更多的smtp限制。

有了这个,PostFWD可以自由地通过邮件,但没有触发速度限制,但一旦它做到了,就回复421拒绝。 正是我想要的。

所以请记住,你限制的顺序,以及你实际限制的内容,都是非常重要的。

请注意,这是一个私人内部邮件服务器,用于一个非常特定的目的。 不要将此代码用于生产或共享邮件服务器