- tar -zxf sendmail.8.14.2.tar.gz
- cd sendmail-8.14.2
- cd libmilter/
- ./Build -c
- ./Build install
- tar -zxf db-4.5.20.tar.gz
- cd db-4.5.20
- cd build_unix
- ../dist/configure
- make & make install
- tar -zxf milter-limit-0.14.tar.gz
- tar -zxf libsnert-1.71.6.tar.gz
- cd com/snert/src/lib
- ./configure & make && make install
- LibSnert/1.71.6
- Copyright 1996, 2009 by Anthony Howe. All rights reserved.
- Platform............: FreeBSD gcc
- Berkeley DB.........: 4.5 -ldb-4.5
- POSIX Threads.......: yes yes
- SQLite3.............: yes
- Sendmail libmilter..: yes
- Semaphore API.......: SYSTEMV_API
- Shared Memory API...: SYSTEMV_API
- CFLAGS..............: -I/usr/local/include/db45 -I/usr/home/feishu/limit/org/sqlite/include -D_THREAD_SAFE -pthread -D_REENTRANT -O2 -Wall -I${top_srcdir}/../../include
- LDFLAGS.............: -L/usr/local/lib/db45 -L/usr/home/feishu/limit/org/sqlite/lib -pthread -L${top_srcdir}/../../lib
- LIBS................:
- make build
- make install
- cd ../milter-limit
- ./configure --enable-run-user=postfix --enable-run-group=mail --enable-debug
- make build
- make install
- echo "smtpd_milters = unix:/var/run/milter/milter-limit.socket" >> /usr/local/etc/postfix/main.cf
milter-limit 的规则文件写在/etc/mail/access 中,然后用makemap 来生成
makemap hash /etc/mail/access.db < /etc/mail/acces
# 请注意access.db权限不能为可执行,并且可以让postfix 用户能够读取
/etc/mail/access 文件的规则包括
milter-limit-Connect: # 客户端连接IP
milter-limit-From: # 发件人地址
milter-limit-To: # 收件人地址
milter-limit-Auth: # 通过SMTP认证的发件人
支持以下匹配规则
[network/cidr]limit 无类域间路由
!pattern!limit 简单文本匹配
/regex/limit POSIX正则表达式
limit:时间单位可以是秒(s)、分钟(m)、小时(h)、天(d)、星期(w)
格式: messages ‘/’ time [unit]
# 发往sina.com域限制在1小时发送2封邮件
策略:
启动参数: policy=reject
none 什么都不做
tag 给邮件标题打标签 启动参数:subject-tag=[SPAM]
quarantine 将邮件送入隔离队列(不发送,需要通过命令激活).
later 不接收邮件,提示发送端发送延迟消息,邮件仍旧在发送端的队列中,稍候重试
reject 拒绝邮件(默认值)
discard 直接丢弃
启动命令
/usr/local/sbin/milter-limit verbose=all policy=later -start
如果需要调试使用 verbose=all 在/var/log/maillog 中查看日志
其他参数用 -help 参数查看
postfix 基本参数设置
smtp_skip_4xx_greeting = yes
smtp_skip_5xx_greeting = yes
default_destination_concurrency_limit = 2 #同一IP并发连接
initial_destination_concurrency = 2
smtp_helo_name = mail.test.com # 本机对外真实域名
smtpd_milters = inet:localhost:8891,unix:/var/run/milter/milter-limit.socket
测试发送邮件,如果在一小时呢发送超过2封每秒,会被拒绝投递
查看日志:
tail /var/log/maillog
如下信息
说明控制能正常功能工作了
Mar 11 19:20:18 mail milter-limit[5613]: 00004 NOQUEUE: limit max=2 seconds=3600
Mar 11 19:20:18 mail milter-limit[5613]: cache get {milter-limit-to:sina.com}
Mar 11 19:20:18 mail milter-limit[5613]: 00004 NOQUEUE: cache get key={milter-limit-to:sina.com} value={1268309916, 2} rc=0
Mar 11 19:20:18 mail milter-limit[5613]: 00004 NOQUEUE: isOverLimit(8d50100, 8d4fbe8) {milter-limit-to:sina.com, 2/1h, 2, 4b98df9c}
rc=1
Mar 11 19:20:18 mail milter-limit[5613]: 00004 NOQUEUE: reply 450 4.7.1 has exceeded 2 messages per 1 hour
Mar 11 19:20:18 mail postfix/smtpd[5618]: NOQUEUE: milter-reject: RCPT from unknown[192.168.1.109]: 450 4.7.1 has exceeded 2 messag