联系我们

info@serverion.com

给我们打电话

+1 (302) 380 3902

如何设置安全的 Postfix 和 Dovecot 邮件服务器

如何设置安全的 Postfix 和 Dovecot 邮件服务器

电子邮件仍然是全球企业必不可少的沟通工具。对于需要安全、可靠且可扩展解决方案的技术专业人员、IT 团队和企业主来说,设置内部邮件服务器可能会带来翻天覆地的变化。在本指南中,我们将引导您了解如何使用 后缀 作为 SMTP 服务和 鸽舍 作为 IMAP/POP3 服务。此解决方案可确保高性能、TLS 加密和灵活性,满足您的电子邮件需求。

读完本指南,您将逐步了解如何构建适用于企业级或本地设置的安全邮件服务器。无论您是管理高流量应用程序的开发人员,还是希望控制电子邮件数据的小型企业主,本指南都能帮助您顺利实现目标。

什么是 Postfix 和 Dovecot?

后缀

在深入了解设置过程之前,让我们先分解一下这些组件的作用:

  • 后缀Postfix:一款开源邮件传输代理 (MTA),用于发送、接收和路由电子邮件。Postfix 以其安全性、模块化架构和易于配置而闻名,广泛应用于小型和大型环境。
  • 鸽舍:一款支持 IMAP 和 POP3 协议的高性能邮件投递代理 (MDA)。它专注于用户身份验证,并安全地将电子邮件存储在邮箱中。其内置的 TLS 加密功能可确保与电子邮件客户端(例如 Mozilla Thunderbird,保持安全。

为什么要使用 Postfix 和 Dovecot 作为邮件服务器?

对于许多 IT 专业人士来说,内部电子邮件服务器可以增强数据控制、提高安全性,并根据特定业务需求进行定制。以下是 Postfix 与 Dovecot 结合使用是绝佳选择的原因:

  • 数据安全:这两种工具都具有强大的加密功能,包括用于安全通信的 TLS 和 Diffie-Hellman 参数设置。
  • 灵活性:先进的邮箱格式、身份验证后端和模块化配置提供量身定制的解决方案。
  • 性能:Postfix 可处理高电子邮件吞吐量,而 Dovecot 的高速邮箱操作可确保为用户提供流畅的性能。
  • 兼容性:Dovecot 支持 Thunderbird 等标准电子邮件客户端,可与用户工作流程无缝集成。

分步指南:设置安全邮件服务器

本节概述了使用 Postfix 和 Dovecot 设置本地邮件服务器的九个主要步骤。本指南基于以下测试环境: Fedora 41 作为虚拟机。

1.安装并配置Dovecot

Dovecot 是邮件传递系统的骨干。请按照以下步骤安装和配置 Dovecot:

  • 安装 Dovecot:运行命令在您的服务器上安装 Dovecot。
    sudo yum安装dovecot 
  • 生成证书:使用类似 SSCG(简单签名证书生成器) 创建自签名 TLS 证书。这些证书对于加密电子邮件通信至关重要。
  • 启用 TLS 加密:更新 Dovecot 配置文件(/etc/dovecot/conf.d/10-ssl.conf)替换为您的私钥、公共证书和 CA 证书的路径。例如:
    ssl_cert = 
  • 设置邮箱位置:指定邮箱格式和存储位置。建议格式为 sdbox(单鸽舍箱),其中每封电子邮件都存储为单独的文件。更新 10-邮件.conf file:
    mail_location = sdbox:/var/mail/%n 

2. 设置身份验证

Dovecot 支持多种身份验证后端,包括本地文件、PAM、LDAP 或 SQL。为了简单起见,本示例使用 基于 PAM 的身份验证:

  • 编辑 /etc/dovecot/conf.d/auth-system.conf.ext 文件来通过 PAM 配置用户身份验证。
  • 确保在身份验证过程中剥离域名。修改 auth_用户名_格式 在 10-auth.conf:
    auth_username_format = %Ln 

3.配置LMTP协议

这 本地邮件传输协议 (LMTP) 确保 Postfix 和 Dovecot 之间的无缝通信以实现本地消息传递。

  • 确认 LMTP 侦听器已启用 /etc/dovecot/conf.d/10-master.conf. 更新 LMTP 套接字的权限以允许 Postfix 访问:
    unix_listener /var/run/dovecot/lmtp { 模式 = 0600 用户 = postfix } 

4.安装并配置Postfix

Postfix 是负责发送和路由电子邮件的 SMTP 服务。设置方法如下:

  • 安装 Postfix:
    sudo yum 安装 postfix 
  • 基本配置:更新主配置文件(/etc/postfix/main.cf) 具有以下核心参数:
    • inet_interfaces = 本地主机
    • mydestination = localhost.localdomain
    • 邮箱传输 = lmtp:unix:/var/run/dovecot/lmtp
  • TLS 支持:确保 Postfix 使用之前生成的相同 TLS 证书。在 主配置文件:
    smtpd_tls_cert_file=/etc/dovecot/ssl/cert.pem smtpd_tls_key_file=/etc/dovecot/ssl/key.pem 
  • 启动服务:启用并启动Postfix服务:
    sudo systemctl 启用 postfix sudo systemctl 启动 postfix 

5.验证服务间通信

  • 通过使用以下方式从服务器发送电子邮件来测试配置 邮件 公用事业:
    echo“测试电子邮件正文”| mail -s“测试主题”admin@yourdomain.com 
  • 监视日志文件(/var/log/邮件日志) 以确保 Postfix 通过 LMTP 套接字成功将消息传递给 Dovecot。

6. 将 Thunderbird 设置为电子邮件客户端

最后,配置 Mozilla Thunderbird 连接到您的邮件服务器:

  • 使用相应 Dovecot 用户的电子邮件地址和密码。
  • 将传入的 IMAP 服务器设置为您的邮件服务器的主机名。
  • 使用 启动TLS 用于加密和默认的 IMAP/SMTP 端口。

配置完成后,Thunderbird 应该能够使用新配置的服务器发送和接收电子邮件。

7. Protect Your Sending Domain with SPF, DKIM and DMARC

Securing an email server with TLS protects connections, but it does not establish whether a message is authorized to use the domain shown in its From address. Before sending production email, administrators should configure SPF to identify authorized sending systems, enable DKIM signing for outgoing messages and publish a DMARC policy that checks alignment with the visible sender domain.

The importance of these controls is also evident in DNS configuration data. In November 2026, Lithuanian cybersecurity project AGuard examined 64,910 .lt domains and found that 44,466 (68.5%) had no published DMARC record. A further 25.3% used a monitoring-only policy (p=none), while just 6.2% published a quarantine or reject policy. The email authentication study and dataset provides the detailed breakdown and methodology.

These findings do not establish that the domains were compromised, and the sample includes domains that may not send email at all. For organizations operating their own mail servers, the recommended approach is to identify every legitimate sending source, verify SPF and DKIM alignment, monitor DMARC reports and introduce enforcement gradually to avoid rejecting legitimate correspondence.

Production deployments also require appropriate public DNS records, including MX records for inbound mail and reverse DNS for sending IP addresses. The localhost-only Postfix configuration shown earlier in this guide is a starting point for local testing, not a complete publicly accessible mail server. External SMTP access, relay restrictions and certificate validation need to be configured and tested separately.

关键要点

  • Postfix 和 Dovecot 配对:Postfix 擅长处理电子邮件传输,而 Dovecot 提供安全传递和邮箱管理。
  • 启用 TLS:始终配置 TLS 加密以保护电子邮件通信的安全。
  • 身份验证很重要:适当的身份验证(如 PAM 或 LDAP)可确保只有授权用户才能访问服务器。
  • 防火墙规则:对于远程设置,请配置防火墙以允许 IMAP、POP3 和 SMTP 通信。
  • 彻底测试:通过发送测试电子邮件和检查日志文件来验证配置。
  • 灵活的邮箱格式:使用类似以下格式 sdbox 实现高性能和有组织的电子邮件存储。
  • 使用可靠的客户端:Mozilla Thunderbird 等电子邮件客户端与 IMAP 和 SMTP 协议无缝集成。

结论

使用 Postfix 和 Dovecot 设置安全的电子邮件服务器看似复杂,但在适当的指导下,它将成为一项易于管理的任务。此设置不仅可以保护您的电子邮件数据,还可以灵活地自定义服务器以满足特定的业务需求。无论您运行的是关键任务应用程序还是管理小型企业,完全掌控您的电子邮件基础设施都能让您获得强大的功能并节省成本。

通过遵循本分步指南,您已为可扩展、安全可靠的电子邮件通信系统奠定了基础。祝您主机愉快!

来源:“如何使用 postfix 和 dovecot 设置安全邮件服务器” – Middleware Technologies,YouTube,2025 年 9 月 4 日 – https://www.youtube.com/watch?v=sLPsXa_fIQM

用途:嵌入以供参考。简短的引述可用于评论/评论。

相关博客文章

zh_CN