- Postfix2 (TLS + SASL2)の設定 -
Postfixは、配送速度やセキュリティ重視のMTA( Mail Transfer Agent )です。
設定もSendmailと比べ簡単ということなので、Postfixを採用しました。実際に、設定をしてみて、Sendmailより楽でした。
ここでは、Postfix2を用いて、TLSによる暗号化、及びSASL2によるSMTP Authの設定を行なっていきます。
また、ソースファイルからrpmファイルを作成し、インストールします。
ソースファイルからrpmファイルの作成にあたっては、こちらを参考にしました。
作業ディレクトリに移動します。 # cd /usr/src/redhat/SOURCES postfix2のSource RPMファイルをダウンロードします。 # wget http://ftp.wl0.org/official/2.1/SRPMS/postfix-2.1.5-3.src.rpm ダウンロードしたファイルを展開します。 # rpm -Uvh postfix-2.1.5-3.src.rpm userとgroupが違います・・・というエラーがたくさん発生しますが、無視します。 /usr/src/redhat/SOURCES ディレクトリ内にPostfix関連のファイルが出現します。 ここからがビルドオプションです。 # set the required build options # export POSTFIX_SASL=2 # export POSTFIX_TLS=1 # export POSTFIX_LDAP=0 SASL2とTLSを有効にし、LDAPがデフォルトで有効になっているので無効にしました。 また、postfix-2.1.5-3ディレクトリ内のmake-postfix.specの冒頭の部分に、 exportできるオプションの一覧が示されています。 RPMファイル作成に必要なspecファイルを作成します。 specファイルを自動生成してくれるスクリプトを利用しました。 # sh make-postfix.spec 以下が実行結果です。 Creating Postfix spec file: /usr/src/redhat/SPECS/postfix.spec Checking rpm database for distribution information... - if the script gets stuck here: check and remove /var/lib/rpm/__db.00? files Distribution is: redhat-release-9-3 (redhat-9.0) adding SASL v2 support to spec file adding TLS support to spec file specファイルが作成されたディレクトリに移動します。 # cd /usr/src/redhat/SPECS rpmbuildコマンドによりRPMファイルを作成します。 # rpmbuild -ba postfix.spec 以下のディレクトリにpostfix-2.1.5-3.sasl2.tls.rh9.i386.rpmが作成されているはずです。 確認してみてください。 # ls /usr/src/redhat/RPMS/i386 Postfix2のインストール # rpm -ihv postfix-2.1.5-3.sasl2.tls.rh9.i386.rpm Postfix2の設定 以下に編集箇所を示します。 これは取り合えず起動させるための設定です。 SASL2、TLSの設定はこのページの下の方にあります。 # cd /etc/postfix # vi main.cf myhostname = mail.e-hiro.net mydomain = e-hiro.net myorigin = $mydomain mydestination = $myhostname, localhost.$mydomain, $mydomain inet_interfaces = all mynetworks_style = subnet mynetworks = 192.168.0.0/20, 127.0.0.0/8 relay_domains = $mydestination home_mailbox = Maildir/ sendmail_path = /usr/sbin/sendmail.postfix MTAをsendmailかpostfixのうちpostfixの方を選択してください。 # update-alternatives --config mta aliasの変更例 # vi /etc/postfix/aliases postfix: webmaster ← postfix宛のメールをwebmasterに配送する設定です。 aliasを変更したら以下のコマンドを実行して反映させます。 # postalias /etc/postfix/aliases 設定の確認 エラーがなければ起動できます。 # postfix check Sendmailのアンインストール Sendmailをアンインストールしてもsendmailコマンドは使用できます。 PostfixがSendmailと互換性があるためらしいです。 # rpm -e sendmail # rpm -e sendmail-cf postfixの設定の確認ができます。 # postconf -n Postfixの起動 # postfix start 自動起動の追加 # chkconfig --add postfix 追加されたか確認 # chkconfig --list postfix SASL2(SMTP AUTH)の設定 SASL2によるSMTP AUTHを行なうには、cyrus-sasl-2.x.xが必要です。 インストールされていなければ、インストールしてください。 apt-getコマンドを利用すれば簡単にインストールできると思います。 sasldb2によるSMTP AUTH認証を行うためには、以下の設定を追記してください。 # vi /etc/postfix/main.cf # SMTP AUTH : sasl2 smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $mydomain smtpd_sasl_security_options = noanonymous smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination ← 1行で記述してください。 broken_sasl_auth_clients = no sasldb2でSMTP AUTH認証をする設定 UNIXパスワードとは別のパスワードが設定できるので、セキュリティ的にこの方が高いと思います。 smtpd.confファイルがなければ作成してください。 # vi /usr/lib/sasl2/smtpd.conf pwcheck_method: auxprop sasldb2の作成 $myoriginと同一のドメイン(ホスト)名を指定してください。 # saslpasswd2 -c -u `/usr/sbin/postconf -h mydomain` User Password: Again (for verification): 上記の場合では、Userの認証のためのパスワードを作成しています。 Postfixがsasldb2を利用できるようにgroup、permission(権限)を変更してください。 この作業は初回のみ必要となります。 # chgrp postfix /etc/sasldb2 # chmod 640 /etc/sasldb2 # ln /etc/sasldb2 /var/spool/postfix/etc 設定したパスワードの削除 # saslpasswd2 -d -u `/usr/sbin/postconf -h mydomain` User 登録されているユーザー名の確認 # sasldblistusers2 TLSの設定 TLS化のために以下の設定を追記してください。 また、キーの作成についてはこちらを参考にしてください。 # vi /etc/postfix/main.cf # TLS : /usr/local/certs smtpd_tls_cert_file = /usr/local/certs/server.crt smtpd_tls_key_file = /usr/local/certs/server.key smtpd_tls_CAfile = /usr/local/certs/ca.crt smtpd_tls_CApath = /usr/local/certs smtpd_tls_loglevel = 1 smtpd_use_tls = yes smtpd_tls_session_cache_database = sdbm:/etc/postfix/smtpd_scache tls_random_source = dev:/dev/urandom Outlook/Outlook Expressを使用する場合の設定とTLSセッションキャッシュマネージャの設定 をmaster.cfで行ってください。 submission、smtps、tlsmgrの注釈(#)を削除してください。 2行に渡っているものもありますので、注意してください。 以下は削除後のものになります。 # vi /etc/postfix/master.cf # ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ========================================================================== smtp inet n - n - - smtpd submission inet n - n - - smtpd -o smtpd_etrn_restrictions=reject smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes #submission inet n - n - - smtpd # -o smtpd_etrn_restrictions=reject # -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes #628 inet n - n - - qmqpd pickup fifo n - n 60 1 pickup cleanup unix n - n - 0 cleanup qmgr fifo n - n 300 1 qmgr #qmgr fifo n - n 300 1 oqmgr tlsmgr fifo - - n 300 1 tlsmgr rewrite unix - - n - - trivial-rewrite bounce unix - - n - 0 bounce defer unix - - n - 0 bounce trace unix - - n - 0 bounce verify unix - - n - 1 verify (以下略) (付録) 不正中継チェックサイト こちらで第三者不正中継チェックができます。 全てが青色の文字で、no relays acceptedと表示されるとOKです。 送信者による制限 送信アドレス(envelope-from)またはドメインにより受信制限の設定をします。 # vi /etc/postfix/main.cf smtpd_sender_restrictions = reject_unknown_sender_domain reject_non_fqdn_sender hash:/etc/postfix/reject_sender # vi /etc/postfix/reject_sender yahoo.co.jp REJECT hotmail.com REJECT goo.ne.jp REJECT postmapコマンドでreject_sender.dbを作成します。 # postmap /etc/postfix/reject_sender Postfixキューからのメッセージの削除 ABCDEFGはキューIDでmailqコマンドで確認できます。 # postsuper -d ABCDEFG キューに存在するメールの強制的再送 # postfix flush ファイアーウォールの設定(IPTABLES) INPUTの25(--dport 25)を開かないと外部から受信できません。 物凄く基本的なことだとは思いますが・・・。 TLS化の送信エラーについて 原因はウィルスチェックソフトでした。 何語か分からないのですが、Nortonの設定によるものらしいです。 http://kiki.ee.ntu.edu.tw/Outlook/FAQ/
Copyright © 2004-2005 E-HIRO.NET. All Rights Reserved.