免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7949 | 回复: 2
打印 上一主题 下一主题

[Mail] :em14:Postfix 2.3.4:check_client_access问题(就是想做个黑名单) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-23 18:12 |只看该作者 |倒序浏览
系统:Debian/Etch
Postfix 2.3.4-3

main.cf里面加上了这一段:


  1. smtpd_client_restrictions =
  2.         permit_mynetworks,
  3.         permit_sasl_authenticated,
  4.         check_client_access hash:/etc/postfix/access,
  5.         reject_unknown_client_hostname
复制代码


然后创建一个新文件:/etc/postfix/access,权限为:


  1. -rw-r--r-- 1 root postfix   143 2007-01-23 17:40 access
复制代码


内容为:


  1. .hotmail.com            REJECT
  2. .digitalriver.com       REJECT
  3. .absgroup.com           REJECT
  4. .macbilling.com         REJECT
  5. .nobumoto.com           REJECT
  6. .protektedrecords.com   REJECT
复制代码


接下来为了使设置生效,运行了如下命令:


  1. mail:~# postmap hash:/etc/postfix/access
  2. mail:~# /etc/init.d/postfix reload
复制代码


我仔细看过Postfix的官方文档,关于access的部分是这样描述的:
...
pattern action
              When pattern matches a mail address, domain or host
              address, perform the corresponding action.
...
...
...
domain.tld
              Matches domain.tld as the domain part of  an  email
              address.

              The pattern domain.tld also matches subdomains, but
              only when the string smtpd_access_maps is listed in
              the  Postfix  parent_domain_matches_subdomains con-
              figuration setting (note that this is  the  default
              for  some versions of Postfix).  Otherwise, specify
              .domain.tld (note the  initial  dot)  in  order  to
              match subdomains.
...
...
...
REJECT optional text...
              Reject the address etc. that matches  the  pattern.
              Reply  with  $reject_code optional text... when the
              optional text is specified, otherwise reply with  a
              generic error response message.
...

结合我上面的access文件,设定应该没有写错,可是我用自己的hotmail帐号测试给我的邮件服务器发信,却无法REJECT,mail.log里面是这样的:

  1. Jan 23 17:41:55 mail postfix/smtpd[28447]: connect from bay0-omc3-s20.bay0.hotmail.com[65.54.246.220]
  2. Jan 23 17:41:56 mail postfix/smtpd[28447]: 245883A10C: client=bay0-omc3-s20.bay0.hotmail.com[65.54.246.220]
  3. Jan 23 17:41:56 mail postfix/cleanup[28450]: 245883A10C: message-id=<BAY7-F26A2A495000268406D89C7BDAD0@phx.gbl>
  4. Jan 23 17:41:56 mail postfix/qmgr[28419]: 245883A10C: from=<wasilylin@hotmail.com>, size=1239, nrcpt=1 (queue active)
  5. Jan 23 17:41:56 mail postfix/virtual[28451]: 245883A10C: to=<linxiaosong@keynet.com.cn>, relay=virtual, delay=0.71, delays=0.69/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)
  6. Jan 23 17:41:56 mail postfix/qmgr[28419]: 245883A10C: removed
  7. Jan 23 17:41:56 mail postfix/smtpd[28447]: disconnect from bay0-omc3-s20.bay0.hotmail.com[65.54.246.220]
复制代码


也就是说,这个黑名单根本就没有生效,查过google和postfix的官方列表,都没有找到答案,很明显是我的设置哪里出错了,但是反复检查也没有查出什么问题。

论坛徽章:
0
2 [报告]
发表于 2007-01-23 19:50 |只看该作者

check_client_access
改为
check_sender_access



.hotmail.com            REJECT
改为
hotmail.com            REJECT


应该可以

[ 本帖最后由 sosogh 于 2007-1-23 19:53 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2007-01-24 11:35 |只看该作者

非常感谢,问题解决了!(附原因说明)

关键就是这句:

The pattern domain.tld also matches subdomains, but only when the string smtpd_access_maps is listed in the  Postfix  parent_domain_matches_subdomains configuration setting.  Otherwise, specify .domain.tld (note  the  initial  dot)  in order to match subdomains.


他说如果你把smtpd_access_maps放到parent_domain_matches_subdomains列表里,在access文件里指定的域名就能够匹配到子域,否则必须写成.domain.tld这种形式,问题就出在如果已经把smtpd_access_maps放到parent_domain_matches_subdomains列表里,然后再写成.domain.tld的形式,反而完全不能匹配了。
接下来测试了
smtpd_client_restrictions的check_client_access(CONNECTING检查)
smtpd_sender_restrictions的check_sender_access(MAIL_FROM检查)
发现全都正常了,因此正确的做法是:
access里面只填写发件人@后面的部份,官方文档说以后会废除掉parent_domain_matches_subdomains,改成.domain.tld的形式去匹配域名及子域。

我现在维护黑名单的方式就是两重检查,首先检查主机名,在连接开始的时候就拒绝掉,如果无法拿到主机名,再在对端发送MAIL_FROM命令的时候检查域名,总能把垃圾挡住。举个例子:
我用同事的gmail帐号发信测试,发现以下信息:

  1. connect from nz-out-0506.google.com[64.233.162.225]
  2. from=<chandle.wei@gmail.com>
复制代码

access里面这样写:

  1. google.com REJECT ...
  2. gmail.com REJECT ...
复制代码

然后分别打开warn_if_reject调试(一次只打开一个),很准确的消息依次出现了:
打开check_client_access的warn_if_reject出现了:

  1. reject: RCPT from nz-out-0506.google.com[64.233.162.234]: 554 5.7.1 <nz-out-0506.google.com[64.233.162.234]>: Client host rejected
复制代码

关掉check_client_access的warn_if_reject,然后打开check_sender_access的warn_if_reject出现了:

  1. reject_warning: RCPT from nz-out-0506.google.com[64.233.162.228]: 554 5.7.1 <chandle.wei@gmail.com>: Sender address rejected
复制代码

非常好,很准确地满足了我的需求,谢谢sosogh,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP