はじめての自宅サーバ構築 - Fedora/CentOS - Last Update 2008/07/25
It opened to 2004/09/19.
当サイトはFedora9で運用しています
Visitors
Pageviews
Today(IP/PV)
3,374,121
12,762,129
1,279/8,751
動作確認 [ FC1 / FC2 / FC3 / FC4 / FC5 / FC6 / Fedora7 / Fedora8 / Fedora9 / CentOS4 / CentOS5 ]
  1. postfixとは・・・
  2. postfixのインストール
  3. postfixの設定
  4. メールボックスの設定
  5. SMTP-Authユーザパスワードの設定
  6. sendmailサービスの停止とデフォルトMTAの変更
  7. OSの再起動を行なった時にpostfix(SMTPサーバ)・SMTP-Authを自動的に起動するように設定する
  8. postfix・SMTP-Authの起動
  9. 接続前の準備
  10. クライアントメールソフトの設定
    設定例(Becky!)
  11. 管理者宛へのメールを一般ユーザに送る
  12. こんな時は・・・

■ postfixとは・・・

皆さんが通常使っている電子メールについて、簡単にご説明します。
電子メールの送受信をする為に、プロバイダから指定されているSMTPサーバ・POPサーバという欄を見たことがありませんか?
このSMTPサーバとPOPサーバとは何でしょう?
SMTPサーバ(送信メールサーバ)とは、皆さんが書いた電子メールをサーバ上から外部ネットワークに送信する機能を持ったサーバであり、
POPサーバ(受信メールサーバ)とはその逆に外部から電子メールをサーバに受信する機能を持ったサーバの事です。
大抵のプロバイダは、このSMTPサーバとPOPサーバは同じになっていると思います。
いわゆる、送信・受信の両方の機能を持っているサーバを指定している事になります。

postfixはSMTPの機能を持っています。ここでは、このpostfixを構築する方法をご紹介いたします。
また、グローバルから外部宛メールを送信できるようにSMTP-Authをもたせる事とします。(不正中継利用の防止)
POPサーバ(受信メールサーバ)を構築するにはメールサーバ(POP/IMAP)の構築(Dovecot)をご覧ください。

■ postfixのインストール

# yum -y install postfix

■ postfixの設定

設定ファイルの編集
# 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 = fedora.kajuhome.com

ドメイン名を設定する
# 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 = kajuhome.com

送信者メールアドレスの@以降をドメイン名にする
# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites.  If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
myorigin = $mydomain

Postfix が待ち受けるべき全てのネットワークインターフェースを指定
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on.  By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
inet_interfaces = all

メールをローカルで受信するドメイン名を指定(ドメイン全体のメールサーバ)
# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
        :
        :
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

信頼されたネットワークをCIDR (network/mask) 表記で指定(ローカルネットワーク)
# Alternatively, you can specify the mynetworks list by hand, in
# which case Postfix ignores the mynetworks_style setting.
#
# Specify an explicit list of network/netmask patterns, where the
# mask specifies the number of bits in the network part of a host
# address.
#
# You can also specify the absolute pathname of a pattern file instead
# of listing the patterns here. Specify type:table for table-based lookups
# (the value on the table right-hand side is not used).
#
mynetworks = 192.168.1.0/24, 127.0.0.0/8

中継を許可するドメインを指定
# The relay_domains parameter restricts what destinations this system will
# relay mail to.  See the smtpd_recipient_restrictions restriction in the
# file sample-smtpd.cf for detailed information.
        :
        :
# NOTE: Postfix will not automatically forward mail for domains that
# list this system as their primary or backup MX host. See the
# permit_mx_backup restriction in the file sample-smtpd.cf.
#
relay_domains = $mydestination

メールボックス(Maildir)を各ユーザのホームディレクトリに配置
# 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 = Maildir/

ホストの接続に関しての拒否(SPAM拒否設定)
smtpd_client_restrictions = permit_mynetworks,
                            reject_rbl_client relays.ordb.org,
                            permit

smtpd_client_restrictions 属性の「relays.ordb.org」について
2007年に入ってからメールログ「/var/log/maillog」に以下の様な「relays.ordb.org」接続エラーが多数でる様になりました。

Jan  4 03:54:34 fedora postfix/smtpd[24034]: warning: 164.68.9.218.relays.ordb.org: RBL lookup error:
 Host or domain name not found. Name service error for name=164.68.9.218.relays.ordb.org type=A:
 Host not found, try again

理由は不明ですが、メール出来ない場合や受信までの時間がかかる事、SPAM対策として発揮できていない理由により
以下の対策にする事をお勧めします。

ホストの接続に関しての設定
smtpd_client_restrictions = permit_mynetworks, reject_unknown_client, permit
    permit_mynetworks    :クライアントIPが $mynetworks に属していた場合は要求を許可する 
    reject_unknown_client:クライアントIPが DNS に PTR レコードを持たない場合等に要求を拒否


メール送信時にアカウント名・パスワードをサーバに通知し、メールサーバから認証を受ける
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_local_domain = $mydomain
            または (※1)
smtpd_sasl_local_domain = $myhostname

※1
「smtpd_sasl_local_domain」属性はメールアドレスの「@」以降の部分(当サイトであれば「kajuhome.com」に当たる)によって変更します。
SMTP認証に失敗する場合に切り替えて見てください

■ メールボックスの設定

新規ユーザを作成した場合、メールボックス(Maildir)を作成する様にする
# mkdir /etc/skel/Maildir
# chmod 700 /etc/skel/Maildir


既存ユーザのメールボックス(Maildir)を作成する(例:linuxユーザの場合)
一度設定すれば構いません。
# mkdir /home/linux/Maildir

既存ユーザ(linux)のメールボックス(Maildir)のパーミッション・オーナ・グループ変更パーミッション変更
# chmod 700 /home/linux/Maildir
オーナ・グループ変更
# chown linux:linux /home/linux/Maildir

■ SMTP-Authユーザパスワードの設定

既存のアカウント(ユーザ)のパスワードとSMTP-Authパスワードを別にする場合です。
SMTP-Authパスワードを明示的にしたい場合に設定して下さい。(推奨)
設定ファイルの変更(32bit版の場合)
# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: auxprop
先頭に「#」を付けてコメント化
#mech_list: plain login

設定ファイルの変更(64bit版の場合)
# vi /usr/lib64/sasl2/smtpd.conf
pwcheck_method: auxprop
先頭に「#」を付けてコメント化
#mech_list: plain login

※:上記の様に「32bit版」と「64bit版」では修正するファイルが違うので注意して下さい。
  当方は、この理由で送信できずに悩まされました。


既存ユーザ(linux)のSMTP-Auth(送信認証)パスワード設定する
# saslpasswd2 -u kajuhome.com -c linux
パスワードを入力
Password:
確認入力(上記のパスワードと同じ物を入れる)
Again (for verification):
SMTP-Authユーザの確認
# sasldblistusers2
linux@kajuhome.com: userPassword


sasldb2のパーミッション・グループ変更
初期時、一度設定すれば構いません。
sasldb2の確認
# ll /etc/sasldb2
-rw-------  1 root root 12288  7月 21 05:21 /etc/sasldb2
    ↑              ↑
グループ読取(なし)    グループ(root)
パーミッション変更
# chmod 640 /etc/sasldb2
グループ変更
# chgrp postfix /etc/sasldb2
sasldb2の確認
# ll /etc/sasldb2
-rw-r-----  1 root postfix 12288  7月 21 05:21 /etc/sasldb2

■ sendmailサービスの停止とデフォルトMTAの変更

今後は、メールをpostfixで行なう為、デフォルトで起動されているsendmailを停止します。
また、システムデフォルトのMTAがsendmailとなっている為、postfixへ変更します。

sendmailサービスの停止
# chkconfig sendmail off
設定内容を確認
# chkconfig --list sendmail
sendmail        0:オフ  1:オフ  2:オフ  3:オフ  4:オフ  5:オフ  6:オフ


デフォルトMTAの変更
# alternatives --config mta

2 プログラムがあり 'mta' を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

上記一覧の「postfix」側の番号を入力
Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2

■ OSの再起動を行なった時にpostfix(SMTPサーバ)・SMTP-Authを自動的に起動するように設定する

起動時にpostfixを起動する
# chkconfig postfix on
設定内容を確認
# chkconfig --list postfix
postfix         0:オフ  1:オフ  2:オン  3:オン  4:オン  5:オン  6:オフ

起動時にSMTP-Authを起動する
# chkconfig saslauthd on
設定内容を確認
# chkconfig --list saslauthd
saslauthd       0:オフ  1:オフ  2:オン  3:オン  4:オン  5:オン  6:オフ

■ postfix・SMTP-Authの起動

postfiixを起動する
# /etc/rc.d/init.d/postfix start
Starting postfix:                                          [  OK  ]

SMTP-Authを起動する
# /etc/rc.d/init.d/saslauthd start
saslauthd を起動中:                                        [  OK  ]

■ 接続前の準備

WANから接続するに当たって、ルータの設定が必要です。
ルータのポート開閉は、ご自分のルータ取扱説明書をご覧ください。
DNS名で接続するには事前にドメイン名の取得を行っている必要があります。(以下は代表的なものであり、また、当サイトが使用させて頂いております)

■ クライアントメールソフトの設定

当サイトで紹介しているpostfixの設定は、SMTP-Auth(送信認証)を使用する様に設定しています。
クライアントのメールソフトがSMTP-Auth(送信認証)に対応している必要があります。

主な、SMTP-Auth(送信認証)対応メールソフト

■ 設定例(Becky!)

SMTP-Authユーザパスワードを何処に設定するのか?という質問が多々見受けられるので「Becky!」を例にあげて説明します。
メールボックスの設定で「詳細」タブを開き、SMTP認証グループ内の以下の項目を指定します。

チェックボックスはデフォルトのままでも構いませんが、「CRAM-MD5」はチェックしておかないとエラーとなります。

■ 管理者宛へのメールを一般ユーザに送る

一般的にシステムに関するワーニングやアラート等は、Linux自身が管理者(root)へメールを自動的に送っています。
この情報を取得するには、管理者でログインして「# mail」コマンドで確認するか、rootアカウントでクライアントメーラソフト等で取得しなければなりません。
管理者(root)への接続はセキュリティ上、あまり良くありません。そこで、管理者へメールが送られた時、一般ユーザに転送(正確には移動)させる方法を紹介します。
aliasファイルの変更
# vi /etc/aliases
#
#  Aliases in this file will NOT be expanded in the header from
#  Mail, but WILL be visible over networks or from /bin/mail.
#
#       >>>>>>>>>>      The program "newaliases" must be run after
#       >> NOTE >>      this file is updated for any changes to
#       >>>>>>>>>>      show through to sendmail.
#

# Basic system aliases -- these MUST be present.
mailer-daemon:  postmaster
postmaster:     root

# General redirections for pseudo accounts.
bin:            root
daemon:         root
        :
        :
        :
# Person who should get root's mail
#root:          marc
root宛てをlinuxに変更
root:           linux

■ こんな時は・・・

■ 広告

ページ先頭へ

Copyright(©)2004-2008 First home server construction. All Right Reserved.