CentOS の Postfix で Postgrey による迷惑メール対策

スポンサーリンク
スポンサーリンク

CentOS の Postfix でグレイリスティングを有効にする Postgrey の設定方法です。
グレイリスティングにより迷惑メール対策が行えます。

参考:Greylisting方式による迷惑メール対策|電子メール | 岐阜大学情報館

またここでは、グレイリスティングで迷惑メール対策する対象に、迷惑メールの送信元となることが多い、動的IPアドレス割り当てのホストを対象とする、S25Rスパム対策も実施します。

通常のメールサーバーが構築されていることを前提(参考:CentOS6でのメールサーバの設定(postfixその1))に、メール受け入れの条件に次を追加して対策します。

・ホワイトリストにのっている場合は、受け入れる
・S25Rスパム対策を実施(動的IPアドレス割り当てのホストからの接続は、Postgrey でチェックする)

スポンサーリンク

設定方法

Postgrey のインストール

Postgrey をインストールします。

まず、EPELリポジトリを利用できるようにします。次の記事を参照してください。

CentOS6/7でEPELリポジトリを利用する設定: パソコン鳥のブログ

EPELリポジトリが利用できるようになったら、Postgrey をインストールします。

yum install postgrey

Postgrey を動作させるための Postfix への設定

次のファイルを作成します。

/etc/postfix/s25r

/^unknown$/                                  check_greylist
/^[^.]*[0-9][^0-9.]+[0-9].*\./               check_greylist
/^[^.]*[0-9]{5}/                             check_greylist
/^([^.]+\.)?[0-9][^.]*\.[^.]+\..+\.[a-z]/    check_greylist
/^[^.]*[0-9]\.[^.]*[0-9]-[0-9]/              check_greylist
/^[^.]*[0-9]\.[^.]*[0-9]\.[^.]+\..+\./       check_greylist
/^(dhcp|dialup|ppp|[achrsvx]?dsl)[^.]*[0-9]/ check_greylist

/etc/postfix/main.cf に次を追加します。

/etc/postfix/main.cf

smtpd_restriction_classes = check_greylist
check_greylist = check_policy_service unix:/var/spool/postfix/postgrey/socket

また、main.cf の smtpd_recipient_restrictions に
check_client_access regexp:/etc/postfix/white-list.txt,check_client_access regexp:/etc/postfix/s25r
を追加します。

CentOS6でのメールサーバの設定(postfixその1): パソコン鳥のブログ に従ってメールサーバーを構築している場合は、次のようになります。

/etc/postfix/main.cf

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination,check_client_access regexp:/etc/postfix/white-list.txt,check_client_access regexp:/etc/postfix/s25r

ホワイトリストの準備

ホワイトリストを用意します。
日々更新がされているリストがありますので、次のコマンドでダウンロードし、/etc/postfix/white-list.txt に保存します。

crul -o /etc/postfix/white-list.txt http://www.gabacho-net.jp/anti-spam/white-list.txt

毎日自動的にダウンロードされるように、cron用の設定をします。
次のファイルを作成してください。

/etc/cron.daily/postgrey-whitelist

#!/bin/sh
curl -o /etc/postfix/white-list.txt http://www.gabacho-net.jp/anti-spam/white-list.txt >/dev/null 2>&1

実行権限をつけます。

chmod +x /etc/cron.daily/postgrey-whitelist

Postgreyの起動設定・Postfixへの反映

これで準備ができました。

最後に Postgreyの起動設定と、Postfix へ反映して、設定完了です。

systemctl enable postgrey
systemctl start postgrey
systemctl reload postfix

参考

Rgrey – S25R + greylisting
阻止率99%のスパム対策方式の研究報告 | スパム対策技術

コメント

タイトルとURLをコピーしました