Linux-admin-set-up-postfix-mta-and-imap-pop3

提供:Dev Guides
移動先:案内検索

Postfix MTAおよびIMAP/POP3をセットアップする

CentOS 7サーバーから電子メールを送信するには、最新のMail Transfer Agent(MTA)を構成するためのセットアップが必要です。 Mail Transfer Agentは、SMTPを介してシステムユーザーまたは企業のインターネットドメインに送信メールを送信するデーモンです。

このチュートリアルでは、デーモンをローカルで使用するための設定プロセスのみを説明しています。 業務用にMTAをセットアップするための高度な構成については詳しく説明しません。 これには、DNS、ブラックリストに登録されていない静的なルーティング可能なIPアドレスの取得、高度なセキュリティとサービス設定の構成などが含まれますが、これらに限定されません。 要するに、このチュートリアルは基本的な設定に慣れるためのものです。 インターネットに面したホストのMTA設定にはこのチュートリアルを使用しないでください。

セキュリティと管理の容易さの両方に焦点を合わせて、このチュートリアルのMTAとして Postfix を選択しました。 CentOSの古いバージョンにインストールされているデフォルトのMTAは、_Sendmail_です。 Sendmail はすばらしいMTAです。 ただし、著者の謙虚な意見では、PostfixはMTAに関する次の注意事項に対処するときに最適な場所を見つけます。 CentOSの最新バージョンでは、PostfixはデフォルトのMTAとしてSendmailに取って代わりました。

Postfixは、広く使用され、よく文書化されたMTAです。 積極的に維持および開発されています。 最小限の構成を念頭に置いて(これは単なるメールです)、システムリソースを使用して効率的です(これも単なるメールです)。

  • ステップ1 *-YUMパッケージマネージャーからPostfixをインストールします。
[root@centos]# yum -y install postfix
  • ステップ2 *-Postfix設定ファイルを設定します。

Postfix設定ファイルは_/etc/postfix/main.cf_にあります

単純なPostfix構成では、特定のホストに対して、ホスト名、ドメイン、発信元、inet_interfaces、および宛先を構成する必要があります。

ホスト名の設定-ホスト名は、Postfixホストの完全修飾ドメイン名です。 OpenLDAPの章では、CentOSボックスに「_vmnet.local_ドメイン上のcentos」という名前を付けました。 この章ではそれを守りましょう。

# 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 = centos.vmnet.local

ドメインの設定-上記のように、このチュートリアルで使用するドメインは_vmnet.local_です

# 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 = vmnet.local

オリジンの設定-単一のサーバーとドメインのセットアップでは、次のセクションのコメントを外してデフォルトのPostfix変数を残すだけです。

# 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

ネットワークインターフェースを設定します-単一のネットワークインターフェースと、そのインターフェースに関連付けられているすべてのプロトコルとIPアドレスでPostfixをリッスンしたままにします。 これは、Postfixのデフォルト設定を有効にしておくだけで実行できます。

# 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
# Enable IPv4, and IPv6 if supported
inet_protocols = all
  • ステップ3 *-PostfixのSASLサポートを設定します。

SASL認証のサポートがない場合、Postfixはローカルユーザーからのメールの送信のみを許可します。 または、ユーザーがローカルドメインから電子メールを送信すると、_relaying denied_エラーが発生します。

- SASL または Simple Application Security Layer Framework は、さまざまなアプリケーション層プロトコル間でさまざまな手法をサポートする認証用に設計されたフレームワークです。 認証メカニズムをアプリケーション層プロトコルに任せる代わりに、SASL開発者(および消費者)は、組み込みの利便性またはより安全な認証(安全なサービスへのアクセスと言えば)を持たない可能性のある高レベルのプロトコルに現在の認証プロトコルを活用します。

「cyrus-sasl *パッケージをインストールする

[root@centos]# yum -y install  cyrus-sasl
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 *base: repos.forethought.net
* extras: repos.dfw.quadranet.com
 * updates: mirrors.tummy.com
Package cyrus-sasl-2.1.26-20.el7_2.x86_64 already installed and latest version
Nothing to do

SASL認証用に_/etc/postfix/main.cf_を設定します

smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

_main.conf_のSASLオプション

##Configure SASL Options Entries:
smtpd_sasl_auth_enable = yes
smptd_recipient_restrictions =
permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtp_sasl_type = dovecot
smtp_sasl_path = private/auth/etc
  • ステップ4 *-着信SMTPサービスを許可するようにFirewallDを構成します。
[root@centos]# firewall-cmd --permanent --add-service=smtp
success

[root@centos]# firewall-cmd --reload
success

[root@centos]#

次に、CentOSホストがポート25(SMTP)で要求を許可して応答していることを確認します。

Nmap scan report for 172.16.223.132
Host is up (0.00035s latency).
Not shown: 993 filtered ports
PORT    STATE  SERVICE
   20/tcp  closed ftp-data
   21/tcp  open   ftp
   22/tcp  open   ssh
   25/tcp  open   smtp
   80/tcp  open   http
   389/tcp open   ldap
   443/tcp open   https
MAC Address: 00:0C:29:BE:DF:5F (VMware)

ご覧のとおり、SMTPはリッスンしており、デーモンは内部LANからの要求に応答しています。

Dovecot IMAPおよびPOP3サーバーをインストールする

Dovecotは、小規模から大規模の組織の着信メールのニーズを処理するよう設計された安全なIMAPおよびPOP3サーバーです。 CentOSで多用されているため、CentOSおよびMTA SASLプロバイダーの受信メールサーバーをインストールおよび構成する例としてDovecotを使用します。

前述したように、DNSのMXレコードを構成したり、サービスがドメインのメールを処理できるようにする安全なルールを作成したりすることはありません。 したがって、これらのサービスをインターネットに接続しているホスト上に設定するだけで、SPFレコードのないセキュリティホールを活用する余地を残すことができます。

  • ステップ1 *-Dovecotをインストールします。
[root@centos]# yum -y install dovecot
  • ステップ2 *-dovecotを設定します。

dovecotのメイン設定ファイルは_/etc/dovecot.conf_にあります。 最初にメインの構成ファイルをバックアップします。 編集を行う前に、常に構成ファイルをバックアップすることをお勧めします。 このようにして、id(たとえば)改行はテキストエディターによって破壊され、何年もの変更が失われます。 現在のバックアップを運用環境にコピーするので、元に戻すのは簡単です。

_dovecot_のプロトコルとデーモンサービスを有効にする

# Protocols we want to be serving.
protocols = imap imaps pop3 pop3s

ここで、dovecotデーモンを有効にして起動時にリッスンする必要があります-

[root@localhost]# systemctl start  dovecot
[root@localhost]# systemctl enable dovecot

Dovecotが指定されたポートでローカルにリッスンしていることを確認しましょう:imap、pop3、imapセキュア、およびpop3セキュア。

[root@localhost]# netstat -antup | grep dovecot
 tcp        0        0 0.0.0.0:110        0.0.0.0:*        LISTEN        4368/dovecot
 tcp        0        0 0.0.0.0:143        0.0.0.0:*        LISTEN        4368/dovecot
 tcp        0        0 0.0.0.0:993        0.0.0.0:*        LISTEN        4368/dovecot
 tcp        0        0 0.0.0.0:995        0.0.0.0:*        LISTEN        4368/dovecot
 tcp6       0        0 :::110                :::*          LISTEN        4368/dovecot
 tcp6       0        0 :::143                :::*          LISTEN        4368/dovecot
 tcp6       0        0 :::993                :::*          LISTEN        4368/dovecot
 tcp6       0        0 :::995                :::*          LISTEN        4368/dovecot

[root@localhost]#

ご覧のとおり、_dovecot_は、指定されたポートでIPv4およびIPv4をリッスンしています。

POP3 110
POP3s 995
IMAP 143
IMAPs 993

次に、ファイアウォールルールを作成する必要があります。

[root@localhost]# firewall-cmd --permanent --add-port=110/tcp
success

[root@localhost]# firewall-cmd --permanent --add-port=143/tcp
success

[root@localhost]# firewall-cmd --permanent --add-port=995/tcp
success

[root@localhost]# firewall-cmd --permanent --add-port=993/tcp
success

[root@localhost]# firewall-cmd --reload
success

[root@localhost]#

着信メールサーバーは、POP3 _、 POP3s IMAP_、および_IMAPs_の要求をLAN上のホストに受け入れています。

Port Scanning host: 192.168.1.143

   Open TCP Port:   21          ftp
   Open TCP Port:   22          ssh
   Open TCP Port:   25          smtp
   Open TCP Port:   80          http
   Open TCP Port:   110         pop3
   Open TCP Port:   143         imap
   Open TCP Port:   443         https
   Open TCP Port:   993         imaps
   Open TCP Port:   995         pop3s