====== Postfix でメールサーバ ======
メールサーバとして Postfix をインストール。
===== Postfixのインストール =====
apt-get でインストール。
$ sudo apt-get install postfix
インストール中にダイアログで Postfic の設定ができる。
最初にサーバの使用目的についての説明がでるので、読んだら OK を押す。
* General type of mail configuration
* Internet Site を選択
* System mail name
* 使用するメールアドレスの@以下のアドレス部分を入力
===== 設定 =====
インストール中の設定ではほとんど設定できていないので、追加で設定。
設定用のコマンドがあるのでそれを利用する。
$ sudo dpkg-reconfigure postfix
途中まではインストール中に設定した項目なので飛ばす。
* Root and posmaster mail recipient
* root 宛のメールを転送するユーザ 都合良いユーザのユーザ名を入力
* Other destinations to accept mail for (blank for none)
* 自サーバへのメールと解釈するアドレスをカンマ区切りで入力
* mail.example.com, localhost.localdomain, localhost
* Force synchronous updates on mail queue?
* メールキューの設定のようだが、おそらく大規模なメールサーバでなければどちらでも関係ないと思われ
* No
* Local networks
* ローカルネットワークのアドレスを追加で入力
* 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24
* Mailbox size limit (byte)
* mailbox のサイズを設定。後で maildir 形式に変更するので、0を設定
* Local address extension character
* 何に使うのかよくわからない。デフォルトのままで
* Internet protocols to use
* IPv4 しか使わないので ipv4 を選択
メール保存形式をデフォルトの mbox から maildir に変更。
$ sudo postconf -e 'home_mailbox = Maildir/'
設定内容は /etc/postfix/main.cf に保存されている。
====== SMTP Authentication ======
SASLを使って暗号化された回線でSMTP接続できるようにする。
/etc/postfix/main.cf に以下を追加。
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth-client
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
inet_interfaces = all
サーバの鍵を用意する。[[ubuntu-server-10-04:self-signed_certificate|自己署名サーバ証明書の作成]]
サーバの鍵を /etc/ssl/private/server.key に crtファイルを /etc/ssl/certs/server.crt に配置。
server.key はパスワードが解除してあるので、パーミッションとオーナーを変更しておく。
$ sudo chown root:ssl-cert /etc/ssl/private/server.key
$ sudo chmod 640 /etc/ssl/private/server.key
CAの証明書を /etc/ssl/certs/cacert.pem に配置。
/etc/postfix/main.cf に以下を追加。
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/ssl/private/server.key
smtpd_tls_cert_file = /etc/ssl/certs/server.crt
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
myhostname = mail.example.com
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
* mail.example.com はサーバのアドレスに置き換える
最後に Postfix を再起動。
$ sudo /etc/init.d/postfix restart
====== SASLの設定 ======
AMTP Authentication で使用する SASL を設定する。
必要なパッケージをインストール。
$ sudo apt-get install dovecot-common
/etc/dovecot/dovecot.conf を編集する。socket listen を検索して以下のように変更。
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
path = /var/spool/postfix/private/auth-client
mode = 0660
user = postfix
group = postfix
}
}
Outlook から接続する場合は mechanisms に login を追加。
$ mechanisms = plain login
====== テスト ======
設定が終わったら telnet でテストする。
$ telnet mail.example.com 25
telnet から以下のコマンドを実行。
ehlo mail.example.com
以下の出力が含まれていれば OK。"LOGIN" は Outlook のための設定を行った場合に表示される。
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
====== SSL/TLS接続を有効にする ======
STARTTLS ではなく直接465ポートにアクセスして暗号化接続を行えるようにする。
$ sudo vi /etc/postfix/master.cf
コメントを3行分はずす。
smtps inet n - - - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
その後再起動かリロード。
$ sudo /etc/init.d/postfix restart
====== スパムの踏み台チェック ======
外部からの不正リレーをきちんと防げているかをチェックするには、メールサーバから以下のコマンドを実行する。
$ telnet relay-test.mail-abuse.org
* 参考: [[http://www.postfix-jp.info/origdocs/antispam.html|Postfix antispam]]
===== root 宛てのメールを転送 =====
root にメールを送信されても受信する機会がないので、root 宛てのメールはシステム管理をするユーザに転送する。
$ sudo vi /etc/aliases
root 宛てのメッセージを他のユーザに転送する。
# See man 5 aliases for format
postmaster: root
root: foobar
/etc/aliases を編集した後に以下のコマンドで設定を適用する。
$ sudo newaliases
===== 参考 =====
[[https://help.ubuntu.com/10.04/serverguide/C/postfix.html|公式ドキュメント Postfix インストール]]