メールサーバー · 2 min read · Nov 16, 2025
完璧なサーバー - CentOS 5.6 x86_64 [ISPConfig 2] - ページ 5
11 Postfix と SMTP-AUTH および TLS
Postfix と Dovecot をインストールします (Dovecot は POP3/IMAP サーバーになります):
yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain postfix dovecot次に、SMTP-AUTH と TLS を設定します:
postconf -e ‘smtpd_sasl_local_domain =’ postconf -e ‘smtpd_sasl_auth_enable = yes’ postconf -e ‘smtpd_sasl_security_options = noanonymous’ postconf -e ‘broken_sasl_auth_clients = yes’ postconf -e ‘smtpd_sasl_authenticated_header = yes’ postconf -e ‘smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination’ postconf -e ‘inet_interfaces = all’ postconf -e ‘mynetworks = 127.0.0.0/8’
Postfix が PLAIN と LOGIN ログインを許可するように /usr/lib64/sasl2/smtpd.conf を編集する必要があります。32Bit CentOS 5.6 では、代わりに /usr/lib/sasl2/smtpd.conf を編集する必要があります。次のようになります:
vi /usr/lib64/sasl2/smtpd.conf| pwcheck_method: saslauthd mech_list: plain login |
その後、TLS 用の証明書を作成します:
mkdir /etc/postfix/ssl cd /etc/postfix/ssl/ openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crtopenssl rsa -in smtpd.key -out smtpd.key.unencryptedmv -f smtpd.key.unencrypted smtpd.key openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
次に、Postfix を TLS 用に設定します:
postconf -e ‘smtpd_tls_auth_only = no’ postconf -e ‘smtp_use_tls = yes’ postconf -e ‘smtpd_use_tls = yes’ postconf -e ‘smtp_tls_note_starttls_offer = yes’ postconf -e ‘smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key’ postconf -e ‘smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt’ postconf -e ‘smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem’ postconf -e ‘smtpd_tls_loglevel = 1’ postconf -e ‘smtpd_tls_received_header = yes’ postconf -e ‘smtpd_tls_session_cache_timeout = 3600s’ postconf -e ‘tls_random_source = dev:/dev/urandom’
次に、Postfix インストールのホスト名を設定します (server1.example.com を自分のホスト名に置き換えてください):
postconf -e 'myhostname = server1.example.com'これらの設定ステップの後、/etc/postfix/main.cf は次のようになります (すべてのコメントを削除しました):
cat /etc/postfix/main.cf| queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix mail_owner = postfix inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost unknown_local_recipient_reject_code = 550 alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb $daemon_directory/$process_name $process_id & sleep 5 sendmail_path = /usr/sbin/sendmail.postfix newaliases_path = /usr/bin/newaliases.postfix mailq_path = /usr/bin/mailq.postfix setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /usr/share/doc/postfix-2.3.3/samples readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES smtpd_sasl_local_domain = smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_authenticated_header = yes smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination mynetworks = 127.0.0.0/8 smtpd_tls_auth_only = no smtp_use_tls = yes smtpd_use_tls = yes smtp_tls_note_starttls_offer = yes smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem smtpd_tls_loglevel = 1 smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s tls_random_source = dev:/dev/urandom myhostname = server1.example.com |
デフォルトでは、CentOS の Dovecot デーモンは IMAP および IMAPs サービスのみを提供します。POP3 および POP3s も必要な場合は、Dovecot を設定する必要があります。/etc/dovecot.conf を編集し、protocols = imap imaps pop3 pop3s の行を有効にします:
vi /etc/dovecot.conf| [...] # サービスを提供したいプロトコル: imap imaps pop3 pop3s # dovecot-auth のみを使用したい場合は、これを "none" に設定できます。 protocols = imap imaps pop3 pop3s [...] |
Postfix、saslauthd、および Dovecot を起動します:
chkconfig –levels 235 sendmail off chkconfig –levels 235 postfix on chkconfig –levels 235 saslauthd on chkconfig –levels 235 dovecot on /etc/init.d/sendmail stop /etc/init.d/postfix start /etc/init.d/saslauthd start /etc/init.d/dovecot start
SMTP-AUTH と TLS が正常に動作しているか確認するには、次のコマンドを実行します:
telnet localhost 25 Postfix メールサーバーへの接続が確立されたら、次のように入力します:
ehlo localhost 次の行が表示される場合:
250-STARTTLS および
250-AUTH LOGIN PLAIN すべてが正常です。
[root@server1 ssl]# telnet localhost 25
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
220 server1.example.com ESMTP Postfix
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@server1 ssl]#
quit を入力してシステムのシェルに戻ります。
11.1 Maildir
Dovecot は Maildir 形式 (mbox ではない) を使用するため、サーバーに ISPConfig をインストールする場合は、Management -> Server -> Settings -> Email で Maildir を有効にしてください。ISPConfig は必要な設定を行います。
ISPConfig をインストールしたくない場合は、Postfix を設定してユーザーの Maildir にメールを配信する必要があります (ISPConfig を使用している場合でもこれを行うことができます - 害はありません ;-)):
postconf -e ‘home_mailbox = Maildir/‘
postconf -e ‘mailbox_command =’
/etc/init.d/postfix restart
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。