Postfix 2.3 (SMTP-AUTH, TLS対応)
| Table of Contents |
インストール環境
- OS
- CentOS 5.5 (kernel 2.6.18-194.11.1.el5)
- パッケージ
- postfix-2.3.3-2.1.el5_2
パッケージのインストール
- postfix本体のインストール
# yum install postfix
これでインストールは完了です。
基本設定
main.cfの編集
- 設定ファイル/etc/postfix/main.cf」を編集します。
# vi /etc/postfix/main.cf # ホスト名 myhostname = mail.oss-d.net # ドメイン名 mydomain = oss-d.net # @以降のドメイン名 myorigin = $mydomain # メールを受け取るネットワークインタフェースのアドレス範囲 inet_interfaces = all # メールの最終目的地とみなす範囲の指定 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain # 信頼できるクライアントのネットワーク mynetworks = 192.168.11.0/24, 127.0.0.0/8 # リレーを許可するドメインを指定 relay_domains = $mydestination # メールBOXの形式 home_mailbox = Maildir/
SMTP-AUTH対応(SASL認証)
main.cfの編集
- 設定ファイル/etc/postfix/main.cf」を編集します。
# SASLによるSMTP認証を使用 smtpd_sasl_auth_enable = yes # 使用可能な認証メカニズムの設定 # noanonymous : 匿名接続を拒否。 # noplaintext : PLAIN認証を拒否(Outlook ExpressはPLAIN認証のみ対応) #smtpd_sasl_security_options = noanonymous, noplaintext smtpd_sasl_security_options = noanonymous # 認証時のTLSの利用(TLSを強制する場合はyesに変更) #smtpd_tls_auth_only = yes #ローカル認証 realm を設定 smtpd_sasl_local_domain = $myhostname #メールの送信可能なユーザ定義 # mynetworks sasl認証された は許可。それ以外は拒否 smtpd_recipient_restrictions = permit_mynetworks permit_auth_destination permit_sasl_authenticated reject # Outlook LOGIN 認証を利用するための設定 broken_sasl_auth_clients = yes
SASLの設定
- 「/usr/lib/sasl2/smtpd.conf」を下記の通り設定します。
pwcheck_method: saslauthd mech_list: login plain
- 「/etc/sysconfig/saslauthd」を下記の通り設定します。ユーザ情報はPAM経由でUNIXアカウントを利用します。
MECH=pam
- SASLの自動起動設定
# chkconfig saslauthd on
- SASLの起動
# /etc/init.d/saslauthd start
SMTP-AUTH対応(LDAP認証)
SMTP-AUTHの認証をLDAPで行うよう設定します。
SASLの設定
- 「/usr/lib/sasl2/smtpd.conf」を下記の通り設定します。
# vi /usr/lib/sasl2/smtpd.conf pwcheck_method: saslauthd mech_list: login plain
- 「/etc/sysconfig/saslauthd」を下記の通り設定します。
# vi /etc/sysconfig/saslauthd MECH=ldap
- SASLがLDAPのユーザ情報を使用するよう「/etc/saslauthd.conf」を設定します
# vi /etc/saslauthd.conf ldap_servers: ldap://192.168.11.100 ldap_search_base: dc=oss-d,dc=net ldap_filter: uid=%u
- SASLの自動起動設定
# chkconfig saslauthd on
- SASLの起動
# /etc/init.d/saslauthd restart
SMTP-TSL対応
秘密鍵と証明書の作成
秘密鍵「localhost.key」と証明書「localhost.crt」を作成します。
- カレントディレクトリを変更します。
# cd /etc/pki/tls
- 秘密鍵を生成します。
# openssl genrsa -des3 2048 > private/localhost.key
「Enter PEM pass phrase:」と表示されるので、パスフレーズを入力すると暗号化のための秘密鍵(localhost.key)が生成されます。
- Apache起動時に毎回パスフレーズを聞かれるので、秘密鍵からパスフレーズを削除します。
# openssl rsa -in private/localhost.key -out private/localhost.key 「Enter pass phrase for private/localhost.key:」と表示されるので、先ほどのパスフレーズを入力します。
- 生成された秘密鍵を使ってサイト証明書を発行します(Common NameはURLでのホスト名を入力)
# openssl req -new -x509 -key private/localhost.key -out certs/localhost.crt -days 3650 ----- Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:oss-d.net Email Address []:
main.cfの編集
- 設定ファイル「/etc/postfix/main.cf」を編集します。
# vi /etc/postfix/main.cf #TLSを有効にする smtpd_use_tls = yes #秘密鍵ファイルの指定 smtpd_tls_key_file = /etc/pki/tls/private/localhost.key #証明書ファイルの指定 smtpd_tls_cert_file = /etc/pki/tls/certs/localhost.crt #TLSセッションキャッシュデータベースの指定 smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_tls_scache #TLSのログレベル指定 smtpd_tls_loglevel = 1
master.cfの編集
- 設定ファイル「/etc/postfix/master.cf」を編集します。(コメントをはずすだけ)
# vi /etc/postfix/master.cf smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject tlsmgr unix - - n 1000? 1 tlsmgr
起動・自動起動
送信メールサーバーの切り替え
CentOSではデフォルトでsendmailが起動しているため、Postfixに切り替えます。
- sendmailの停止
# /etc/rc.d/init.d/sendmail stop # chkconfig sendmail off
- MTAの切り替え
「alternatives」コマンドで2を選択します。
# alternatives --config mta 選択 コマンド ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.postfix Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
自動起動の設定
- chkconfigコマンドで自動起動をONにします
# chkconfig postfix on
- chkconfigコマンドで自動起動の確認をします。
LUNレベル3,4,5がonになっていれば問題ありません。
# chkconfig --list postfix postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
起動
- Postfix を起動します。
# /etc/init.d/postfix start
- psコマンドで起動の確認を行います。
# ps ax |grep postfix 1909 ? Ss 1:29 /usr/libexec/postfix/master
各種コマンド
- デフォルト値から変更した設定を確認する
# postconf -n
- デフォルトの設定値を確認する
# postconf -d
- キューの状態を確認する
# postqueue -p
または# mailq
- キュー内のメールを強制的に再送する
# postqueue -f
または# postfix flush
- キューを削除する
# postsuper -d queue_id
- キューを全て削除する
# postsuper -d ALL