Fedora Core: 2006年9月アーカイブ
参考サイト
★http://fedorasrv.com/postfix.shtml
http://www.aconus.com/~oyaji/centos/smtp-centos.htm
■Postfixインストール
|
■Postfix設定
| (1)Postfix設定 |
|
[root@fedora ~]# vi /etc/postfix/main.cf ← Postfix設定ファイル編集 # 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 = virtual.domain.tld myhostname = fedora.fedorasrv.com ← 追加(自FQDN名を指定) # 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 = fedorasrv.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 = $myhostname #myorigin = $mydomain myorigin = $mydomain ← 追加(ローカルからのメール送信時の送信元メールアドレス@以降にドメイン名を付加) # 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 #inet_interfaces = $myhostname #inet_interfaces = $myhostname, localhost inet_interfaces = localhost ↓ inet_interfaces = all ← 変更(外部からのメール受信を許可) # The mydestination parameter specifies the list of domains that this # machine considers itself the final destination for. # # These domains are routed to the delivery agent specified with the # local_transport parameter setting. By default, that is the UNIX # compatible delivery agent that lookups all recipients in /etc/passwd # and /etc/aliases or their equivalent. # # The default is $myhostname + localhost.$mydomain. On a mail domain # gateway, you should also include $mydomain. # # Do not specify the names of virtual domains - those domains are # specified elsewhere (see VIRTUAL_README). # # Do not specify the names of domains that this machine is backup MX # host for. Specify those names via the relay_domains settings for # the SMTP server, or use permit_mx_backup if you are lazy (see # STANDARD_CONFIGURATION_README). # # The local machine is always the final destination for mail addressed # to user@[the.net.work.address] of an interface that the mail system # receives mail on (see the inet_interfaces parameter). # # Specify a list of host or domain names, /file/name or type:table # patterns, separated by commas and/or whitespace. A /file/name # pattern is replaced by its contents; a type:table is matched when # a name matches a lookup key (the right-hand side is ignored). # Continue long lines by starting the next line with whitespace. # # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS". # mydestination = $myhostname, localhost.$mydomain, localhost ↓ mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← 変更(自ドメイン宛メールを受信できるようにする) #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, # mail.$mydomain, www.$mydomain, ftp.$mydomain # 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/ home_mailbox = Maildir/ ← 追加(メールボックス形式をMaildir形式にする) # SHOW SOFTWARE VERSION OR NOT # # The smtpd_banner parameter specifies the text that follows the 220 # code in the SMTP server's greeting banner. Some people like to see # the mail version advertised. By default, Postfix shows no version. # # You MUST specify $myhostname at the start of the text. That is an # RFC requirement. Postfix itself does not care. # #smtpd_banner = $myhostname ESMTP $mail_name #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) smtpd_banner = $myhostname ESMTP unknown ← 追加(メールサーバーソフト名の隠蔽化) 以下を最終行へ追加(SMTP-Auth設定) smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination 以下を最終行へ追加(メール不正中継ホストのデータベースに登録されているホストからの接続を拒否する場合) smtpd_client_restrictions = reject_rbl_client relays.ordb.org 以下を最終行へ追加(SMTP-Auth設定) message_size_limit = 10485760 ← 追加(受信メールサイズを10MB=10*1024*1024に制限) |
(2)SMTP-Auth設定 SMTP-Auth用ユーザ名、パスワードにシステムのユーザ名、パスワードを使用する場合) |
|
SMTP-Auth用ユーザ名、パスワードとシステムのユーザ名、パスワードを別々にする場合 |
|
(3)Maildir形式メールボックス作成 Postfixのメール格納形式は共有ディレクトリ形式(「/var/spool/mail/ユーザ名」というファイルに全てのメールが蓄積されていく形式)だが、アクセス性能改善及びセキュリティ強化の観点からMaildir形式へ移行する。 【既存ユーザ対処】 既存ユーザのホームディレクトリにMaildir形式のメールボックスを作成して、蓄積済のメールデータを当該メールボックスへ移行する⇒メールデータ移行を参照 【新規ユーザ対処】 新規ユーザ追加時に自動でホームディレクトリにMaildir形式のメールボックスが作成されるようにする |
|
[root@fedora ~]# mkdir -p /etc/skel/Maildir/new ← 新規ユーザ追加時に自動でMaildir形式メールボックス作成(1/4) [root@fedora ~]# mkdir -p /etc/skel/Maildir/cur ← 新規ユーザ追加時に自動でMaildir形式メールボックス作成(2/4) [root@fedora ~]# mkdir -p /etc/skel/Maildir/tmp ← 新規ユーザ追加時に自動でMaildir形式メールボックス作成(3/4) [root@fedora ~]# chmod -R 700 /etc/skel/Maildir/ ← 新規ユーザ追加時に自動でMaildir形式メールボックス作成(4/4) |
(4)未承諾広告メールの削除 未承諾広告メール(件名に「未承諾広告※」と表示されているメール)は受信せずに削除するようにする。 |
|
[root@fedora ~]# vi /etc/postfix/main.cf ← Postfix設定ファイル編集 # The mailbox_command parameter specifies the optional external # command to use instead of mailbox delivery. The command is run as # the recipient with proper HOME, SHELL and LOGNAME environment settings. # Exception: delivery for root is done as $default_user. # # Other environment variables of interest: USER (recipient username), # EXTENSION (address extension), DOMAIN (domain part of address), # and LOCAL (the address localpart). # # Unlike other Postfix configuration parameters, the mailbox_command # parameter is not subjected to $parameter substitutions. This is to # make it easier to specify shell syntax (see example below). # # Avoid shell meta characters because they will force Postfix to run # an expensive shell process. Procmail alone is expensive enough. # # IF YOU USE THIS TO DELIVER MAIL SYSTEM-WIDE, YOU MUST SET UP AN # ALIAS THAT FORWARDS MAIL FOR ROOT TO A REAL USER. # #mailbox_command = /some/where/procmail #mailbox_command = /some/where/procmail -a "$EXTENSION" mailbox_command = /usr/bin/procmail ← 追加(Procmailと連携するようにする) [root@fedora ~]# vi /etc/procmailrc ← procmail設定ファイル作成 SHELL=/bin/bash PATH=/usr/bin:/bin DROPPRIVS=yes MAILDIR=$HOME/Maildir DEFAULT=$MAILDIR/ #LOGFILE=$HOME/procmail.log # ログ出力先 #VERBOSE=ON # 詳細ログ出力 # 未承諾広告メール削除※システムの文字コードがUTF-8(デフォルト)の場合 :0 * ^Subject:.*iso-2022-jp * ^Subject:\/.* * ? echo "$MATCH" | nkf -mwZ2 | sed 's/[[:space:]]//g' | egrep '未承諾広告※' /dev/null # 未承諾広告メール削除※システムの文字コードがEUCの場合 :0 * ^Subject:.*iso-2022-jp * ^Subject:\/.* * ? echo "$MATCH" | nkf -meZ2 | sed 's/[[:space:]]//g' | egrep '未承諾広告※' /dev/null |
■Postfix起動
| (1)sendmail停止 デフォルトで起動しているSMTPサーバーであるsendmailを停止する |
|
(2)メールサーバー切替え システムで使用するメールサーバー機能をsendmailからPostfixに切替える |
|
(3)Postfix起動
|
(4)ポート25番のOPEN ルーター側の設定でポート25番をOPENする。 ポートチェック【外部からポート開放確認】で「host名」にサーバー名(例:fedorasrv.com)、「port番号」に25と入力して「ポートチェック」ボタン押下し、「ホスト=fedorasrv.com ポート=25 にアクセスできました。」と表示されることを確認。 |
■Dovecot設定
|
■Dovecot起動
| (1)Dovecot起動 |
|
(2)ポート110番(POPの場合)または143番(IMAPの場合)のOPEN ルーター側の設定でポート110番(POPの場合)または143番(IMAPの場合)をOPENする。 ポートチェック【外部からポート開放確認】で「host名」にサーバー名(例:fedorasrv.com)、「port番号」に110(POPの場合)または143(IMAPの場合)と入力して「ポートチェック」ボタン押下し、「ホスト=fedorasrv.com ポート=110(POPの場合)または143(IMAPの場合) にアクセスできました。」と表示されることを確認。 |
■メールユーザ追加
| (1)メールユーザ追加(SSHによるリモート接続はできないようにする場合) ※例としてユーザ名をfedoraとする |
|
[root@fedora ~]# useradd -s /sbin/nologin fedora ← ユーザ追加 [root@fedora ~]# passwd fedora ← パスワード設定 Changing password for user fedora. New UNIX password: ← パスワード応答 Retype new UNIX password: ← パスワード応答(確認) passwd: all authentication tokens updated successfully. 以下はSMTP-Auth用ユーザ名、パスワードとシステムのユーザ名、パスワードを別々にする場合のみ [root@fedora ~]# echo "パスワード" | saslpasswd2 -p -u fedora.fedorasrv.com -c fedora ← SMTP-Auth用ユーザ/パスワード登録 [root@fedora ~]# sasldblistusers2 ← SMTP-Auth用ユーザ名、パスワード確認 fedora@fedora.fedorasrv.com: userPassword [root@fedora ~]# chgrp postfix /etc/sasldb2 ← sasldb2所有グループをpostfixに変更※最初の1回のみ ※SMTP-Auth用ユーザ名、パスワードを削除する場合 [root@fedora ~]# saslpasswd2 -d fedora -u fedora.fedorasrv.com ← SMTP-Auth用ユーザ名、パスワード削除 |
(2)メールユーザ追加(SSHによるリモート接続もできるようにする場合) ※例としてユーザ名をfedoraとする |
|
[root@fedora ~]# useradd fedora ← ユーザ追加 [root@fedora ~]# passwd fedora ← パスワード設定 Changing password for user fedora. New UNIX password: ← パスワード応答 Retype new UNIX password: ← パスワード応答(確認) passwd: all authentication tokens updated successfully. 以下はSMTP-Auth用ユーザ名、パスワードとシステムのユーザ名、パスワードを別々にする場合のみ [root@fedora ~]# echo "パスワード" | saslpasswd2 -p -u fedora.fedorasrv.com -c fedora ← SMTP-Auth用ユーザ/パスワード登録 [root@fedora ~]# sasldblistusers2 ← SMTP-Auth用ユーザ名、パスワード確認 fedora@fedora.fedorasrv.com: userPassword [root@fedora ~]# chgrp postfix /etc/sasldb2 ← sasldb2所有グループをpostfixに変更※最初の1回のみ ※SMTP-Auth用ユーザ名、パスワードを削除する場合 [root@fedora ~]# saslpasswd2 -d fedora -u fedora.fedorasrv.com ← SMTP-Auth用ユーザ名、パスワード削除 |
(3)既存ユーザをメールユーザとする場合 ※例としてユーザ名をfedoraとする |
|
以下はSMTP-Auth用ユーザ名、パスワードとシステムのユーザ名、パスワードを別々にする場合のみ [root@fedora ~]# echo "パスワード" | saslpasswd2 -p -u fedora.fedorasrv.com -c fedora ← SMTP-Auth用ユーザ/パスワード登録 [root@fedora ~]# sasldblistusers2 ← SMTP-Auth用ユーザ名、パスワード確認 fedora@fedora.fedorasrv.com: userPassword [root@fedora ~]# chgrp postfix /etc/sasldb2 ← sasldb2所有グループをpostfixに変更※最初の1回のみ ※SMTP-Auth用ユーザ名、パスワードを削除する場合 [root@fedora ~]# saslpasswd2 -d fedora -u fedora.fedorasrv.com ← SMTP-Auth用ユーザ名、パスワード削除 |
■メール不正中継拒否テスト
|
# yum install postfix
# vi /etc/postfix/main.cf
Postfixの設定は、/etc/postfix/main.cf
を編集します。SMTPを動かすための基本的な設定を下記により行います。ここでは、修正した部分のみ記載しています。(青字は削除、赤字は追加、緑字は変更したものです。)
# ホスト名の設定
# myhostnameでは、通常サーバのホスト名を指定する。しかし、ここで設定するホスト名は
# myoriginの設定と関係しており、myoriginをmyhostnameとした場合は、このホスト名は
# インターネット上でDNSで名前解決できるホスト名でなければならない。
# zive.orgのように、MXを使うとホスト名が使えない場合は、サブドメインをそのまま指定すればよい。
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mail.aconus.com
# ドメイン名の設定
#mydomain = domain.tld
mydomain = aconus.com
# メール送信の設定
# ローカルで配送されたメールがどこからくるように見えるか指定するもので、デフォルトの
# $myhostnameを指定すればいい。分かりにくい表現であるが、ここの値は、localhostが
# 送信する場合のホスト名として@以下に設定されるもので、例えば、デーモンが吐くメール
# やCGIでメールを送信したり、procmailで転送する場合の送信元に設定される。従って、
# ここで指定されたホスト名は、インターネット上でDNSが牽ける名前でないと、相手サーバで
# エラー発生時に返信するためチェックされており、その時点で蹴られてしまうので、注意が
# 必要である。
# ここでの設定は後述するsaslpasswd2の設定時のmydomainと同一でないとエラーとなるので
# 注意が必要。
#myorigin = $myhostname
#myorigin = $mydomain
myorigin = $myhostname
# メール受信の設定
# メールを受け取るネットワークインタフェースのアドレス範囲を指定する。特別な用件が無ければ指定不要(default=all)。
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
inet_interfaces = all
# メールの最終目的地とみなす範囲の指定
#mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# 信頼できるクライアントのネットワークを指定(192.168.0.0/24と192.168.1.0/24を合わせて指定)
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
mynetworks = 192.168.0.0/23, 127.0.0.0/8
# リレーを許可するドメインを指定
#relay_domains = $mydestination
relay_domains = $mydestination
# メールBOXの形式を指定
# Courier-imapを使うため、Maildir形式とする。
#home_mailbox = Mailbox
#home_mailbox = Maildir/
home_mailbox = Maildir/
# sendmail互換プログラムの修正
# sendmail互換プログラムがsendmail.postfixとなっており、CGIとの整合が取れないので修正する。
# CGI側を修正する場合は、下記を含めて修正は不要です。
#sendmail_path = /usr/sbin/sendmail.postfix
sendmail_path = /usr/sbin/sendmail
◆sendmail互換プログラムの修正
messagesにsendmailのpathがおかしいと出ていたので調査したところ、/usr/sbin/sendmailが互換プログラムに置き換わっておらず、CGIからのメール利用ができなくなっていました。下記で修正が必要です。
# mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
# ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail
◆aliasesの修正
RPMからインストールするとroot宛てのメッセージがpostfix宛てに配送されるようになっています。postfixユーザを追加するか、メールを受け取れる実在するユーザに配送先を変更する必要があります。ここでは、おやじ宛てに配送する変更例を示します。
# vi /etc/aliases
postfix: root # この行を追加
[Esc]、[:]、[w]、[q]で保存し、newaliasesを実行。
# newaliases