Quote: http://www.backup.idv.tw/viewtopic.php?t=1355&sid=6ee57bf59ea2be8537dc634f5abb342d

* 原理
Greylisting 的原理是:
在 SMTP server 傳回 error code 450 後,正常的 MTA (如 Sendmail、Postfix) 會在一段時間後重送,但發廣告信的軟體不會。
在全世界大部分的發廣告信軟體都還沒有抵制 Greylisting 前,我們可以利用這個想法,將廣告信與一般信件分隔開。
而在 Postfix 上的 implementation 叫做 Postgrey。

1.) 下載 postgrey-1.31.tar.gz,解開放至 /etc/postgrey
         http://postgrey.schweikert.ch/pub/postgrey-1.31.tar.gz

      解壓 postgrey-1.31.tar.gz
      mv postgrey-1.31 /etc/postgrey

2.) 安裝相關套件
         Perl (version >= 5.6.0) 
         Net::Server 
         IO::Multiplex 
         BerkeleyDB (Perl module) 
         Berkeley DB (Library, version >= 4.1)

cpan> install Net::Server
cpan> install IO::Multiplex
cpan> install BerkeleyDB

3.) 測試 postgrey
         /etc/postgrey/postgrey –unix=/var/run/postgrey/socket –retry-window=2 –auto-whitelist-clients=5 –lookup-by-host –exim

根據錯誤訊息來修正問題
   mkdir /etc/postfix
   cp /etc/postgrey/postgrey_whitelist_clients /etc/postgrey/postgrey_whitelist_recipients /etc/postfix
   mkdir -p /var/run/postgrey
   groupadd nogroup
   useradd postgrey
   mkdir  -p /var/spool/postfix/postgrey/
   chown postgrey.nogroup /var/spool/postfix/postgrey/

以上你也可以自行定義在 postgrey 執行時後面所接的參數 – 2008/02/15 added
–user=postgrey
–group=nogroup
–dbdir=/var/spool/postfix/postgrey/
–whitelist-clients=/etc/postfix/postgrey_whitelist_clients
–whitelist-recipients=/etc/postfix/postgrey_whitelist_recipients

至於 –auto-whitelist-clients=5 意思就是某來源 IP 只要符合下列兩項就會被列為白名單
   a.) At least 5 successfull attempts of delivering a mail (after greylisting was done). That number can be changed by specifying a number after the –auto-whitelist-clients argument. Only one attempt per hour counts.

   b.) The client was last seen before –max-age days (35 per default).

–greylist-action 用來跟 exim 說要作什麼後續處理
–greylist-text 文字說明,參數 %s 為顯示被列灰名單還有多少秒、%r 為收件者 domain 是什麼

4.) 啟動 postgrey
         /etc/postgrey/postgrey –unix=/var/run/postgrey/socket –retry-window=2 –auto-whitelist-clients=5 –lookup-by-host –exim -d

5.) 編輯 vi /etc/exim.conf,(由於 f2blog 會對斜線 自動刪除,為了省麻煩所以用附檔方式)
exim.conf-postgrey.txt

6.) vi /etc/postgrey/postgrey_whitelist

127.0.0.1
# external ip
10.1.1.123

7.) 重新載入/啟動 exim

8.) 加入開機啟動
echo "/etc/postgrey/postgrey –unix=/var/run/postgrey/socket –retry-window=2 –auto-whitelist-clients=5 –lookup-by-host –exim -d" >> /etc/rc.local

測試由 Client 寄一封信,底下為 Server 與 Client 的 mail log 訊息

Client 端 (postfix)
   more /var/log/maillog

Sep 20 01:00:07 test postfix/smtp[3527]: 237434F02BC: to=<exim@exim.ssorc.tw>, relay=mail.exim.ssorc.tw[10.1.1.111], delay=173, status=deferred (host mail.exim.ssorc.tw[10.1.1.111] said: 451 Greylisted, see http://postgrey.schweikert.ch/help/mail.exim.ssorc.tw.html (in reply to RCPT TO command))

Server 端 (exim)
   more /var/log/exim/mainlog

2007-09-20 17:09:42 H=(test.ssorc.tw) [10.1.1.123] F=<root@localhost.localdomain> temporarily rejected RCPT <exim@exim.ssorc.tw>: greylisted host 10.1.1.123
2007-09-20 17:09:42 H=(test.ssorc.tw) [10.1.1.123] incomplete transaction (RSET) from <root@localhost.localdomain>

   more /var/log/maillog

Sep 21 17:19:26 hi222 postgrey[10707]: action=greylist, reason=new, client_name=xxx.xxx.xxx, client_address=xxx.xxx.xxx, sender=cross@xxx, recipient=cross@ssorc.tw
Sep 21 17:19:26 hi222 postgrey[10707]: cleaning up old logs…
Sep 21 17:57:36 hi222 postgrey[10707]: action=pass, reason=triplet found, delay=2290, client_name=xxx.xxx.xxx, client_address=xxx.xxx.xxx.xxx, sender=cross@xxx, recipient=cross@ssorc.tw

ref: http://attenuate.org/~simon/wiki/Exim_and_postgrey
ref: http://www.bebt.de/blog/debian/archives/2006/07/30/T06_12_27/index.html

2007/09/21
   將 domains = +local_domains : +relay_to_domains 註解
   因為會造成 local 使用者無法寄信,outlook 出現

無法傳送郵件,因為某位收件者被伺服器拒絕。被拒絕的電子郵件地址是 'cross@ssorc.tw"。 主旨 '123', 帳戶: 'mail.ssorc.tw', 伺服器: 'mail.ssorc.tw', 通訊協定: SMTP, 伺服器回應: '421 Unexpected failure, please try later', 連接埠: 25, 安全(SSL): 否, 伺服器錯誤: 421, 錯誤碼: 0x800CCC79

2007/10/25
   [Q:] 451 Greylisted, see http://postgrey.schweikert.ch/help/ssorc.tw.html
   [A:] 這個情況是當註解 # domains = +local_domains : +relay_to_domains 時所造成的
          再把它反註解,當內部寄內部就ok,但寄到外部就出現 421 Unexpected failure, please try later
          後來 log 查到 unknown named domain list "+relay_to_domains",我就改為
          domains = +local_domains,也就是把 : +relay_to_domains 拿掉就ok了
          所以其實 2007/09/21 的作法應該就照 2007/10/25 才對吧,我想。
          後來再行驗證確認,設定要有 domains = +local_domains,意思就是內部寄內部ok,但要寄外部就
          要勾選我的伺服器需要驗證了

2007/10/26
   但後來其實呢, 設定為 domain = +local_domains 時,寄內不ok,寄外ok,不過勾選驗證就可寄內ok,
   不過常理來說怎會讓寄內不ok呢,怪
   可是後來不勾選的話,寄外內又都可以,搞什麼
   最終我想我自已搞烏龍了,domains = 還是要設,正確為
   domains = +local_domains : +relay_domains

   再次check,因為 directadmin 的 exim 有加入 pop before smtp,所以我驗證過程中一直有誤判,
   結論還是設上 domains = +local_domains : +relay_domains,不過還是會有 451的訊息,
   而這個解決辦法是勾選我的伺服器需要驗證

   再來再來,因為有使用到 webmail,需要設為 domains = +local_domains : +relay_domains : localhost

2007/10/29
   更正,關於 webmail 問題,不是在 domains = 後面加,而是要把 localhost 加入 /etc/postgrey/postgrey_whitelist 檔案裡

Related posts 相關文章
QUALYS 發現 Linux glibc 有嚴重漏洞,可以遠端控制系統 part2
More...
你覺得有多少網站是 ok 的 ?
More...
Gmail 為什麼有些郵件會被標示為垃圾郵件
More...
被 Spamhaus 列入前幾大的黑名單
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。