首页主机资讯centos邮件服务器设置技巧

centos邮件服务器设置技巧

时间2025-11-20 14:16:05发布访客分类主机资讯浏览833
导读:CentOS 邮件服务器设置技巧 一 架构与端口规划 组件选型:使用 Postfix 作为 MTA(负责发送/转发),Dovecot 作为 MDA/LDA(负责 IMAP/POP3 与本地投递),通过 SASL 完成发信认证,启用 TLS...

CentOS 邮件服务器设置技巧

一 架构与端口规划

  • 组件选型:使用 Postfix 作为 MTA(负责发送/转发),Dovecot 作为 MDA/LDA(负责 IMAP/POP3 与本地投递),通过 SASL 完成发信认证,启用 TLS 加密传输。
  • 端口用途与加密建议:
    • 25/TCP:SMTP(MTA 间通信/入站),建议仅用于服务器间通信,客户端发信优先用 587/Submission
    • 587/TCP Submission:客户端发信端口,强制 STARTTLS,配合 SASL 认证。
    • 465/TCP SMTPS:隐式 SSL 发信端口(可选,部分客户端仍使用)。
    • 110/TCP POP3:明文 POP3,建议仅在内网或配合 TLS。
    • 995/TCP POP3S:POP3 over SSL。
    • 143/TCP IMAP:明文 IMAP,建议启用 STARTTLS。
    • 993/TCP IMAPS:IMAP over SSL。
  • 基础 DNS 记录(示例域:example.com):
    • A:mail.example.com → 服务器公网 IP
    • MX:example.com → 10 mail.example.com
    • SPF:v=spf1 mx -all(按实际发送源增减机制)
    • DKIM:selector._domainkey.example.com TXT(由 DKIM 工具生成)
    • DMARC:_dmarc.example.com TXT “v=DMARC1; p=none; rua=mailto:dmarc@example.com”
  • 系统建议:优先使用 CentOS Stream 8/9RHEL 8/9 等受支持版本;如使用 CentOS 7,注意其已 EOL,需自行维护安全更新。

二 Postfix 关键配置

  • 核心参数(/etc/postfix/main.cf):
    • 基础标识
      • myhostname = mail.example.com
      • mydomain = example.com
      • myorigin = $mydomain
      • inet_interfaces = all
      • inet_protocols = ipv4(或 all)
      • mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
      • mynetworks = 127.0.0.0/8 [::1]/128(仅内网可信网段;云上请仅放内网段)
    • 邮箱存储与投递
      • home_mailbox = Maildir/(与 Dovecot 保持一致)
    • 安全与认证
      • smtpd_sasl_type = dovecot
      • smtpd_sasl_path = private/auth
      • smtpd_sasl_auth_enable = yes
      • smtpd_sasl_security_options = noanonymous
      • smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination
      • smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
    • TLS 加密
      • smtpd_use_tls = yes
      • smtpd_tls_security_level = may(Submission 建议 encrypt)
      • smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
      • smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
      • smtpd_tls_session_cache_database = btree:${ data_directory} /smtpd_scache
      • smtp_tls_session_cache_database = btree:${ data_directory} /smtp_scache
  • 主配完成后执行:systemctl restart postfix & & systemctl enable postfix。

三 Dovecot 关键配置

  • 协议与存储(/etc/dovecot/dovecot.conf 或 10-mail.conf):
    • protocols = imap pop3 lmtp
    • mail_location = maildir:~/Maildir
    • mail_privileged_group = mail
  • 认证与 SASL(/etc/dovecot/conf.d/10-auth.conf):
    • disable_plaintext_auth = no(若全链路启用 TLS,可设为 yes 强制加密)
    • auth_mechanisms = plain login
    • 使用 Dovecot SASL 供 Postfix:smtpd_sasl_type = dovecot;smtpd_sasl_path = private/auth
  • SSL/TLS(/etc/dovecot/conf.d/10-ssl.conf 或主配置):
    • ssl = yes
    • ssl_cert = /etc/letsencrypt/live/mail.example.com/fullchain.pem
    • ssl_key = /etc/letsencrypt/live/mail.example.com/privkey.pem
  • Master 服务与 Postfix 对接(/etc/dovecot/conf.d/10-master.conf):
    • service auth { unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } }
  • 启动:systemctl restart dovecot & & systemctl enable dovecot。

四 防火墙与端口开放

  • firewalld 放行常用端口(示例):
    • sudo firewall-cmd --permanent --add-port=25/tcp
    • sudo firewall-cmd --permanent --add-port=587/tcp
    • sudo firewall-cmd --permanent --add-port=465/tcp
    • sudo firewall-cmd --permanent --add-port=110/tcp
    • sudo firewall-cmd --permanent --add-port=995/tcp
    • sudo firewall-cmd --permanent --add-port=143/tcp
    • sudo firewall-cmd --permanent --add-port=993/tcp
    • sudo firewall-cmd --reload
  • 云厂商安全组同样需放行上述端口(尤其是 25/587/465/993/995)。

五 测试与加固清单

  • 连通性与协议测试
    • SMTP:telnet localhost 25;或 openssl s_client -connect mail.example.com:25 -starttls smtp
    • Submission:openssl s_client -connect mail.example.com:587 -starttls smtp
    • IMAP/POP3:openssl s_client -connect mail.example.com:993995
    • 日志排查:tail -f /var/log/maillog
  • 发信测试
    • echo “Test body” | mail -s “Test” user@example.org(检查收件箱与垃圾箱)
  • 安全与合规
    • 强制加密:Submission 使用 STARTTLS,禁用明文端口或限制来源;IMAP/POP3 优先 993/995
    • 身份认证:仅允许 SASL 发信(配合 mynetworks 最小化)。
    • 域名与信誉:正确配置 SPF、DKIM、DMARC;保持 PTR 记录与 HELO 主机名一致;避免开放转发与开放中继。
    • 反垃圾:部署 SpamAssassin/RspamdClamAV/Amavis,启用 Greylisting 与速率限制。
    • 备份与变更:定期备份 /etc/postfix /etc/dovecot 与用户邮箱;变更前先在测试环境验证。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: centos邮件服务器设置技巧
本文地址: https://pptw.com/jishu/752035.html
centos中phpstorm如何配置版本控制 怎样在centos上备份phpstorm项目

游客 回复需填写必要信息