参考図書
メールサーバを構築にあたり以下の図書を参考にしました.
Amazon.co.jp: Postfix実践入門 (Essential Software Guide Book): 清水 正人: 本
注意
時間
時間がずれているとメールが遅れて届く原因となるのでNTPの設定もすること.現在の時刻は以下のコマンドで取得できます.
date Thu Aug 18 21:21:44 JST 2011
SELINUXの無効化
SELINUXが無効になっていないとログが吐けないなどの問題点があります.ですので,以下をSELINUXを無効化してくください.
SELinuxの状態を確認する.
getenforce Enforcing ← SELinux有効
これを無効化する
setenforce 0 ← SELinux無効化
SELinuxの状態確認
getenforce Permissive ← SELinux無効
ただし,再起動時には戻ってしまうので変える
vi /etc/sysconfig/selinux ← SELinux設定ファイル編集 SELINUX=enforcing ↓ SELINUX=disabled ← システム起動時にSELinuxを無効化
インストール設定
インストール
yum -y install postfix
バージョンノ確認
postconf mail_version mail_version = 2.3.3
OSのMTAの切り替え
alternatives --config mta There are 2 programs which provide 'mta'.
Selection Command ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 2 NOV /etc/xinetd.d# alternatives --config mta
There are 2 programs which provide 'mta'.
Selection Command ----------------------------------------------- * 1 /usr/sbin/sendmail.sendmail + 2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number:2と入れる
次に切り替っていることを確認する.
alternatives --display mta |grep link link currently points to /usr/sbin/sendmail.postfix ←postfixに変わっていることを確認 alternatives --display mta /usr/sbin/sendmail.sendmail - priority 90 ←postfixに変わっていることを確認 slave mta-pam: /etc/pam.d/smtp.sendmail
MTAに切り替わっていることを順に確認する
ls -al /usr/sbin/sendmail lrwxrwxrwx 1 root root 21 Apr 9 10:57 /usr/sbin/sendmail -> /etc/alternatives/mta
sendmailコマンドが/etc/alternatives/mtaのシンボリックリンクになっていて
さらに.etc/alternatigves/mtaを各人するとpostfixになっている.
ls -al /etc/alternatives/mta lrwxrwxrwx 1 root root 26 May 15 13:47 /etc/alternatives/mta -> /usr/sbin/sendmail.postfix
このようにsendomailコマンドがPostfixでインストールしたsendmailコマンドのリンクに変わっていることがわかります.
自動起動を確認する
chkconfig --list postfix postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ついでにsendmailをchkconfigの制御下において自動起動しないようにする.
/etc/init.d/以下にsenmailが無いとできない.
chkconfig --add sendmail chkconfig --list sendmail sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off chkconfig sendmail off chkconfig --list sendmail sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ランレベル1-6でoffに設定されていれば自動起動はしない.
メールキューを表示
mailq Mail queue is empty
無しならOK
postqueue -p postqueue: warning: Mail system is down -- accessing queue directly Mail queue is empty
Postfixの設定
vi /etc/postfix/main.cf
設定ファイルの注意点
パラメータの値は”や'で囲まない
正mydestination = $myhostname, localhost.$mydomain
誤 mydestination = "myhostname", localhost.$mydomain
コメント行のとゆうから始めない
#FQN
myhostname = mail.server-test.info #FQDN Name
外部に送出するメールのドメイン名
コンピュータの正式なホスト名(FQDN)を設定します.
myhostname = nov.mail.example.com
ホスト名(FQDN)は以下のコマンドで調べることができる
hostname -f nov.mail.example.com
ドメイン名の設定
mydomainパラメータで自サイトのドメイン名を設定する
mydomain = mail.example.com
myoriginパラメータでメールアドレスをk32ru@nov.mail.example.comというホスト名が入る形式にするか
k32ru@mail.example.comという「ユーザ名@ドメイン名」という形式にするかを設定します.
myorigin = $mydomain
#これは k32ru@mail.example.comのメール形式にすることを示す.
メールの受け取りと受け取るドメインの設定
メールサーバを実際に運用するためには,外部のメールサーバから自身のメールサーバへのメールを受け取る必要があります.
しかし,Postfixではセキュリティ上デフォルトではローカルからしか利用できないようになっています.
つまり,外部のメールサーバからメールをうけとれるようになっています.
この設定を変更するにはinet_ineterfaceパラメータを変更します.
以下のように設定してすべての外部サーバから送られてきたメールを受け取るようにします.
inet_interfaces = all
他のメールサーバのメール転送を行わないホスト,ドメイン名を指定します.
つまり,ここで指定したホスト,ドメインはローカルにメールが配送されます.
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
上のように設定することで
usr@nov.mail.example.com, usr@localhost.mail.example.com,kotai@localhost,k32ru@mail.example.com
というメールの形式をPostfitxが受け取り処理します.
利用可能なクライアントのネットワーク範囲の設定
一般的なユーザがメールサーバををりようするためには,所属するネットワークのクライアントからメールクライアントソフト(MUA)を起動し,Postfixが起動する
メールサーバに接続します.これらのクライアントはPostfixを経由してメールを送信できるようになります.
このようなクライアントを信頼されたクライアントと呼びます.
(信用されない外部のクライアントはメールのリレーはできない)
Postfixのデフォルトでは自ホストと自分の所属するサブネットのクライアントを信頼しています.
信頼されたクライアントを設定するにはmynetworksパラメータを使用します.
インストールされた初期の状態では以下が設定されています.
#mynetworks = 168.100.189.0/28, 127.0.0.0/8 #mynetworks = $config_directory/mynetworks #mynetworks = hash:/etc/postfix/network_table
最初を編集して以下のように設定します.
mynetworks = 192.168.1.0/24, 127.0.0.0/8
自分の所属するサブネットのIPアドレス/ネットマスクとじホストを意味する127.0.0.0/8を設定します.
メールリレーをするドメイン名の設定
外部から送られてくるメールをリレーをするドメイン名を設定します.
インストールしたmain.cfではコメントアウトされています.
Postfixのデフォうとが$mydestinatonとなっていますので,単に#を外しておくだけでもよいでしょう.
初期設定になっている値が明確になります.
relay_domains = $mydestination
メールを直接配送するか,あるいは上位のメールサーバに送るかの設定
デフォルトで,Postfixはメールを直接インターネット上のサーバに配送しようとしますが,メールを配送する際に
どのメールサーバにメールを送るかが指定できます.
例えば,Postfixメールサーバを設置する場所がローカルエリアネットワーク内で上位にメインとなる
メールサーバやプロバイダのサバーがあり,実際にそちら位に任せる場合などにrelayhostのパラメータを変更します.
デフォルトでもかまわないが,明確に何も設定してないことを示すために以下のように右側を空にします.
relayhost =
ローカルのメール配送方式の設定
ローカルのメール配送方式をhome_mailboxパラメータで設定します.
home_mailbox = Maildir/
今回は違いますが,Mailbox形式の場合はメールスプールディレクトリを指定します.
一般には/var/spool/mailが利用されます.
ただし,今回は使わないのでコメントアウトしておきあます.
#mail_spool_directory = /var/spool/mail
Postfixの起動と停止
Postfix checkを実行してPostfix設置時のパーミッション,ディレクトリ,所有者などをチェックします.
何も表示されずにプロンプトが返ってくれば問題ありません.
postfix check
現在までの設定は以下のようになりました.
queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix mail_owner = postfix myhostname = nov.mail.example.com mydomain = mail.example.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain unknown_local_recipient_reject_code = 550 mynetworks = 192.168.1.0/24, 127.0.0.0/8 relay_domains = $mydestination relayhost = alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases home_mailbox = Maildir/ smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
ps axf で以下のようになっているこをと確認する
2338 ? Ss 0:00 /usr/libexec/postfix/master 2347 ? S 0:00 \_ qmgr -l -t fifo -u 2581 ? S 0:00 \_ pickup -l -t fifo -u 2353 ? Ss 0:00 gpm -m /dev/input/mice -t exps2
Postfixの動作確認とSMTPプロトコル
SMTPプロトコルと直接話して動作確認を行う.
HELO
クライアントが接続さいに接続元を送出する.グリーティングメッセージ(挨拶)自分のホスト名を名乗る
EHLO
Extended Hello 拡張SMTP(ESTMP)に対応しているをサーバに知らせる.
サーバ側がESMTPに対応していれば拡張機能で知らせることできる.
telnetコマンドを使いpostfixへ接続する.
Postfixを設定した同じホスト上で接続を試みるため
ホスト名はlocalhostとしてポート番号を明示します.
実際にtelnetを使ってSMTPへ接続すると以下のような感じになります.
telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 nov.mail.example.com ESMTP Postfix (2.3.3)
メールサーバからの応答コードに220が含まれている.
220はサービス準備完了.他は以下のサイトを参考にすること.
http://e-words.jp/p/r-smtp.html
220の次にはドメイン(ホストほFQDN)が入り,メールサーバ,すなわちPostfixと接続ができたことが通知されます.
接続後,メールサーバに対して挨拶を送ります.
まさにHello(コマンドはEHLO)とともに,自マシンのFQDNを送出することでメールサーバに接続元を認識させます.
EHLO nov.mail.example.com 250-nov.mail.example.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN PIPELINING 複数のSMTPコマンドのパイプライン(つないで実行する) SIZE 10240000 送信メールの最大サイズ10240000バイト VRFY ユーザが存在するかを確認する.ただし,これはユーザが存在するかを辞書アタックできる危険性がある.そのため無効化できる. ETRN 宛先メールのキューを探してメールを一括配送するETRNコマンド ENHANCEDSTATUSCODES 拡張ステータスコード(Enhanced-Status-Codes) 8BITMIME 8-bit MIMEメッセージ使用可 DSN 配送状況に関する通知(Delivery Status Notification)
メールを書く. .(ピリオド)とEnterで終了
MAIL FROM:<root@localhost> 250 2.1.0 Ok RCPT TO:<k32ru@localhost> 250 2.1.5 Ok DATA 354 End data with <CR><LF>.<CR><LF> This is a test1 This is a test2 . 250 2.0.0 Ok: queued as 2D80719B2811F NOOP ←コネクションを維持.何もしない 250 2.0.0 Ok QUIT ←コネクション終了 221 2.0.0 Bye Connection closed by foreign host.
上手くいかない場合には
telnetで接続しても応答コードが返ってこない場合には
telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
まず,ログを吐き出すようにする.
vi /etc/syslog.conf mail.* -/var/log/maillog ↓ mail.* /var/log/maillog
syslogをリスタート
/etc/init.d/syslog reload
んで,別画面でターミナル開いてログを常に確認する
tail -f /var/log/maillog
なんらかのログを吐いている筈なのでそれを見て検索すること
Aug 18 03:04:35 nov postfix/smtpd[2688]: warning: database /etc/aliases.db is older than source file /etc/aliases Aug 18 03:04:35 nov postfix/smtpd[2688]: connect from localhost.localdomain[127.0.0.1] Aug 18 03:05:43 nov postfix/smtpd[2688]: B767C8A58151: client=localhost.localdomain[127.0.0.1] Aug 18 03:06:01 nov postfix/cleanup[2691]: B767C8A58151: message-id=<20110817180543.B767C8A58151@nov.mail.example.com> Aug 18 03:06:01 nov postfix/qmgr[2582]: B767C8A58151: from=<root@mail.example.com>, size=424, nrcpt=1 (queue active) Aug 18 03:06:01 nov postfix/local[2692]: warning: database /etc/aliases.db is older than source file /etc/aliases Aug 18 03:06:01 nov postfix/local[2692]: B767C8A58151: to=<root@mail.example.com>, relay=local, delay=31, delays=31/0.02/0/0, dsn=2.0.0, status=sent (delivered t Aug 18 03:06:01 nov postfix/qmgr[2582]: B767C8A58151: removed Aug 18 03:06:25 nov postfix/smtpd[2688]: disconnect from localhost.localdomain[127.0.0.1]
セキュリティ上関係
バナーの編集
ただし,応答コード220にはホスト名を明記するようにRFCに規約があるため,$myhostnameは省かないように注意
初期設定では以下のような感じになっていた.
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
応答は以下のような感じになる.
220 nov.mail.example.com ESMTP Postfix (2.3.3)
しかし,バージョンんが見えると狙われる原因になるので以下のように編集して
smtpd_banner = $myhostname Mail System
最後に設定ファイルを読み込む
postfix reload
telnetで確認
telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 nov.mail.example.com Mail System quit 221 2.0.0 Bye Connection closed by foreign host.
VRFY コマンド抑制
VRFYコマンドは引数に指定したユーザまたはメールボックが存在するか確認するものです.
デフォルトでは以下のようになっています.
VRFY k32ru ←サーバ存在するアカウント名 252 2.0.0 k32ru VRFY test ←サーバに存在しないアカウント名 550 5.1.1 <test>: Recipient address rejected: User unknown in local recipient table
以下を設定して,再読み込みを行う.
disable_vrfy_command = yes postfix reload
telnetで確認する
VRFY k32ru 502 5.5.1 VRFY command is disabled ←コマンドが無効化されている.
EHLOしないクライアントの接続を拒否
smtpd_helo_required = yes
ただし,これだとEHLO hogehogeのようなでたらめなマシン名やDNSで弾けない嘘の名前もホスト名と成り得るので以下を使い拒否する.
具体的にははsmtpd_helo_restrictionsパラメータを設定する.
reject_invalid_hostname
HELO/EHLOの文法に間違いがあると接続を拒否する.デフォルトでは501エラー
reject_non_fqdn_houstname
接続ホストがFQDNでない場合に要求を要求.デフォルトでは504
reject_unknown_hostname
接続クライアントがDNSで引けない場合に要求を拒否.デフォルトでは450
permit_mynetworks
自ネットワーク内からは接続を受け入れる.
左から有効になる.
smtpd_helo_restrictions = permit_mynetwokrs,reject_invalid_hostname,reject_unkown_hostname,permit
POPとIMAPの構築とSMTP認証
yum -y install dovecot
設定ファイル /etc/dovecot.conf
SSL関連ファイル /etc/pki/dovecotディレクトリ以下
証明書の作成
証明書を再作成するには証明書作成用の設定ファイルを修正する,
vi /etc/pki/dovecot/dovecot-openssl.cnf [ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_dn x509_extensions = cert_type prompt = no
[ req_dn ] # country (2 letter code) C=JP
# State or Province Name (full name) ST=Tokyo
# Locality Name (eg. city) L=Chiyoda
# Organization (eg. company) O=NAKAMURALab
# Organizational Unit Name (eg. section) OU=IMAP server
# Common Name (*.example.com is also possible) CN=mail.mail.example.com
# E-mail contact emailAddress=postmaster@mail.example.com
[ cert_type ] nsCertType = server
証明書の削除
デフォルトで入っているのを削除
rm /etc/pki/dovecot/certs/dovecot.pem
証明書の有効期限の延長
vi /usr/share/doc/dovecot-1.0.7/examples/mkcert.sh $OPENSSL req -new -x509 -nodes -config $OPENSSLCONFIG -out $CERTFILE -keyout $KEYFILE -days 3650 || exit 2
実行して証明書を作成する
sh /usr/share/doc/dovecot-1.0.7/examples/mkcert.sh
Dovecotの設定
imapsとpop3sはIMAP over SSL,POP over SSLを意味する
SSLを使用する場合にはまず通常のPOPなりIMAPすなわち,POP3やimapで動作テストを行なってからSSL側に移行すると設定時の問題の切り分けが出来ます.
vi /etc/dovecot.conf protocols = pop3 log_path = /var/log/dovecot.log disable_plaintext_auth = no ← 平文パスワードでの接続を許可する mail_location = maildir:~/Maildir ← メールボックの位置
Dovecotの起動
/etc/init.d/dovecot start
Dovecot Imap を起動中: [ OK ]
chkconfig --list dovecot
dovecot 0:off 1:off 2:off 3:off 4:off 5:off 6:off
chkconfig dovecot on chkconfig --list dovecot dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
開いているポートの確認
netstat -ln |grep 110
tcp 0 0 :::110 :::* LISTEN
ちなみに
110がPOPのTCPポート
995がPOPS
143がIMAP
993がIMAPS
telnetによる確認
telnet localhost 110 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. +OK Dovecot ready. ←Dovecotによる応答あり USER k32ru ←USERに続けてログインユーザ名を入力 +OK PASS ***** ←OKが帰ってきたらパスワードを入力 +OK Logged in. ←ユーザ名とパスワードで認証されるとログインに成功 LIST ←LISTコマンドで受け取ったメール数を確認できる +OK 3 messages: ←メッセージが3通あることが確認できる 1 1641 2 1430 3 559 . TOP 3 ←TOPコマンドに続けて,メールの番号を指定するとメールヘッダを表示 +OK Return-Path: <root@localhost.mail.example.com> X-Original-To: k32ru@localhost Delivered-To: k32ru@localhost.mail.example.com Received: from nov.mail.example.com (nov.mail.example.com [127.0.0.1]) by nov.mail.example.com (Postfix) with ESMTP id 2D80719B2811F for <k32ru@localhost>; Sun, 15 May 2011 23:39:31 +0900 (JST) Message-Id: <20110515143954.2D80719B2811F@nov.mail.example.com> Date: Sun, 15 May 2011 23:39:31 +0900 (JST) From: root@localhost.mail.example.com To: undisclosed-recipients:;
. RETR 3 ←RETERコマンドに続けてメールの番号を指定するとメールボディを表示される +OK 559 octets Return-Path: <root@localhost.mail.example.com> X-Original-To: k32ru@localhost Delivered-To: k32ru@localhost.mail.example.com Received: from nov.mail.example.com (nov.mail.example.com [127.0.0.1]) by nov.mail.example.com (Postfix) with ESMTP id 2D80719B2811F for <k32ru@localhost>; Sun, 15 May 2011 23:39:31 +0900 (JST) Message-Id: <20110515143954.2D80719B2811F@nov.mail.example.com> Date: Sun, 15 May 2011 23:39:31 +0900 (JST) From: root@localhost.mail.example.com To: undisclosed-recipients:;
This is a test1 This is a test2 . QUIT←QUITコマンドで終了する +OK Logging out. Connection closed by foreign host.
POP3Sを利用する
protocols = pop3 pop3s
先ほど作った証明書と秘密鍵ファイルを指定する
ssl_cert_file = /etc/pki/dovecot/certs/dovecot.pem ssl_key_file = /etc/pki/dovecot/private/dovecot.pem
認証局のCAを購入した場合にはそのCAをインストしてssl_ca_fileパラメータでその位置を指定します.
ssl_ca_file = /etc/pki/dovecot/trusted.certificate
Postfixを再起動
/etc/init.d/postfix restart
ポートが開いているかを確認
netstat -ln |grep tcp tcp 0 0 :::995 :::* LISTEN
メールクライアントを使用して995番に接続する
「SSLを使用する」か「TLSを使用する」にチェックを入れても同じように接続できます.
サーバ上でメールクライアントソフト(MUA)からアクセスしたディレクトリであるメールボック位置をlsコマンドで確認すると次のよなファイルが作成されていることがわかります.
-rw------- 1 k32ru k32ru 195 May 16 03:27 dovecot-uidlist -rw------- 1 k32ru k32ru 180 May 16 03:27 dovecot.index -rw------- 1 k32ru k32ru 16384 May 16 03:27 dovecot.index.cache -rw------- 1 k32ru k32ru 260 May 16 03:27 dovecot.index.log
これらのファイルはDovecotが利用するバイナリ形式のインデックスファイル類です.インデックスファイルを利用することでDovecotは高いパフォーマンスを得ています.
ちなみに中身をcatで見ると文字化けするので
cd /home/k32ru /home/k32ru/Maildir# cat dovecot.index.log �M�M���� �MH��M�M5�M��� ���� ����@����cache������M����@�M��
hexdumpを使うと良い
hexdump -C /home/k32ru/Maildir/dovecot.index.log 00000000 01 00 18 00 14 1b d0 4d 01 00 00 00 00 00 00 00 |.......M........| 00000010 00 00 00 00 14 1b d0 4d 80 80 80 88 20 00 00 10 |.......M.... ...| 00000020 18 00 04 00 14 1b d0 4d 48 00 0c 00 ed 0e d0 4d |.......MH......M| 00000030 14 1b d0 4d 35 0f d0 4d 80 80 80 88 02 00 00 10 |...M5..M........| 00000040 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |................| 00000050 03 00 00 00 08 00 00 00 80 80 80 84 20 00 00 10 |............ ...| 00000060 1c 00 04 00 04 00 00 00 80 80 80 89 40 00 00 10 |............@...| 00000070 ff ff ff ff 00 00 00 00 00 00 00 00 04 00 04 00 |................| 00000080 00 00 05 00 63 61 63 68 65 00 00 00 80 80 80 83 |....cache.......| 00000090 80 00 00 10 14 1b d0 4d 80 80 80 87 40 00 00 00 |.......M....@...| 000000a0 00 00 00 00 14 1b d0 4d 00 00 00 00 04 00 04 00 |.......M........| 000000b0 00 00 00 00 80 80 80 85 04 00 00 00 01 00 00 00 |................| 000000c0 02 00 00 00 08 00 00 00 80 80 80 87 40 00 00 00 |............@...| 000000d0 00 00 00 00 14 1b d0 4d 00 00 00 00 04 00 04 00 |.......M........| 000000e0 00 00 00 00 80 80 80 88 00 02 00 00 01 00 00 00 |................| 000000f0 f8 00 00 00 02 00 00 00 0c 01 00 00 03 00 00 00 |................| 00000100 20 01 00 00 | ...| 00000104
送信メール認証 SMTP-AUTH
本書ではSALSライブラリを使うためにCyrus-SASLパッケージに含まれるsaslauthデーモンは使用しません.
PostfixがDovecot SASLライブラリをに対応しているかどうかをpostconfコマンドを使って確認する.
postconf -a cyrus dovecot
対応できていることが確認できたらPostfixの設定ファイルに以下のパラメータを追加します.
smtpd_sasl_type = dovecot
SASLプラグインタイプでDovecotを選択する.デフォルトがcyrusと鳴っている場合がある.
smtpd_sasl_auth_enable = yes
SASL認証を有効にする
smtpd_sasl_authenticated_header = yes
Recevied:フィールドに認証されたユーザ名を表示する,(必出ではない)
broken_sasl_auth_clients = yes
Microsoft Outlook Express 4 やExchange 5.0はSASL認証で「AUTH=PLAIN」を使っているため
このパラメータをyesにしないとSASL認証ができない.
smptd_sasl_path = private/auth
DovecotSASLライブラリの認証ソケットファイル,Postfixのキューディレクトリ(/var/spool/postfix)からの相対パスで記述する.
実際のパスは/var/spool/postfix/private/authとなる.
Dovecotの設定を変更して再起動すると自動的に作られる.このUNIXドメインソケットをDovecotとPostfixが共有することでSMTP-AUTHとPOPやIMAPのユーザアカウントを共用できりょうになる.
smtpd_sasl_auth_cache_time = 90d
SASL認証を保持する期間.デフォルトは90日
smtpd_sasl_security_options = noplaintext,noanonymous
平文パスワード,Anonymous認証を拒否する
noactive.nodictionayなどを追加するとActiveアタックや辞書式のアタックを拒否する
smtpd_tls_CAfile = /etc/postfix/CA.pem
デフォルトは空.第3者認証局が発行した証明書を使用する場合には証明書のファイルパスを明示する.
以上を設定したらPostfixを再起動させる
postfix reload
Dovecotの設定
平文パスワードを使用するplainとPAM認証(login)を有効にしています.
#socket listen { #master { # Master socket provides access to userdb information. It's typically # used to give Dovecot's local delivery agent access to userdb so it # can find mailbox locations. #path = /var/run/dovecot/auth-master #mode = 0600 # Default user/group is the one who started dovecot-auth (root) #user = #group = #} #client { # The client socket is generally safe to export to everyone. Typical use # is to export it to your SMTP server so it can do SMTP AUTH lookups # using it. #path = /var/run/dovecot/auth-client #mode = 0660 #} #} }
↓を以下のように編集する.
auth default mechanisms = plain login client { # The client socket is generally safe to export to everyone. Typical use # is to export it to your SMTP server so it can do SMTP AUTH lookups # using it. # path = /var/run/dovecot/auth-client path = /var/spool/postfix/private/auth mode = 0660 user = postfix group = postfix } }
以上を設定したらdovecotを再起動させます.
/etc/init.d/dovecot restart Dovecot Imap を停止中: [ OK ] Dovecot Imap を起動中: [ OK ]
Dovecotを再起動するとUNIXドメインソケットファイルが作成されます.
このソケットファイルがPostfixとDovecotで共通で使われる認証データの受け渡し場所となります.
すなわちDovecotのユーザ,パスワードファイルの内容で,PostfixでSMTP-AUTHができるようになります.
ls -F /var/spool/postfix/private/auth
/var/spool/postfix/private/auth=
最後に「=」がついているがの,ソケットファイルです.
このソケットファイルは/var/spool/postfixディレクトリ以下に置かれるためmPostfixをchrot環境で動作させたときでもそのまま利用できます.
SMTP-AUTHのテスト
SMTP-AUTH動作テストはメールクライアントソフト(MUA)から行うだけではなくmtelnetコマンドでホスト上からも実行することもできます.
dovecot.conf内でmechanisms = plainを記述しているのでPlain認証を使っています.
ユーザ名とパスワードをBASE64でエンコードしてメールサーバに接続してみます.
ユーザ名とパスワードのBASE64エンコード値はPerlのモジュールのMMIME::Base64関数でできます.
perl -MMIME::Base64 -e 'print encode_base64("ユーザ名\0ユーザ名\0パスワード");'
したがって,ユーザ名がk32ru パスワードがhogehoge774だったら以下のようになります.
perl -MMIME::Base64 -e 'print encode_base64("k32ru\0k32ru\0hogehoge774");' a290YW5pAGtvdGFuaQBob2dlaG9nZTc3NA==
出力された文字がユーザ名とパスワードをBASE64エンコード値なのでコピーしておきます.
telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 nov.mail.example.com Mail System EHLO nov.mail.example.com 250-nov.mail.example.com 250-PIPELINING 250-SIZE 10240000 250-ETRN 250-AUTH PLAIN LOGIN ←SMTP-AUTHが追加されているのがわかる 250-AUTH=PLAIN LOGIN ←broken_sasl_auth_clients = yesの設定が有効になっている. 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN AUTH PLAIN a290YW5pAGtvdGFuaQBtYWRlc2lrbw== ←先ほどエンコードした値で認証 235 2.0.0 Authentication successful ←応答コード235が返り,認証に成功 MAIL FROM:<root@mail.example.com> 250 2.1.0 Ok RCPT TO:<k32ru@mail.example.com> 250 2.1.5 Ok DATA 354 End data with <CR><LF>.<CR><LF> This is SMTP-AUTH test mail . 250 2.0.0 Ok: queued as DBB6819B2811F ←メールがキューに入れられた. QUIT 221 2.0.0 Bye ←メールサーバから切断された. Connection closed by foreign host.
先ほどのメールを受信して見る. Received: from nov.mail.example.com (nov.mail.example.com [127.0.0.1]) (Authenticated sender: k32ru) ←k32ruで認証されている.smtpd_sasl_authenticated_header = yes by nov.mail.example.com (Postfix) with ESMTP id DBB6819B2811F for <k32ru@mail.example.com>; Mon, 16 May 2011 04:50:24 +0900 (JST) Message-Id: <20110515195039.DBB6819B2811F@nov.mail.example.com> Date: Mon, 16 May 2011 04:50:24 +0900 (JST) From: root@mail.example.com ←k32ruで認証されているが,rootからk32ru宛になっている. To: undisclosed-recipients:;
以上のことより,k32ruで認証されているが,rootからk32ru宛になっていてこのメールが送信者が偽装されていることがわかる.
OPB25への対処
OPB25とはメールサーバの送信ポートである25番ポートをブロックしてスパムを減らしましょうとうもの
自分のISPがOPB25を実施しているかどうかはメールサーバの25番ポートにtelnetコマンドで接続できるかで確認できます.
telnet mailserveraddress 25
応答コード220が返ってくれば25番ポートで接続できます.
出来ない場合には「Trying~」という箇所から先に進みません
Postfix smptdのサブミッションポートを有効にする.
vi /etc/postfix/master.cf
TLSの使用
smtpd_use_tls = yes
TLSを使用する
smtpd_tls_loglevel = 1
TLSのログレベルを指定
smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem Dovecotの設定で作成した証明書を指定 smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem
Dovecotの設定で作成した秘密鍵を指定
smtpd_tls_session_cache_database = btree:/etc/postfix/smptd_scache
接続キャッシュファイルを指定する
smtpd_tls_session_casche_timeout = 3600s
キャッシュの保存時間を指定する
必要に応じて
smtpd_tls_received_header = yes
Recived:フィールドにTLS情報を書きだす
smtpd_enforce_tls = yes
TLSを強制.TLSが使用できないクライアントを拒否する
smtpd_starttls_timeout = 300s
TLSのハンドシェイク手順の開始から終了までの時間を制限する
smtpd_tls_CAfle= /etc/pki/CA/cacert.pem
servervice postfix restart
telnetで接続を確認する.
telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 nov.mail.example.com Mail System EHLO nov.mail.example.com 250-nov.mail.example.com 250-PIPELINING 250-SIZE 10240000 250-ETRN 250-STARTTLS ←STARTTLSが追加 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN STARTTLS ←STARTTLSコマンドを送出 220 2.0.0 Ready to start TLS QUIT Connection closed by foreign host.
SMTP over SSL
TLSは最初プレーンテキストで接続し,STARTTLSコマンド入力後のセッションが暗号化されました.
これに対してSMTP over SSL(SSL/SMTPS)はセッションの最初からすべて暗号化された通信が確立されます.
ブラウザでhttpsを使ってSL通信を行うイメージとなります.
vi /etc/master.cfを編集します.
smtps inet n - n - - smtpd
これでsmtpsが有効となりまう.以下はmaster.cfの設定例です.
-o smtpd_tls_wrappermode=yes
TLSラッパーモードを使用する.Outlook ExpressやOutlook2002が存在する場合には有効にする.
-o smtpd_sasl_auth_enable=yes ← SASL認証を有効にする. -o smtpd_client_restrictions=permit_sasl_authenticated,reject ← SALS認証できないクライアントからのメールを拒否する
SMTP over SSLはTCPの465番ポートを使用します,
TLSもそうですが,SMTP over SSLもパスワードは暗号化されて送出されるため
平文パスワードを使用するように設定しておきます.
SMTP over SSLの動作確認
netstat -ln |grep tcp tcp 0 0 0.0.0.0:587 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN tcp 0 0 :::995 :::* LISTEN
SMTP over SSLでは接続の最初の段階からSSLに暗号化が行われるために
プレーンテキストのtelentコマンドでは接続することはできません
OpenSSLに付属するTLS/SSL用クライアントプログラムであるs_connectコマンドをつかって,SMTPSのTCP465番ポートに接続します,
s_connectコマンドを使うと,サーバとSSLによrくコネクションをつくるkとおができて,それ以降は平文でのコマンドでのやりとりができます.
s_connetctコマンドでサーバに接続する際に,-quit(または-ign_eof)オプションをつけないと,メール送信に使うコマンドRCTP TO:~の
「R」文字でエラーが発生して先に進めなくなります.
接続すると最初にSSL証明書の内容などが画面に大量に表示っされます.
220応答が返ってくれば認証を行いログインしてメールを送信することができます.
本には openssl s_client -quiet -connect localhost:465
を使えと書かれていたけどこれだとエラーがでてできなかった.
openssl s_client -quiet -starttls smtp -crlf -connect localhost:465 depth=0 /C=JP/ST=TOKYO/L=Chida/O=NAKAMURALAB/OU=IMAP server/CN=nov.mail.example.com/emailAddress=postmaster@mail.example.com verify error:num=18:self signed certificate verify return:1 depth=0 /C=JP/ST=TOKYO/L=Chida/O=NAKAMURALAB/OU=IMAP server/CN=nov.mail.example.com/emailAddress=postmaster@mail.example.com verify return:1 250 DSN EHLO nov.is.frde.dendai.ac.jp ←EHLO 250-nov.mail.example.com 250-PIPELINING 250-SIZE 10240000 250-ETRN 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN AUTH PLAIN a290YW5pAGtvdGFuaQBtYWRlc2lrbw== ←ユーザ名とパスワードをBASE64でエンコードした値 235 2.0.0 Authentication successful LIST 502 5.5.2 Error: command not recognized MAIL FROM: <k32ru@mail.example.com> 250 2.1.0 Ok RCPT TO: <root@mail.example.com> 250 2.1.5 Ok DATA 354 End data with <CR><LF>.<CR><LF> This smtp over ssl test mail . 250 2.0.0 Ok: queued as 8CCB119B2811F QUIT ←QUITコマンドで終了 221 2.0.0 Bye read:errno=0
thunderbirdでは以下の設定で確認した.
TLS
サーバ名 serverip
port 110
STARTTLS
適用される送信(SMTP)サーバはアカウントの一番上を確認
サーバ名 server ip
port 465
User name k32ru
認証方法 通常のパスワード認証
STARTTS
SMTP over SSL
IMAP
ServerName serverip
Port 995
SSL/TLS
通常のパスワード認証
SMTP
SSL/TLSはダメみたい
Android のK9では以下の設定で確認
サーバ名 serverip
port 995
SSL/TLS
サーバ名 server ip
port 465
User name k32ru
認証方法 通常のパスワード認証
STARTTS
TODO 外部からのK9動作確認
nat descriptor masquerade static 1 1 192.168.1.2 tcp 22
nat descriptor masquerade static 1 2 192.168.1.2 tcp www
nat descriptor masquerade static 1 3 192.168.1.2 tcp smtp
nat descriptor masquerade static 1 4 192.168.1.5 tcp 465
nat descriptor masquerade static 1 5 192.168.1.5 tcp 993
nat descriptor masquerade static 1 6 192.168.1.5 tcp 995
nat descriptor masquerade static 1 7 192.168.1.5 tcp 31412
Userminの導入
yum -y install perl-Net-SSLeay yum -y install perl-Authen-PAM cd /tmp wget http://www.webmin.com/jcameron-key.asc rpm --import jcameron-key.asc wget http://jaist.dl.sourceforge.net/project/webadmin/usermin/1.470/usermin-1.470-1.noarch.rpm rpm -Uvh usermin-1.470-1.noarch.rpm
rm -f RPM-GPG-KEY.dag.txt jcameron-key.asc usermin-1.470-1.noarch.rpm
userminの設定
echo "lang=ja_JP.euc" >> /etc/usermin/config
echo "denyusers=root" >> /etc/usermin/miniserv.conf
vi /etc/usermin/webmin.acl
#user
user: changepass forward ← 追加(パスワード変更とメール転送設定のみ実行可能とする)
/etc/rc.d/init.d/usermin restart ← Usermin再起動
Stopping Usermin server in /usr/libexec/usermin
mv /etc/usermin/miniserv.pem /etc/usermin/miniserv.pem.org ← デフォルトのUsermin用サーバー証明書をリネーム
cat /etc/pki/tls/certs/server.crt /etc/pki/tls/certs/server.key > /etc/usermin/miniserv.pem
テスト
ブラウザ上でメールを操作できるできるようにする
参考URL
http://centossrv.com/squirrelmail.shtml
wget http://jaist.dl.sourceforge.net/project/squirrelmail/stable/1.4.21/squirrelmail-1.4.21.tar.bz2
tar jxvf squirrelmail-1.4.21.tar.bz2
mv squirrelmail-1.4.21 /var/www/html/private/webmail
webmailを構築してテストメールを送信しようとしたら以下のようなエラーが出た
Message not sent. Server replied:
認証が必要です 530 5.7.0 Must issue a STARTTLS command first telnetで確認したところ同じようなエラーが確認された NOV /home/k32ru% telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 nov.mail.example.com Mail System
EHLO mail.example.com
250-nov.mail.example.com
250-PIPELINING
250-SIZE 20971520
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM root@mail.example.com
530 5.7.0 Must issue a STARTTLS command first
^]
telnet> quit
Connection closed.
どっかで認証をさせなければいけないとあるからそれが原因だと思われる.
TLS options
smtpd_tls_received_header = yes
smtpd_enforce_tls = no
そしたら,次は以下のように出た
翻訳に失敗しました
554 5.7.1 <nov.mail.example.com[127.0.0.1]>: Client host rejected: Access denied
旧メール鯖→新メール鯖の移行
ドメイン名の変更
myhostname = nov.mail.example.com
だったがメールが送信できないので
旧サーバはMXレコードがyyy.mail.example.comと出ていたので以下のように変更した.
myhostname = yyy.mail.example.com
DNSのキャッシュの問題により反映されるのには30分ほど時間がかかる
新しくユーザを作成した場合にはMaildirを追加する
mkdir -p /e
tc/skel/Maildir/new
mkdir -p /etc/skel/Maildir/cur mkdir -p /etc/skel/Maildir/tmp chmod -R 700 /etc/skel/Maildir/ touch /etc/skel/.forward
587で通信できるように
submission inet n - n - - smtpd
メール送信のログレポート
メールのログは以下のように設定してある場合には/var/log/maillogに吐かれる
vi /etc/syslog.conf mail.* /var/log/maillog
しかし,maillogはパッと見わかりづらいのでpflogsummを入れてログを解析する.
pflogsummはperlのツールなので最初に必要なモジュールを入れる.
yum -y install perl-Date-Calc
pflogsummを入れる.
yum -y install postfix-pflogsumm
動作確認のため今日のレポートを出す
/usr/bin/perl /usr/sbin/pflogsumm -d today /var/log/maillog
毎日レポートを出すようにする.
vi pflogsumm_report #!/bin/bash
MAILLOG=`mktemp` for log in `ls /var/log/maillog*|sort -r` do cat $log >> $MAILLOG done REPORT=`mktemp` pflogsumm --problems_first --verbose_msg_detail --mailq -d yesterday $MAILLOG > $REPORT cat $REPORT | mail -s "`head -1 $REPORT` in `uname -n`" postmaster rm -f $MAILLOG $REPORT
しかし,レポトートを出してみたがいらない情報があると判断し以下のように変更した
pflogsumm --problems_first --verbose_msg_detail --mailq -d yesterday $MAILLOG > $REPORT ↓ pflogsumm -d today $MAILLOG > $REPORT
chmod 700 pflogsumm_report
とりあえず,出力してみる.
./pflogsumm_report
毎日実行するようにする
mv pflogsumm_report /etc/cron.daily/
メールの不正中継点のチェック
以下のサイトを利用した.
第三者中継チェック RBL.JP
出力レポートを表示する.
不正中継されてないことを確認する.
第三者中継テスト 第三者中継テストのためmail.example.comに接続しています...
<<< 220 nov.mail.example.com Mail System >>> HELO h.rbl.jp <<< 250 nov.mail.example.com 中継テスト その0
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@h.rbl.jp> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@rbl.jp> <<< 554 5.7.1 <rlytest@rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その1
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その2
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その3
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その4
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@[203.0.113.0]> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その5
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest%h.rbl.jp@mail.example.com> <<< 554 5.7.1 <rlytest%h.rbl.jp@mail.example.com>: Relay access denied relay NOT accepted!! 中継テスト その6
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest%h.rbl.jp@[203.0.113.0]> <<< 554 5.7.1 <rlytest%h.rbl.jp@[203.0.113.0]>: Relay access denied relay NOT accepted!! 中継テスト その7
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <"rlytest@h.rbl.jp"> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その8
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <"rlytest%h.rbl.jp"> <<< 554 5.7.1 <rlytest%h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その9
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@h.rbl.jp@mail.example.com> <<< 554 5.7.1 <rlytest@h.rbl.jp@mail.example.com>: Relay access denied relay NOT accepted!! 中継テスト その10
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <"rlytest@h.rbl.jp"@mail.example.com> <<< 554 5.7.1 <rlytest@h.rbl.jp@mail.example.com>: Relay access denied relay NOT accepted!! 中継テスト その11
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <"rlytest@h.rbl.jp"@[203.0.113.0]> <<< 554 5.7.1 <rlytest@h.rbl.jp@[203.0.113.0]>: Relay access denied relay NOT accepted!! 中継テスト その12
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <@mail.example.com:rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その13
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <@[203.0.113.0]:rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 中継テスト その14
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <h.rbl.jp!rlytest> <<< 554 5.7.1 <h.rbl.jp!rlytest>: Relay access denied relay NOT accepted!! 中継テスト その15
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <h.rbl.jp!rlytest@mail.example.com> <<< 554 5.7.1 <h.rbl.jp!rlytest@mail.example.com>: Relay access denied relay NOT accepted!! 中継テスト その16
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <h.rbl.jp!rlytest@[203.0.113.0]> <<< 554 5.7.1 <h.rbl.jp!rlytest@[203.0.113.0]>: Relay access denied relay NOT accepted!! 中継テスト その17
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <"rlytest%h.rbl.jp"@fr.dendai.ac.jp> <<< 554 5.7.1 <rlytest%h.rbl.jp@fr.dendai.ac.jp>: Relay access denied relay NOT accepted!! 中継テスト その18
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@mail.example.com> <<< 250 2.1.0 Ok >>> RCPT TO: <"rlytest@h.rbl.jp"@fr.dendai.ac.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp@fr.dendai.ac.jp>: Relay access denied relay NOT accepted!! 中継テスト その19
>>> RSET <<< 250 2.0.0 Ok >>> MAIL FROM: <rlychk@localhost> <<< 250 2.1.0 Ok >>> RCPT TO: <rlytest@h.rbl.jp> <<< 554 5.7.1 <rlytest@h.rbl.jp>: Relay access denied relay NOT accepted!! 接続を閉じています...
>>> QUIT <<< 421 4.7.0 nov.mail.example.com Error: too many errors 第三者中継テストの結果
全てのテストが行われました, no relays accepted. Return to RBL.JP home page Copyright c 2002-2004 RBL.JP Project.
追記
外部からメール送れない
SSLで外部からログインしたユーザがメールを送れないという問題点があったので以下を参考にして
SMTPの時に認証されたユーザのみをメールを送信できるようにした設定の追加を行なった.
SMTP-AUTHのsmtpd_recipient_restrictionsの順番 - 覚え書き Plus!>
vi /etc/postfix/main.cf smtpd_recipient_restrictions = permit_mynetworks, reject_non_fqdn_recipient, permit_sasl_authenticated, reject_unauth_destination
メールの経路削除
外部からメールを送信するとメールヘッダに経由した箇所が記録されるので,結果として自分のローカルIPとグローバルIPが記録される.
例を以下に上げる.メールはリモートでSMTP認証し,Gmail宛に送ったメールである.
メールヘッダの全部
Delivered-To: **@gmail.com Received: by 10.236.111.44 with SMTP id v32cs137111yhg; Wed, 28 Sep 2011 09:20:35 -0700 (PDT) Received: by 10.236.131.82 with SMTP id l58mr54516132yhi.90.1317226834254; Wed, 28 Sep 2011 09:20:34 -0700 (PDT) Return-Path: <k32ru@mail.example.com> Received: from nov.mail.example.com (mail.example.com. [*******]) by mx.google.com with ESMTP id v5si9811504anc.************; Wed, 28 Sep 2011 09:20:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of k32ru@mail.example.com designates ***.***.***.** as permitted sender) client-ip=**.**.**.**; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of k32ru@mail.example.com designates 203.0.113.0 as permitted sender) smtp.mail=k32ru@mail.example.com Received: from [192.168.1.4] (hoge.isp.name [**.*.****.***]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: k32ru) by nov.mail.example.com (Postfix) with ESMTP id 8995B8A58107 for <***@gmail.com>; Thu, 29 Sep 2011 01:20:30 +0900 (JST) Message-ID: <4E83490C.10506@mail.example.com> Date: Thu, 29 Sep 2011 01:19:24 +0900 From: k32ru Mitsunori <k32ru@mail.example.com> User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: **@gmail.com Subject: test Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit
このメールはテストメールです
ローカルIPとグローバルIPが記録されているのは以下の部分である. Received: from [192.168.1.4] (hoge.isp.name [**.*.****.***])
そのため,Receviedヘッダを削除する.ただし,これをやるとメールの経路がわからなくなり問題が起こった場合に問題の特定が難しくなるといった問題点がある.
vi /etc/postfix/main.cf #delete Recived mail header header_checks = regexp:/etc/postfix/header_checks
vi /etc/postfix/header_checks /^Received:/ IGNORE
ヘッダを削除したメールは以下のようになり,消えているのがわかる.
Delivered-To: hogehoge@gmail.com Received: by 10.236.95.49 with SMTP id o37cs57961yhf; Mon, 31 Oct 2011 05:08:02 -0700 (PDT) Received: by 10.150.207.6 with SMTP id e6mr3746743ybg.88.1320062879718; Mon, 31 Oct 2011 05:07:59 -0700 (PDT) Return-Path: <k32ru@mail.example.com> Received: from nov.mail.example.com (yyy.mail.example.com. [mail server's global ip]) by mx.google.com with ESMTP id o18si7334027anp.***; Mon, 31 Oct 2011 05:07:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of k32ru@mail.example.com designates ***.**.*** as permitted sender) client-ip=**.**.**.**; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of k32ru@mail.example.com designates 203.0.113.0 as permitted sender) smtp.mail=k32ru@mail.example.com Message-ID: <4EAE8F96.2070907@mail.example.com> Date: Mon, 31 Oct 2011 21:07:50 +0900 From: Mitsunori k32ru <k32ru@mail.example.com> User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: hogehoge@gmail.com Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit
k32ruです.
運用に関して起こったエラー
特定のユーザにメールが届かない
特定のユーザにメールが送れない件についての見分け方と解決方法について連絡致します.
メールが相手に届かないという状態は2つが考えられます.
- アドレスを間違えたことによる宛先不明
- 設定で特定のドメンからのメールしか受信しないようにしている.
見分け方
参考URL
http://bouncehammer.jp/ja/email-topics/2010/11/distinguish-between-the-unknown-and-the-filtered.html
in reply to RCPT TO Command = 宛先不明(SMTPのRCPT TO:コマンドでエラーが出た)
in reply to end of DATA Command =ドメイン指定拒否(SMTPのDATAコマンド以降でエラーが出た)
ログデータ
/var/log/maillog
maillog.2:Mar 17 19:08:31 nov postfix/smtp[16360]: 529908A5856B: to=<*****@docomo.ne.jp>, orig_to=<wada@mail.example.com>, relay=mfsmax.docomo.ne.jp[203.138.180.112]:25, delay=0.33, delays=0.19/0.06/0.03/0.04, dsn=5.0.0, status=bounced (host mfsmax.docomo.ne.jp[203.138.180.112] said: 550 Unknown user tt_moon_ametamas@docomo.ne.jp (in reply to end of DATA command))
解決策
参考URL
http://app.m-cocolog.jp/t/typecast/71249/67411/3669589/list_comments
◆PCto携帯メール不可 550 Unknown user (ドコモの迷惑メール拒否設定)◆
ドコモショップで家内の母の携帯を、F883iSに機種変更。PCから携帯に送信
すると、
メールアドレスが存在しないとの下記メッセージで送信不可。
Remote-MTA: dns; mfsmax.docomo.ne.jp
Diagnostic-Code: smtp; 550 Unknown user bbbbbb@docomo.ne.jp
相手(携帯)が拒否設定になっていると、メッセージしてくれば親切なのですが、
冷たくアドレスがない(unknow user)と拒否。
----- 現象と原因と解決策 -----
現象: 携帯=>PCは送信OK PC=>携帯は送信不可
原因: i-modeで迷惑メール拒否が設定されていた。
解決策: 注2の【受信・拒否設定】をみて、自分に適切な方法を選択
----- 事例:私のケース -----
原因: 下記①②が拒否設定となっていた。(注1参照)
解決策: 個別に受信したいドメイン、アドレスを登録
=パソコンのメールアドレスbbbbbb@docomo.ne.jpを登録。 (注2参照)
----- 確認方法と設定方法 -----
【拒否設定確認方法】
携帯電話 i-mode => iMenu => お客様サポート
=> 各種設定(確認・変更・利用) => 詳細な設定(メール設定) => メール
設定確認 =>
①URL付きメール拒否設定 ②携帯からのメール受信/拒否設定
③パソコンからのメール受信/拒否設定 ④大量送信者メール
⑤未承認広告メール ⑥メールサイズ制限 、、等々
【設定方法】<個別に受信許可アドレスを設定>
、、、、、 => メール設定 => 迷惑メール対策 => 認証 パスワード4桁 決定
=> 受信拒否設定 次へボタン => 説明注意 => ステップ4 受信設定ボタン
=> 個別に受信したいアドレス => bbbbbb@docomo.ne.jp を入力 登録ボタン
注1: 【設定確認方法】
http://www.nttdocomo.co.jp/info/spam_mail/confirmation/
注2: 【受信・拒否設定】 (最適な設定を選択)
http://www.nttdocomo.co.jp/info/spam_mail/measure/domain/index_image.html