Linux Admin教程

Linux Admin IMAP

为了从我们的 CentOS 7 服务器发送电子邮件,我们需要进行设置以配置现代邮件传输代理 (MTA)。邮件传输代理是负责发送出站邮件的守护进程系统用户或公司 Internet 域通过 SMTP。
值得注意的是,本教程只讲授了设置本地使用的守护进程的过程。我们不会详细介绍为业务运营设置 MTA 的高级配置。这是许多技能的组合,包括但不限于:DNS、获取未列入黑名单的静态可路由 IP 地址以及配置高级安全和服务设置。简而言之,本教程旨在让您熟悉基本配置。请勿将本教程用于面向 Internet 的主机的 MTA 配置。
结合对安全性和易于管理的关注,我们选择 Postfix 作为本教程的 MTA。在旧版 CentOS 中安装的默认 MTA 是 SendmailSendmail 是一个很棒的 MTA。然而,根据作者的拙见,Postfix 在处理 MTA 的以下注释时遇到了一个甜蜜点。在最新版本的 CentOS 中,Postfix 已取代 Sendmail 作为默认 MTA。
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
配置网络接口-我们将让 Postfix 监听我们的单个网络接口以及与该接口关联的所有协议和 IP 地址。只需为 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简单应用程序安全层框架 是一个框架,设计用于支持不同应用层协议之间的不同技术的身份验证。 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 Auth配置/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 步-配置 FirewallD 以允许传入的 SMTP 服务。
[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 的大量使用,我们将使用 Dovecot 作为为 CentOS 和 MTA SASL Provider 安装和配置传入邮件服务器的示例。
如前所述,我们不会为 DNS 配置 MX 记录或创建允许我们的服务处理域邮件的安全规则。因此,仅在面向 Internet 的主机上设置这些服务可能会为没有 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
POP3 995
IMAP 143
IMAP 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]#
我们的接收邮件服务器正在接受 POP3POP3sIMAPIMAP 对主机的请求局域网。
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 
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4