上文提到使用選擇性灰名單 (Selective Greylisting) 的其中一個辦法是 Postfwd。現在就讓我先介紹安裝方法,尤其是在 CentOS Linux 上有些程序是要留意的。
前題
首先要安裝 greylisting 的 daemon。sqlgrey 是一個方便又很好的程式,再者 epel repository 也有現成 rpm package。安裝非常容易。
postfwd 安裝
1. 在 postfwd.org 下載 postfwd 的最新版本。但提議下載 1.* 版本,因為 2.* 仍為 Development 版本。寫本文是的最新 1.*版本為 v.1.18。
2. 解壓後會見到幾個子目錄。首先要將 sbin 目錄下的 postfwd 檔抄至 /usr/local/sbin 下。
3. configuration file 在 etc 目錄下,將 postfwd.cf.example 抄至 /etc/ 目錄下並改為 postfwd.cf。
4. 為了使 postfwd 在開機時自動運作,也要將 bin 目錄的 postfwd-script.sh 抄至 /etc/init.d/ 目錄下並改叫 postfwd。有幾個 configuration 也因應修改:
PFWCMD=/usr/local/sbin/postfwd PFWCFG=/etc/postfwd.cf PFWPID=/var/run/postfwd.pid PFWUSER=postfix PFWGROUP=postfix
5. postfwd 開機時必須要比 postfix 圥啟動。在 CentOS 環境下,可以在/etc/init.d/postfwd 檔的開頭加上:
# chkconfig: 2345 78 32 # description: Postfwd Policy Server
這便會使 postfwd 較先啟動。
6. 加入 postfwd 這 service 在開機程序
chkconfig --add postfwd
7. 啟動 postfwd
/etc/init.d/postfwd start
在 /var/log/maillog 中便會看到 postfwd 正常啟動的訊息。
postfix configuration
1. postfix 的 configuration 也要作出相應改動。在 main.cf 檔內加上:
##postfwd configuration smtpd_restriction_classes = greylisting 127.0.0.1:10040_time_limit = 3600 smtpd_recipient_restrictions = .... .... check_policy_service inet:127.0.0.1:10040 smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10040 greylisting = check_policy_service inet:127.0.0.1:2501
smtpd_end_of_data_restrictions 是給 postfwd 作為控制例如 size check 時使用,將來我會另文再介紹。
2. Restart postfix
測試
/usr/local/sbin/postfwd -C -f /etc/postfwd.cf
執行以上 command 便會列出所有 /etc/postfwd.cf 的所有 rulesets。