新規記事の投稿を行うことで、非表示にすることが可能です。
2016年04月10日
sendmailによるSPF認証対応受信メールサーバ@(環境構築)
前回記事でのでSPF認証対応受信メールサーバ構築のための環境整備に続き、実際に、sendmailによるSPF認証対応受信メールサーバを構築してみる。
なお、spf対応の実現方法は、「smf-spf 」を使用する。
検証環境の前提は、前回記事と同じ。
・受信メールサーバは、RedhatEnterpriseLinux6.4、sendmail-8.14.4-9を使用
・spfへの対応は、smf-spf を使用する。
・検証に使用するドメインは、「simalab.com」
・DNSサーバ上で、mxレコードを受信側IPアドレスに設定
・DNSサーバ上で、spfレコードを送信側IPアドレスに設定
・送信サーバ側でメールを送信した場合、送信者アドレスのドメイン部を「log.simalab.com」を「simalab.com」に書き換える。
http://server-setting.info/centos/sendmail-smf-spf-install.html
以下、構築手順の記載。
wgetがインストールされていない場合は、下記のとおりインストール
[root@mx-ns src]# yum install wget
参照URLのとおり、smf-spf の rpm は、通常のリポジトリにはない模様。
smf-spf の rpm は、http://www.city-fan.org/ で公開されているため、そちらのリポジトリを参照可能とするため、
city-fan.org で公開されているリポジトリをまずは、インストールする。
検証環境は、RHEL6.4のため、下記を使用する。
http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-13.rhel6.noarch.rpm
ここでは、/usr/local/srcにダウンロードした。
[root@mx-ns src]# wget http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-13.rhel6.noarch.rpm
CITY-FAN.ORGの公開鍵をインポートする。
[root@mx-ns src]# rpm --import http://www.city-fan.org/ftp/contrib/yum-repo/CITY-FAN.ORG-GPG-KEY
city-fan.org リポジトリをインストールする
[root@mx-ns src]# rpm -Uvh city-fan.org-release-1-13.rhel6.noarch.rpm
準備中... ########################################### [100%]
1:city-fan.org-release ########################################### [100%]
[root@mx-ns src]#
まさに、参照URL記載のとおり、city-fan.org リポジトリは、正式なところでもないので常に無効にしておく(下記赤字箇所)。使いたい時は、yum のパラメータに–enablerepo を指定して使うようにする。
[root@mx-ns src]# cat /etc/yum.repos.d/city-fan.org.repo
[city-fan.org]
name=city-fan.org repository for Red Hat Enterprise Linux (and clones) $releasever ($basearch)
#baseurl=http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch
mirrorlist=http://mirror.city-fan.org/ftp/contrib/yum-repo/mirrorlist-rhel$releasever
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org
[city-fan.org-debuginfo]
name=city-fan.org debuginfo repository for Red Hat Enterprise Linux (and clones) $releasever ($basearch)
#baseurl=http://www.city-fan.org/ftp/contrib-debug/rhel$releasever/$basearch
mirrorlist=http://www.city-fan.org/ftp/contrib-debug/mirrorlist-rhel$releasever
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org
[city-fan.org-source]
name=city-fan.org source repository for Red Hat Enterprise Linux (and clones) $releasever
#baseurl=http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/source
mirrorlist=http://mirror.city-fan.org/ftp/contrib/yum-repo/source-mirrorlist-rhel$releasever
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org
smf-spf を --enablerepo=city-fan.orgオプション付きでインストールする。
[root@mx-ns src]# yum --enablerepo=city-fan.org install smf-spf
〜中略〜
依存性関連をインストールしました:
libspf2.x86_64 0:1.2.10-8.el6 sendmail-milter.x86_64 0:8.15.2-6.0.cf.rhel6
完了しました!
[root@mx-ns src]#
参照URLのとおり、smf-spf を sendmailで利用するためには、メールフィルタリングを実施する「MILTER 」がインストールされていないとダメなようなので、確認する。通常、CentOS , Scientific Linux で提供されている Sendmailは、既に組み込まれているようだが、検証環境(RHEL)でも念のため、確認しておく。
[root@mx-ns src]# sendmail -d0.10
Version 8.14.4
Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF SOCKETMAP STARTTLS
TCPWRAPPERS USERDB USE_LDAP_INIT
以下をsendmail.mcに追加する。
[[root@mx-ns src]# vi /etc/mail/sendmail.mc
# 追加
define(`confMILTER_MACROS_HELO', confMILTER_MACROS_HELO`, {verify}')dnl
INPUT_MAIL_FILTER(`smf-spf', `S=unix:/var/run/smfs/smf-spf.sock, T=S:30s;R:1m')dnl
mcファイルをコンパイルする。
[root@mx-ns src]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
下記のコマンドでsmf-spf を起動する。
[[root@mx-ns src]# service smf-spf start
smf-spf を起動中: [ OK ]
[root@mx-ns src]#
起動したら、システム再起動後も自動で起動するように設定をしておく。
[root@mx-ns src]# chkconfig --list smf-spf
smf-spf 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@mx-ns src]#
[root@mx-ns src]# chkconfig smf-spf on
[root@mx-ns src]#
[root@mx-ns src]# chkconfig --list smf-spf
smf-spf 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@mx-ns src]#
最後にsendmailを再起動する。
[root@mx-ns src]# service sendmail restart
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
sendmail を起動中: [ OK ]
sm-client を起動中: [ OK ]
[root@mx-ns src]#
[root@mx-ns src]#
以上で、構築手順は終了し、次回以降、動作確認を実施する。
2016年04月03日
sendmailによる送信者アドレスのドメイン部書き換え
前回記事1や前回記事2で
メール送信者の認証を行うためのSPFレコードについて、検証・構築などを行った。
それらの環境を利用して、sendmailを使用した受信メールサーバを、DNSのSPFレコードをした認証に対応するように設定・検証したいところだが、
こちらで用意した検証環境には、以下の問題があるため、
・送信者アドレスのドメイン部が送信メールサーバ側「ホスト名」(ここでは、「log.simalab.com」)になっている。
環境を受信メールサーバのSPFレコード対応を検証可能となるように、以下のように変更する。
・検証に使用するドメインは、「simalab.com」
・DNSサーバ上で、mxレコードを受信側IPアドレスに設定
・DNSサーバ上で、spfレコードを送信側IPアドレスに設定
・送信サーバ側でメールを送信した場合、送信者アドレスのドメイン部を「log.simalab.com」を「simalab.com」に書き換える。
送信者アドレスのドメイン部書き換え前の受信メールサーバのログ。
送信者アドレスのドメイン部が「log.simalab.com」(送信サーバ側のホスト名)となっている。
Mar 28 21:22:55 mx-ns sendmail[9686]: u2SCMtZ2009686: from=ment@log.simalab.com, size=631, class=0, nrcpts=1, msgid=<201603281223.u2SCNF9S005120@log.simalab.com>, proto=ESMTP, daemon=MTA, relay=[192.168.3.6]
これを以降で、送信者アドレスのドメイン部を「@simalab.com」に変更する。
まずは、送信者アドレスのドメイン部について、「from:ヘッダ」を書き換えられるように設定する。
以下を送信サーバ側のsendmail.mcに設定追加する。
MASQUERADE_AS(`simalab.com')dnl
define(`confDOMAIN_NAME', `smtp.simalab.com')dnl
mcファイルをコンパイルし、
[root@log mail]# m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf
その後、sendmail再起動する。
[root@log mail]# service sendmail restart
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
sendmail を起動中: [ OK ]
sm-client を起動中: [ OK ]
[root@log mail]#
・以下のように、送信側(log.simalab.com)からメールを送信する。
[ment@log ~]$ mail testuser@simalab.com
Subject: from heder masqerade test
from heder masqerade test (message)
.
EOT
[ment@log ~]$
・以下のように、受信側(mx-ns.simalab.com)からメールが受信される。
赤字箇所のfromヘッダーが(@simalab.com)に書き換えられていることを確認
※ただし、青字箇所のエンベロープfromは書き換えられていないことを確認する。
From ment@log.simalab.com Mon Mar 28 23:23:25 2016
Return-Path:
From: ment@simalab.com
Date: Mon, 28 Mar 2016 23:23:43 +0900
To: testuser@simalab.com
Subject: from heder masqerade test
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
X-SPF-Scan-By: smf-spf v2.0.2 - http://smfs.sf.net/
Received-SPF: None (mx-ns.simalab.com: domain of ment@log.simalab.com
does not designate permitted sender hosts)
receiver=mx-ns.simalab.com; client-ip=192.168.3.6;
envelope-from=; helo=smtp.simalab.com;
Status: R
from heder masqerade test (message)
次に、送信者アドレスのドメイン部について、「エンベロープFrom」を書き換えられるように設定する。
以下を送信サーバ側のsendmail.mcに設定追加する。
FEATURE(masquerade_envelope)dnl
mcファイルをコンパイルし、
[root@log mail]# m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf
その後、sendmail再起動する。
[root@log mail]# service sendmail restart
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
sendmail を起動中: [ OK ]
sm-client を起動中: [ OK ]
[root@log mail]#
・以下のように、送信側(log.simalab.com)からメールを送信する。
[ment@log ~]$ mail testuser@simalab.com
Subject: from envelope from masqerade test
from envelope from masqerade test(message)
.
EOT
[ment@log ~]$
・以下のように、受信側(mx-ns.simalab.com)からメールが受信される。
※赤字箇所のエンベロープfromが「@simalab.com」に書き換えられていることを確認する。
From ment@simalab.com Mon Mar 28 23:39:16 2016
Return-Path:
From: ment@simalab.com
Date: Mon, 28 Mar 2016 23:39:36 +0900
To: testuser@simalab.com
Subject: from envelope from masqerade test
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
X-SPF-Scan-By: smf-spf v2.0.2 - http://smfs.sf.net/
Received-SPF: Pass (mx-ns.simalab.com: domain of ment@simalab.com
designates 192.168.3.6 as permitted sender)
receiver=mx-ns.simalab.com; client-ip=192.168.3.6;
envelope-from=; helo=smtp.simalab.com;
Status: RO
from envelope from masqerade test(message)
・以下の書籍では、「レシピ4.6 リレーホストでマスカレードを実施する。」「レシピ4.10 エンベロープアドレスにマスカレードを実施する。」で紹介されている。
中古価格 |
2016年04月02日
sendmailによる送信者アドレス(From:ヘッダー)のsyslogへの出力
前回記事の続き。
sendmailで、送信者アドレス(From:ヘッダー)のsyslogへの出力を検証してみる。
sendmail.mcに下記の通り、送信者アドレス(From:ヘッダー)によるログ出力用のローカルルールセットを追加する。
LOCAL_CONFIG
Ksyslog syslog
LOCAL_RULESETS
HFrom: $>+log_from
Slog_from
R$* $: $(syslog "From: " $1 $)
[root@mx-ns mail]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
[root@mx-ns mail]# service sendmail restart
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
sendmail を起動中: [ OK ]
sm-client を起動中: [ OK ]
[root@mx-ns mail]#
・メールサーバ側での単体テスト
[root@mx-ns ~]# sendmail -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter
> log_from from header test
log_from input: from header test
log_from returns:
>
syslog(検証環境の場合は/var/log/maillog)に下記のように、From:ヘッダーが出力されていることを確認する。
[root@mx-ns ~]# tail /var/log/maillog -n 1
Mar 28 23:57:42 mx-ns sendmail[9807]: u2SEvQTN009807: From: from.header.test
[root@mx-ns ~]#
前回記事の検証環境のとおり、送受信テストを実施する。
・送信(メールクライアント)側
[ment@log ~]$ mail testuser@simalab.com
Subject: this is from header test
this is from header test message
.
EOT
[ment@log ~]$
受信(メールサーバ)側のログ
メールサーバ側のログに送信者アドレス(From:ヘッダー)のsyslogへの出力が成功していることを確認
Mar 29 00:00:09 mx-ns sendmail[9810]: u2SF09xc009810: From: ment@simalab.com
Mar 28 13:06:51 mx-ns sendmail[8750]: u2S46pls008750: from=, size=680, class=0, nrcpts=1, msgid=<201603280407.u2S47Bed003873@log.simalab.com>, proto=ESMTP, daemon=MTA, relay=[192.168.3.6]
Mar 28 13:06:52 mx-ns sendmail[8751]: u2S46pls008750: to=, delay=00:00:01, xdelay=00:00:00, mailer=local, pri=30860, dsn=2.0.0, stat=Sent
・検証で利用した設定ファイル一式
https://github.com/shi4669/ServerConfig/tree/master/sendmail/etc/mail
sendmailによる件名(Subject:ヘッダー)のsyslogへの出力
前回記事の続き。
sendmailで、件名(Subject:ヘッダー)のsyslogへの出力を検証してみる。
sendmail.mcに下記の通り、件名(Subject:ヘッダー)によるログ出力用のローカルルールセットを追加する。
LOCAL_CONFIG
Ksyslog syslog
LOCAL_RULESETS
HSubject: $>+log_subject
Slog_subject
R$* $: $(syslog "Subject: " $1 $)
[root@mx-ns mail]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
[root@mx-ns mail]# service sendmail restart
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
sendmail を起動中: [ OK ]
sm-client を起動中: [ OK ]
[root@mx-ns mail]#
・メールサーバ側での単体テスト
[root@mx-ns mail]# sendmail -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter
> log_subject subject test
log_subject input: subject test
log_subject returns:
syslog(検証環境の場合は/var/log/maillog)に下記のように、件名が出力されていることを確認する。
[root@mx-ns mail]# tail /var/log/maillog -n 1
Mar 28 12:58:21 mx-ns sendmail[8735]: u2S3w3cF008735: Subject: subject.test
[root@mx-ns mail]#
前回記事の検証環境のとおり、送受信テストを実施する。
・送信(メールクライアント)側
[ment@log ~]$ mail testuser@simalab.com
Subject: this is subject test
this is test subect message
.
EOT
[ment@log ~]$
受信(メールサーバ)側のログ
メールサーバ側のログに件名(Subject:ヘッダー)のsyslogへの出力が成功していることを確認
Mar 28 13:06:51 mx-ns sendmail[8750]: u2S46pls008750: Subject: this.is.subject.test
Mar 28 13:06:51 mx-ns sendmail[8750]: u2S46pls008750: from=, size=680, class=0, nrcpts=1, msgid=<201603280407.u2S47Bed003873@log.simalab.com>, proto=ESMTP, daemon=MTA, relay=[192.168.3.6]
Mar 28 13:06:52 mx-ns sendmail[8751]: u2S46pls008750: to=, delay=00:00:01, xdelay=00:00:00, mailer=local, pri=30860, dsn=2.0.0, stat=Sent
件名に日本語(ダブルバイト文字)を挿入し、動作検証を行ったものの、意図した動作は得られなかった。
・検証で利用した設定ファイル一式
https://github.com/shi4669/ServerConfig/tree/master/sendmail/etc/mail