![]() |
| ◆ | Mailサーバー |
|
SMTPサーバー に postfix・ POP3サーバーに dovecot を使いMailサーバーを構築 |
|
| ◆ | Postfix のインストール |
|
[root@centos]# yum -y install postfix <--- 入力 |
|
| ◆ | Postfix の設定 |
|
[root@centos]# vi /etc/postfix/main.cf <--- 入力 途中略 # INTERNET HOST AND DOMAIN NAMES # # The myhostname parameter specifies the internet hostname of this # mail system. The default is to use the fully-qualified domain name # from gethostname(). $myhostname is used as a default value for many # other configuration parameters. # #myhostname = host.domain.tld <--- コメント解除して書き換え(ホスト名・ドメイン名を指定) ↓ myhostname = fedora-server.papa-net.info #myhostname = virtual.domain.tld # The mydomain parameter specifies the local internet domain name. # The default is to use $myhostname minus the first component. # $mydomain is used as a default value for many other configuration # parameters. # #mydomain = domain.tld <--- コメント解除して書き換え(ドメイン名を指定) ↓ mydomain = papa-net.info ### SENDING MAIL ### 途中略 #myorigin = $mydomain <--- コメント解除(ローカルからのメール送信時の送信元メールアドレス@以降に ↓ ドメイン名を付加) myorigin = $mydomain ### RECEIVING MAIL ### 途中略 inet_interfaces = localhost <--- 書き換え(外部からのメール受信を許可) ↓ inet_interfaces = all 途中略 mydestination = $myhostname, localhost.$mydomain, localhost <--- 追記 ↓ (自分のドメイン宛メールを受信できるようにする) mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 途中略 # TRUST AND RELAY CONTROL 途中略 #relay_domains = $mydestination <--- コメント解除(中継許可) ↓ relay_domains = $mydestination # INTERNET OR INTRANET 途中略 #relayhost = $mydomain #relayhost = [gateway.my.domain] #relayhost = [mailserver.isp.tld] #relayhost = uucphost #relayhost = [an.ip.add.ress] relayhost = [mail.***.***.ne.jp] <--- 追記(OP25B対策 /プロバイダーのSMTPサーバーのアドレス) 途中略 # DELIVERY TO MAILBOX # # The home_mailbox parameter specifies the optional pathname of a # mailbox file relative to a user's home directory. The default # mailbox file is /var/spool/mail/user or /var/mail/user. Specify # "Maildir/" for qmail-style delivery (the / is required). # #home_mailbox = Mailbox #home_mailbox = Maildir/ <--- コメント解除(メールボックス形式をMaildir形式にする) ↓ home_mailbox = Maildir/ 途中略 以下を最終行へ追加(SMTP-Auth設定) smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $mydomain, noplaintext smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination smtpd_sasl_security_options = noanonymous, noplaintext |
|
| ◆ | SMTP-Authの設定 |
|
SMTP認証の為のSASLのSMTP認証にはシステムアカウントを利用する方法と、sasldb2を利用する方法がある sasldb2を利用すれば、システムアカウントとは異なるパスワードを設定できるので、こちらの方がセキュリティは高くなる 必要なパッケージのインストール |
|
|
[root@centos]# yum -y install cyrus-sasl <--- 入力 [root@centos]# yum -y install cyrus-sasl-devel <--- 入力 [root@centos]# yum -y install cyrus-sasl-lib <--- 入力 [root@centos]# yum -y install cyrus-sasl-plain <--- 入力 [root@centos]# yum -y install cyrus-sasl-md5 <--- 入力 |
|
| <<<<< システムアカウントを利用した認証(pamを利用)>>>>> | |
| Postfix の設定 | |
|
[root@centos]# vi /etc/postfix/main.cf <--- 入力 途中略 smtpd_sasl_security_options = noanonymous, noplaintext <--- 書き換え(削除) ↓ smtpd_sasl_security_options = noanonymous |
|
| saslauthd の設定 | |
|
[root@centos]# vi /etc/sysconfig/saslauthd <--- 入力 途中略 # Mechanism to use when checking passwords. Run "saslauthd -v" to get a list # of which mechanism your installation was compiled with the ablity to use. MECH=pam <--- 確認(もし shadow になっていたら書き換え) 以下略 |
|
| saslauthd の起動 | |
|
[root@centos]# /etc/rc.d/init.d/saslauthd start <--- 入力 |
|
| saslauthd の自動 起動設定 | |
|
[root@centos]# chkconfig saslauthd on <--- 入力 |
|
| 自動起動設定の確認 | |
|
[root@centos]# chkconfig --list saslauthd <--- 入力 saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 2・3・4・5 が on になっていればOK |
|
| <<<<< sasldb2による認証 >>>>> | |
| smtpd.conf の設定 | |
|
[root@centos]# vi /usr/lib/sasl2/smtpd.conf <--- 入力 pwcheck_method: saslauthd <--- 書き換え ↓ pwcheck_method: auxprop |
|
| saslauthd の設定 | |
|
[root@centos]# vi /etc/sysconfig/saslauthd <--- 入力 MECH=pam <--- コメント化(MECH=shadow の場合もある) ↓ #MECH=pam FLAGS= <--- 書き換え ↓ FLAGS=sasldb |
|
| SASLデータベースのユーザ管理(登録) | |
|
[root@centos]# saslpasswd2 -u crimson-snow.net -c abc <--- 入力(ユーザー abc 追加) password: ****** <--- パスワード入力(* は実際には表示されません) Again (for verification): ****** <--- 再度 パスワード入力(* は実際には表示されません) |
|
| SASLデータベースのユーザ管理(パスワード変更) | |
|
[root@centos]# saslpasswd2 -u crimson-snow.net abc <--- 入力(ユーザー abc パスワード変更) password: ****** <--- パスワード入力(* は実際には表示されません) Again (for verification): ****** <--- 再度 パスワード入力(* は実際には表示されません) |
|
| SASLデータベースのユーザ管理(削除) | |
|
[root@centos]# saslpasswd2 -u crimson-snow.net -d abc <--- 入力(ユーザー abc 削除) |
|
| SASLデータベースのユーザ管理(ユーザー確認) | |
|
[root@centos]# sasldblistusers2 <--- 入力(ユーザー確認) abc@crimson-snow.net: userPassword <--- ユーザー abc xyz@crimson-snow.net: userPassword <--- ユーザー xyz |
|
| SALSデータベースをPostfixから参照できるようにする(最初の1回のみ) | |
|
[root@centos]# chgrp postfix /etc/sasldb2 <--- 入力 |
|
| SALSデータベースのアクセス権変更 | |
|
[root@centos]# chmod 640 /etc/sasldb2 <--- 入力 |
|
| saslauthd の起動 | |
|
[root@centos]# /etc/rc.d/init.d/saslauthd start <--- 入力 |
|
| saslauthd を自動起動設定 | |
|
[root@centos]# chkconfig saslauthd on <--- 入力 |
|
| 自動起動設定の確認 | |
|
[root@centos]# chkconfig --list saslauthd <--- 入力 saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 2・3・4・5 が on になっていればOK |
|
| ◆ | Postfix の起動 |
|
[root@centos]# /etc/rc.d/init.d/postfix start <--- 入力 |
|
| Postfix を自動起動設定 | |
|
[root@centos]# chkconfig postfix on <--- 入力 |
|
| 自動起動設定の確認 | |
|
[root@centos]# chkconfig --list postfix <--- 入力 postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 2・3・4・5 が on になっていればOK |
|
| ◆ | SMTPサーバーの変更 |
| sendmail がインストールされている場合 | |
| sendmail の停止 | |
|
[root@centos]# /etc/rc.d/init.d/sendmail stop <--- 入力 |
|
| sendmail を自動起動解除設定 | |
|
[root@centos]# chkconfig sendmail off <--- 入力 |
|
| 自動起動解除設定の確認 | |
|
[root@centos]# chkconfig --list sendmail <--- 入力 sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off <--- 全てが off になっていればOK |
|
| デフォルトのSMTPサーバーの変更 | |
|
[root@centos]# alternatives --config mta <--- 入力 2 プログラムがあり 'mta' を提供します。 選択 コマンド ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.postfix Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2 <--- 2 を入力 |
|
| 変更の確認 | |
|
[root@centos]# alternatives --config mta <--- 入力 2 プログラムがあり 'mta' を提供します。 選択 コマンド ----------------------------------------------- * 1 /usr/sbin/sendmail.sendmail + 2 /usr/sbin/sendmail.postfix Enter を押して現在の選択 [+] を保持するか、選択番号を入力します: <--- Enter を押す |
|
| ◆ | バーチャルドメインの追加 |
| 通常使う papa-net ドメインの他に abc.papa-net.info ドメインを追加 | |
|
[root@centos]# vi /etc/postfix/virtual <--- 入力 ---最終行に以下を追記--- abc.papa-net.info anything @abc.papa-net.info @papa-net.info |
|
| 設定の反映 | |
|
[root@centos]# postmap /etc/postfix/virtual <--- 入力 |
|
| Postfix の設定 | |
|
[root@centos]# vi /etc/postfix/main.cf <--- 入力 ---最終行に以下を追記--- virtual_maps = hash:/etc/postfix/virtual |
|
| ◆ | Dovecot のインストール |
|
[root@centos]# yum -y install dovecot <--- 入力 |
|
| ◆ | Dovecotの設定 |
| 設定ファイルが分割されているので二つのファイルを設定 | |
|
[root@centos]# vi /etc/dovecot/dovecot.conf <--- 入力 途中略 # Protocols we want to be serving. #protocols = imap pop3 lmtp <--- コメント解除 して書き換え ↓ protocols = imap imaps pop3 pop3s lmtp 以下略 |
|
|
[root@centos]# vi /etc/dovecot/conf.d/10-auth.conf <--- 入力 ## ## Authentication processes ## # Disable LOGIN command and all other plaintext authentications unless # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP # matches the local IP (ie. you're connecting from the same computer), the# connection is considered secure and plaintext authentication is allowed. #disable_plaintext_auth = yes <--- コメント解除 して書き換え ↓ disable_plaintext_auth = no 以下略 |
|
| ◆ | Dovecotの起動 |
|
[root@centos]# /etc/rc.d/init.d/dovecot start <--- 入力 |
|
| Dovecot を自動起動設定 | |
|
[root@centos]# chkconfig dovecot on <--- 入力 |
|
| 自動起動設定の確認 | |
|
[root@centos]# chkconfig --list dovecot <--- 入力 dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 2・3・4・5 が on になっていればOK |
|
| ◆ | Mailサーバーの送受信テスト |
|
・ポートチェック(ポート開放確認) http://www.cman.jp/network/support/port.html にアクセスしてポートの開放状態をチェック 正常にアクセス出来ない場合はルーターの設定やファイアーフォールの設定を再度確認 |
|
| ・サーバー内送信テスト | |
|
[root@centos]# mail root <--- 入力 (root 宛てにメールを送信) Subject: test <--- 入力 (件名) Hello <--- 入力 (本文) . <--- 入力 (ドット入力で終了) EOT |
|
| ・サーバー外送信テスト | |
|
[root@centos]# echo "Hello" | mail -s test abc@yahoo.com <--- 入力 (自分のアドレス宛てメール送信) |
|
|
サーバー内外送信テストを行って正常にメールが届けばOK もし、届かない場合は再度設定を確認 また、メールのログは下記にて確認 |
|
|
[root@centos]# more /var/log/maillog <--- 入力 |
|
| ◆ | 第三者中継テスト |
| 第三者に不正中継されないかテスト | |
| http://www.rbl.jp/svcheck.php にアクセスし “ ホスト名 ” のところに自分のSMTPサーバー名を入力して “ Check ” をクリック | |
|
全部のテストにパスすると一番下に青い文字で
no relays accepted. 一部または全部がエラーになると一番下に赤い文字で 5 relays accepted. などと不合格の数が表示されます。 |
|
| no relays accepted. と表示されればひとまず安心 | |
| ◆ | メールユーザー |
| ・新規ユーザー 新規ユーザー追加時に自動的にメールボックス作成 |
|
|
[root@centos]# mkdir -p /etc/skel/Maildir/new <--- 入力 [root@centos]# mkdir -p /etc/skel/Maildir/cur <--- 入力 [root@centos]# mkdir -p /etc/skel/Maildir/tmp <--- 入力 |
|
| アクセス権の設定 | |
|
[root@centos]# chmod -R 700 /etc/skel/Maildir/ <--- 入力 |
|
| ・既存ユーザー 既存ユーザーのメールボックス作成 |
|
|
[root@centos]# mkdir /home/****/Maildir/new <--- 入力(ユーザー **** のメールボックス作成) [root@centos]# mkdir /home/****/Maildir/cur <--- 入力(ユーザー **** のメールボックス作成) [root@centos]# mkdir /home/****/Maildir/tmp <--- 入力(ユーザー **** のメールボックス作成) |
|
| アクセス権の設定 | |
|
[root@centos]# chmod -R 700 /home/****/Maildir/ <--- 入力(ユーザー **** のアクセス権の設定) |
|
| 所有権の設定 | |
|
[root@centos]# chown -R **** /home/**** <--- 入力(ユーザー **** に所有権の設定) |
|