postfix 備忘録

Queue に溜まっているメールの確認

# postqueue -p

Queue にあるメールの削除

# postsuper -d queue_id

main.cf の設定変更

main.cf に関するセキュリティ上の変更点

SMTPのVRFYコマンドを使用不可に

disable_vrfy_command = yes

RFC822で定義されている書式に適合しないメールアドレスが通知された場合、受信を拒否

strict_rfc821_envelopes = yes

HELO コマンドでホスト名を通知しないホストの接続を拒否

smtpd_helo_required = yes

SMTP-AUTH(SMTP認証)

SMTP-AUTH(SMTP認証)とは、メールの送信時に認証を行うものです。
SMTP認証を行うために必要なパッケージをインストールします。
今回はSASLを使用した認証を行います。
それには cyrus-sasl パッケージをインストールします。
インストールしたのは以下のパッケージ
cyrus-sasl,cyrus-sasl-lib,cyrus-sasl-md5,cyrus-sasl-plain

cyrus-sasl の設定 /usr/lib/sasl2/smtpd.conf

pwcheck_method: saslauthd
mech_list: cram-md5 plain login

SASL認証用ユーザー/パスワードの設定

# saslpasswd2 -c <ユーザー>

自動起動するように設定

# chkconfig saslauthd on
# chkconfig --list saslauthd
saslauthd       0:off   1:off   2:on    3:on    4:on    5:on    6:off

/etc/postfix/main.cf

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous, noplaintext
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks
 permit_sasl_authenticated
 reject_unauth_destination

上記について補足します。
smtpd_sasl_local_domain : 上記の saslpasswd2 でドメインを変更した場合にはここも変更する
broken_sasl_auth_clients : outlook express などを使用する場合は yes にしておく
smtpd_recipient_restrictions : permit_sasl_authenticated を permit_mynetworks のあとに追加

sender_login_maps

SMTP認証したユーザーと送信するメールアドレスのユーザーが一致することを確認
main.cf

smtpd_sender_restrictions = reject_sender_login_mismatch
smtpd_sender_login_maps = hash:/etc/postfix/sasl_sender_login

sasl_sender_login(postmapでDB化する)

# メールアドレス saslpasswd2のユーザー+ドメイン
aaa@example.jp aaa@mail.example.jp

OP25B(Outbound Port 25 Blocking)対策

自宅SMTPサーバーの接続ISPがOP25Bを導入した

自宅サーバーから送信する場合に、相手のSMTPサーバーに直接送信できなくなります。
対策としては、ISPのSMTPサーバーを経由して送信するようにします。
その際、ISPによってはSMTP認証が必要な場合もあります。
以下では、SMTP認証が必要な場合に関して書きます。

今回、submissionポートを用いたSMTP送信認証サーバーを経由して送信する場合を想定して書いています。

/etc/postfix/main.cf

## Outbound Port 25 Blocking
relayhost = [smtpauth.example.ne.jp]:submission
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = cram-md5, plain, login

/etc/postfix/sasl_passwd(postmapでDB化します)

[smtpauth.example.ne.jp]:submission  isp_user:isp_passwd

SMTPサーバーを利用するクライアント側ISPがOP25Bを導入した

OP25Bにより25番ポートが使用できなくなるので、別のポートで待ち受けるようにします。
以下の2つの方法が考えられます。

Submission Port(ポート:587)の利用

多くのISPで導入されている方法です。OP25Bが導入されると25番ポートが遮断されるため、その代替ポートとしてSubmission Port(ポート:587)を利用します。
但し、外部からの接続であるため不特定多数からアクセスできないようにSMTP-AUTHが必須となります。
以下の設定では、tlsを使用することを強制していますので通信の暗号化も行われます。
/etc/postfix/master.cf

submission   inet    n       -       n       -       -       smtpd
  -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes -o smtpd_etrn_restrictions=reject

SMTPS(SMTP over SSL/TLS. ポート:465)の利用

SMTPS は本来暗号化により通信の秘匿性を保つためのものであるが、ポート番号として通常465番を使用するためOP25Bの影響を受けずにSMTPサーバと通信が可能になります。
こちらも外部からの接続であるため不特定多数がアクセスできないようにSMTP-AUTHが必須となります。また通信内容が暗号化されるので安心して利用できます。
/etc/postfix/master.cf

smtps    inet  n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes

TLSサポート

メールの送信に際して、TLSによる暗号化がサポートされています。
TLSを開始するには通常のポートからSTARTTLSにより開始する方法とsmtpsポート(暗号化を使用する場合の専用ポート)を使用する方法の2種類があります。
これらの設定を行うと、TLSをサポートしているサーバーとの通信も暗号化されます。

/etc/postfix/main.cf

## smtp daemon
smtpd_tls_cert_file = /etc/postfix/tls/server.crt
smtpd_tls_key_file = /etc/postfix/tls/server.key
smtpd_tls_CAfile = /etc/postfix/tls/root.crt
smtpd_tls_session_cache_database = btree:/var/cache/postfix/smtpd_scache
smtpd_use_tls = yes
tls_random_exchange_name = /var/cache/postfix/prng_exch
## smtp client
smtp_tls_cert_file = /etc/postfix/tls/server.crt
smtp_tls_key_file = /etc/postfix/tls/server.key
smtp_tls_CAfile = /etc/postfix/tls/root.crt
smtp_tls_session_cache_database = btree:/var/cache/postfix/smtp_scache
smtp_use_tls = yes

server.crt … サーバー証明書
server.key … サーバー秘密鍵
root.crt … ルート認証局証明書

smtps(Port 465)を使用可能にする場合
/etc/postfix/master.cf

# SMTP over SSL/TLS
smtps    inet  n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes

エラーメッセージに関して

450 4.7.1 Client host rejected: cannot find your hostname

このメッセージはIPアドレスを逆引きして得られた名称が正引きできていないことを示している。
postfixはIPアドレスを逆引きして得られた名称が正引きできるかまでチェックしている。

Backup MX に関する設定

example.com のバックアップ MX を設定する場合には、以下の設定を追加します。

main.cf smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination relay_domains = $mydestination, example.com relay_recipient_maps =

スパム対策

postgrey

Postfix Greylisting Policy Server
Postfix で Greylisting を行う場合に使用します。

バーチャルドメイン

postfixadmin

postfix でバーチャルドメインをサポートするためのソフト


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2009-12-15 (火) 11:25:22 (262d)