y-matsui::weblog

電子楽器、音楽、コンピュータ、プログラミング、雑感。面倒くさいオヤジの独り言

sendmail on CentOS でOP25B(Outbound Port 25 Blocking)対策

エントリータイトルを”sendmail on CentOSOP25B(Outbound Port 25 Blocking)対策”
としたが、ちょっと正しくない。
プロバイダのアカウントを使って接続したユーザが、CentOSで構築した自メールサーバにアクセスできない問題を解決した・・という話。
内容としては、「sendmailを587ポートで待機させるんだけど、不正な転送の踏み台にならないように設定するよ」ってところ。
CentOSsendmailのデフォルトがセキュリティ固めになってきているので、色々とやることがある。

■手順

・(ネットワーク上の)ファイアウォールTCP:587を空ける

・(ネットワーク上の)ファイアウォールでサブミッションポートに対するルールを追加する


・/etc/hosts.allowでsendmailへの接続を許可する
# vi /etc/hosts.allow

#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
sendmail: ALL


・/etc/mail/local-host_namesで自ホストが受信するメールドメインを設定する
[root@host ~]# vi /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
host.domain.jp

※ここでdomain.jpに別のメールサーバがある場合は、domain.jpなどと入れては駄目!。
(すべて飲み込んだ挙句に「該当するユーザいねー、俺知らねー」とエラーを吐き出すことになる)


・/etc/mail/sendmail.mcの設定を変更する
define(`SMART_HOST', `smarthost.domain.jp')
define(`SMART_HOST', `[12.34.56.78]')
dnlDAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
DAEMON_OPTIONS(`Port=submission, Name=MSA')
LOCAL_DOMAIN(`host.domain.jp')dnl
Cwhost.domain.jp


sendmail.cfへ設定を反映する
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


・/etc/mail/accessの編集(転送を許可するドメイン、アドレス範囲の登録)

# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:host.domain.jp RELAY
Connect:domain.jp RELAY
Connect:12.34.56. RELAY


access.dbの更新
# makemap hash /etc/mail/access.db < /etc/mail/access


・/etc/sysconfig/iptableで587ポートを開ける

  • A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 587 -j ACCEPT


sendmail再起動
# /etc/rc.d/init.d/sendmail restart


netstatでサービス稼働を確認
# netstat -a


telnetでクライアントから動作を確認

>telnet host.domain.jp 587
220 host.domain.jp ESMTP Sendmail 8.13.8/8.13.8; Thu, 4 Mar 2010 19:50:51 +0900


■参考サイト
CentOS5で作るネットワークサーバ構築ガイド/秀和システム ←全面的にサンクス
※特にsendmail.mcのDAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')で、M=Eaの記述を除かないと、認証が必須になるあたりのことは、自力では絶対に気付かなかったと思う。

FC4/sendmail/MTA としての sendmail の設定(メールを送るために最低限度すべき事)