CentOS 5.2 に Postfix を SMTP-AUTH 含めて外部レンタルサーバ仕様でセットアップする
VPSサーバに独自ドメインを用いてSMTPサーバをセットアップしたのでメモしておく。
スパムメール送信防止で Outbound Port 25 Blocking を行っているプロバイダーが多く、自分のところも該当している。そのため、Submission Port 587 でSMTP認証(SMTP AUTH)をサポートする必要があったのでその設定も行う。なお、SMTP 認証は PLAIN でセットアップした。
yum から必要なパッケージをインストール
# yum install postfix.i386 # yum install cyrus-sasl-plain.i386
Postfix /etc/postfix/main.cf の設定
書き換え追加して設定した部分は下記のとおり。mailbox は Maildir にする。SASL の設定を追記した。
※ホストのFQDNは mail.domain.tld で受け取るメールアドレスは user@domain.tld とする。
myhostname = mail.domain.tld mydomain = domain.tld myorigin = $mydomain mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks_style = host home_mailbox = Maildir/ # SMTP-Auth # smtpd_sasl_auth_enable = yes smtpd_tls_auth_only = no smtpd_sasl_local_domain = $myhostname smtp_sasl_security_options = noanonymous smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unau th_destination disable_vrfy_command = yes
※レンタルサーバは 1 ホストだけの構成として、mynetworks_style = host とホスト単体に設定した。
新規ユーザ用の Maildir を用意
※既存のユーザには、~/Maildir の同様に作成する。
# mkdir -p /etc/skel/Maildir/cur/ # mkdir /etc/skel/Maildir/new/ # mkdir /etc/skel/Maildir/tmp/ # chmod -R 700 /etc/skel/Maildir
Postfix /etc/postfix/master.cf の設定
smtp と submission をコメント部分を下記のとおり修正して設定する。通常の外部からのメールを受ける場合は、SASL は使わないので SMTP ではオフにする。
smtp inet n - n - - smtpd -o smtpd_sasl_auth_enable=no submission inet n - n - - smtpd -o smtpd_sasl_auth_enable=yes -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
SASL の設定
認証はsaslauthd ではなく、データベース sasldb2 で行う。
/usr/lib/sasl2/smtpd.conf を設定
pwcheck_method: auxprop auxprop_plugin: sasldb mech_list: plain login
認証ユーザ・パスワードを作成
# saslpasswd2 -u mail.domain.tld user
※上記のユーザとパスワードをメーラーでの送信サーバに接続で使用する。
ファイアウォール /etc/sysconfig/iptables の設定
IN/OUT の 25番, IN の 587 番ポートを開ける。
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT -A INPUT -p tcp -m tcp --dport 587 -j ACCEPT -A OUTPUT -p tcp -m tcp --sport 25 -j ACCEPT
postfix, iptables のサービス設定・再起動
最後は postfix の自動起動を on にする。
# service postfix start # service iptables restart # chkconfig postfix on
sendmail 等を使用していた場合、postfix に MTA を切り替える。
# alternatives --config mta
UBE(迷惑メール)中継対策
http://www.ipa.go.jp/security/ciadr/antirelay.html
RBL.JPで対策テストができる。
main.cf の disable_vrfy_command = yes はユーザーが存在するか確認できてしまうため VRFY コマンドを無効にしている。