Postfix スパム(迷惑)メール対策 Postgreyでgreylistingを導入

greylisting方式でスパム(迷惑)メール対策を行ったまとめ。
greylistingとは↓
http://www.gifu-u.ac.jp/imc/security/greylist.html

Postgreyを導入する

メールサーバはPostfixなのでPostgreyを使う。

インストール

メールサーバのOSはFreeBSDなのでportsでインストール。

# cd /usr/ports/mail/postgrey/
# make install clean
Postfixのmain.cfを編集

main.cfのsmtpd_recipient_restrictionsに下記を追記

reject_unauth_destination check_policy_service inet:127.0.0.1:10023
Postgrey起動とPostfixの設定反映
# /usr/local/sbin/postgrey --inet=10023 -d
# postfix reload
Postgreyの自動起動を設定しておく

/etc/rc.confに下記を追記

postgrey_enable="YES"

ホワイトリストの設定

greylistingを使うと下記の現象が発生するため、ユーザからクレームがあればホワイトリストで対応する。

  • メールの遅延(最短5分)
  • 重要なメールも遮断される場合がある
ホワイトリストを作成

/usr/local/etc/postfix/postgrey_whitelist_clientsに許可するドメインかIPを指定する。
デフォルトでamazon.comとか記載されているの適宜削除などする。


ホワイトリストでチェックされるのは
「client_name」
「client_address」
である。
※mailのログに記録されている


メールアドレスのドメインとclient_nameは必ずしも一致しないので要確認。
例えば、
「xxxx@ybb.ne.jp」は「client_name=web10511.mail.ogk.yahoo.co.jp」
となっているため、ybb.ne.jpをホワイトリストに指定していても意味がない。

再起動

起動する時はホワイトリストのファイルを指定します。

# kill [postgreyのプロセスID]
# /usr/local/sbin/postgrey --inet=10023 -d --whitelist-clients=/usr/local/etc/postfix/postgrey_whitelist_clients
# postfix reload


rc.confにも起動オプションを追加しておく。

postgrey_flags="--inet=10023 -d --whitelist-clients=/usr/local/etc/postfix/postgrey_whitelist_clients"
確認

メールのログを見ながら確認すれば一目瞭然。
また、メールのヘッダに「X-Greylist」があるかどうかでも確認できる。