精華區beta FreeBSD 關於我們 聯絡資訊
※ 本文轉錄自 [Daily] 看板 作者: DarkKiller (悸動) 看板: Daily 標題: [文件] 在 Postfix 上強力的 antispam 機制:Postgrey 時間: Fri Dec 24 13:24:49 2004 * AUTHOR Gea-Suan Lin <[email protected]> * LICENSE GNU Free Documentation License Version 1.2, November 2002 http://www.gnu.org/licenses/fdl.html * THANKS 感謝 [email protected] 帶頭使用。 感謝 [email protected] 提出建議。(permit_mynetworks) * 原理 Greylisting 的原理是: 在 SMTP server 傳回 error code 450 後,正常的 MTA (如 Sendmail、 Postfix) 會在一段時間後重送,但發廣告信的軟體不會。 在全世界大部分的發廣告信軟體都還沒有抵制 Greylisting 前,我們可以利用 這個想法,將廣告信與一般信件分隔開。 而在 Postfix 上的 implementation 叫做 Postgrey。 * 注意事項 安裝 Postgrey 後會造成沒有 patch 的 Maple 3 BBS 無法寄信到該台 server,另外會造成信件的延遲寄達,從五分鐘到四個小時都有可能。 另外,若 mail server 有 backup mx,則必須在所有的 mx server 都安裝 Postgrey。 舉例來說,nctu.edu.tw 有三台 mx server: ;; ANSWER SECTION: nctu.edu.tw. 1H IN MX 0 d2-spool.NTCU.net. nctu.edu.tw. 1H IN MX 10 d2-server.NTCU.net. nctu.edu.tw. 1H IN MX 20 mailgate.HCRC.edu.tw. 則這三台 server 都必須安裝 Postgrey 才有效果,否則 spam 軟體有可能在 收到 450 以後就往下面一台丟。 另外,Postgrey 必須使用 Postfix 2.1 或更新的版本。 * 效果 在 bbs.kkcity.com.tw 使用的結果是 300k mail/day -> 4k mail/day,除了 第一次裝完的設定錯誤造成無法寄信,目前沒有使用者在 SYSOP 板上抱怨收不 到信。 * 安裝 Postgrey 要求要 db41 或更新的版本,所以先安裝 db42: cd /usr/ports/databases/db42 make install clean 再安裝 postgrey: cd /usr/ports/mail/postgrey make WITH_BDB_VER=42 install clean 如果您有用 portupgrade 升級的習慣,請記得將 WITH_BDB_VER=42 放入 /usr/local/etc/pkgtools.conf * 設定 Postgrey 在 /etc/rc.conf 內加入一行: postgrey_enable="YES" 啟動 Postgrey: /usr/local/etc/rc.d/postgrey.sh start * 設定 Postfix 在 /usr/local/etc/postfix/main.cf 內: smtpd_client_restrictions = reject_rbl_client relays.ordb.org, reject_rbl_client bl.spamcop.net smtpd_sender_restrictions = reject_unknown_sender_domain, reject_non_fqdn_sender smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service inet:127.0.0.1:10023 除了使用 Greylisting 以外,您應該配合 relays.ordb.org 及 bl.spamcop.net 這兩個強大的 DNSBL。 relays.ordb.org 阻擋 open relay mail server,可以避免 spammer 為了 逃避 Greylisting 而去找 open relay mail server 發信。 (因為 open relay 通常都是正規的 MTA,光用 Greylisting 擋不住) spamcop 則是透過全世界大量的人力阻擋 spam。有些人收到 spam 後會馬上 將 mail header & mail body 送到 spamcop,如果發現短時間有大量的 spam 發送,則 spamcop 會儘速將該 IP 列入 bl.spamcop.net。 而 Greylisting 剛好幫您爭取了這段黃金時間。 在設定完以後,您可以重跑 Postfix: postfix reload * 觀察 您可以用 tail -F /var/log/maillog 看有沒有類似下面的 log,有的話代 表正常運作: Dec 17 00:16:10 news postfix/smtpd[55324]: NOQUEUE: reject: RCPT from 66-65-53-22.nyc.rr.com[66.65.53.22]: 450 <[email protected]>: Recipient address rejected: Greylisted for 300 seconds (see http://isg.ee.ethz.ch/tools/postgrey/help); from=<[email protected]> to=<[email protected]> proto=SMTP helo=<66-65-53-22.nyc.rr.com> * 目前使用的單位 D2 E-mail system (http://d2.nctu.edu.tw/) Group.NCTU.edu.tw (http://group.nctu.edu.tw/) KKcity (http://www.kkcity.com.tw/) Ptt (http://http://www.ptt.cc/) Skysoft (http://www.skysoft.com.tw/) -- Resistance is futile. <[email protected]> -- ※ Origin: 邪惡小鹿鹿 <Deer.twbbs.org> ◆ From: deer.math.nctu.edu.tw