ここではpostfixの/etc/postfix/main.cfにてmynetworks と mynetworks_style は共に未定義である。

[root@c ~]# grep -e "^#mynetworks" -e "^##mynetworks_style" /etc/postfix/main.cf
#mynetworks_style = class
#mynetworks_style = subnet
#mynetworks_style = host
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
[root@c ~]#

そのため、このメールサーバが所属するドメインなら無認証でメールを送信できる(メールサーバを踏み台にして外にメールを出せる)

[root@c ~]# postconf |grep ^mynetworks
mynetworks = 127.0.0.0/8 192.168.0.0/24 [::1]/128 [fe80::]/64
mynetworks_style = subnet
[root@c ~]#

この許諾範囲を制限させ、smtp認証でしかメールを送信できなくしてみる。加えてSSLによる保護と暗号化されたパスワード認証を施してみる。そうすることで外出先からもメールを送信できるようになる。(ルータの調整は必要)

mynetworksの制限

mynetworks行を追加します

[root@c ~]# vi /etc/postfix/main.cf
 :
mynetworks = 127.0.0.0/8
[root@c ~]#

確認

[root@c postfix]# postconf | grep ^mynetworks
mynetworks = 127.0.0.0/8
mynetworks_style = subnet
[root@c postfix]#

これでローカルホストのみが無認証でメールを送信できる。
っが、smtpd_sasl_auth_enableを有効にして、smtpd_sasl_security_optionsに「noanonymous」を加えれば全て認証必須になる

[root@c ~]# vi /etc/postfix/main.cf
 :
#mynetworks = 127.0.0.0/8
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous, noplaintext
[root@c ~]#

smtp認証用のパスワード

[root@c ~]# yum install cyrus-imapd

ここで分岐点がある

1.の場合、pam経由でLinuxログインに使用するパスワードをsmtpの認証用パスワードとして使用できる。
なので、ldapからのパスワードを使用することにもなるのだが
その設定方法は、まず下記のpwcheck_method:にて「saslauthd」を指定します。
そして認証方式を平文で通すなら「plain」「login」を指定して、暗号化されたパスワード認証も扱うなら「cram-md5」も追加します

[root@c ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: cram-md5 plain login
[root@c ~]#

次に、pam経由で認証を行うように/etc/sysconfig/saslauthdを確認します。

[root@c ~]# vi /etc/sysconfig/saslauthd
SOCKETDIR=/run/saslauthd
MECH=pam
FLAGS=
[root@c ~]#

認証デーモンsaslauthdを稼動させ、Linuxアカウントでsmtp認証が可能かを確認する

[root@c ~]# systemctl start saslauthd
[root@c ~]# /usr/sbin/testsaslauthd -u illya -p xxxxxxxxxxxxxxxxxx
0: OK "Success."
[root@c ~]#



2.別途独自のパスワードファイルでsmtp認証のパスワードを管理するには/etc/sasl2/smtpd.conf
「saslauthd」を「auxprop」に変更します。

[root@c ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: auxprop
mech_list: plain login
[root@c ~]#

そして、メールアカウントごとのsmtp認証用パスワードを設置します。下記はsupport<_at_>sysosa.jpのパスワードを定義してます。
これによってsmtp認証用パスワードファイル「/etc/sasldb2」が作成される。

[root@c ~]# saslpasswd2 -u sysosa.jp support
Password:
Again (for verification):
[root@c ~]#

そのまま作成すると

[root@c ~]# ls -l /etc/sasldb2
-rw-r----- 1 root root 12288  3月 30 20:02 /etc/sasldb2
[root@c ~]#

と、smtp認証用パスワードファイルはrootユーザしか読めなくて、postfix稼動ユーザ「postfix」には読めない。なので

[root@c ~]# chgrp postfix /etc/sasldb2
[root@c ~]# ls -l /etc/sasldb2
-rw-r----- 1 root postfix 12288  3月 30 20:02 /etc/sasldb2
[root@c ~]#

とグループ所有者を変更する。

現在登録されているユーザの確認は下記のようにして行う(LANG環境変数によっては文字化けが発生)

[root@c ~]# LANG=C sasldblistusers2
support@sysosa.jp: userPassword
[root@c ~]#

留意
postfixの運用に依存するが、Linuxアカウントでメールを運用する場合、OSのpamからsmtp-auth、dovecot(imap/pop)認証が使える。
なので単一ドメインで運用するならLinuxパースワードがsmtp認証、メール取得パスワードにもなれる。パスワード一元化。
だが、VirtualMailbox構成をとるとsmtp認証向けのパスワード管理機構、dovecot(imap/pop)認証向けのパスワード管理と分散される。
これらを統合してみるmail/samba

postfixにsmtp-auth設定

smtp認証用のパスワードが準備できたので、これをpostfixに反映させる。
/etc/postfix/main.cfの最後当たりに下記を加え、postfixを再起動させる

[root@c ~]# vi /etc/postfix/main.cf
 :
smtpd_sasl_local_domain = $mydomain
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
 
[root@c ~]# systemctl restart postfix

VirtualMailbox構成の際には「smtpd_sasl_local_domain」は未定義でいいみたい

postfixのsmtp-auth認証時の接続の保護

認証中の通信を暗号化させるには/etc/postfix/main.cfの最後に下記を追記する。
暗号通信に使用される証明書はmail/dovecot#ye7dbf8aと同じで構わない。

[root@c ~]# vi /etc/postfix/main.cf
 :
smtpd_use_tls = yes
smtpd_tls_loglevel = 1
smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem
smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem
[root@c ~]#
[root@c ~]# diff -u /etc/postfix/master.cf.orig /etc/postfix/master.cf
--- /etc/postfix/master.cf.orig 2014-06-10 10:39:23.000000000 +0900
+++ /etc/postfix/master.cf      2017-03-30 02:05:34.548148530 +0900
@@ -23,10 +23,10 @@
 #  -o smtpd_sender_restrictions=$mua_sender_restrictions
 #  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
 #  -o milter_macro_daemon_name=ORIGINATING
-#smtps     inet  n       -       n       -       -       smtpd
+smtps     inet  n       -       n       -       -       smtpd
 #  -o syslog_name=postfix/smtps
-#  -o smtpd_tls_wrappermode=yes
-#  -o smtpd_sasl_auth_enable=yes
+  -o smtpd_tls_wrappermode=yes
+  -o smtpd_sasl_auth_enable=yes
 #  -o smtpd_reject_unlisted_recipient=no
 #  -o smtpd_client_restrictions=$mua_client_restrictions
 #  -o smtpd_helo_restrictions=$mua_helo_restrictions
[root@c ~]#
最新の60件
2026-05-22 2026-05-21 2026-05-20 2026-05-19 2026-05-18 2026-05-13 2026-05-12 2026-05-11 2026-05-08 2026-05-06 2026-05-05 2026-05-03 2026-04-30 2026-04-29 2026-04-28 2026-04-27 2026-04-25 2026-04-24 2026-04-22 2026-04-21 2026-04-12 2026-04-08 2026-04-06 2026-04-05 2026-04-02 2026-03-26 2026-03-23 2026-03-21 2026-03-19 2026-03-15 2026-03-14 2026-03-13 2026-03-07 2026-03-06 2026-03-04 2026-03-02 2026-02-26 2026-02-24

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2017-03-30 (木) 20:35:44