ubuntu邮件服务器设置步骤
导读:Ubuntu 邮件服务器搭建与配置步骤 一 准备与基础配置 更新系统并安装基础组件:sudo apt update && sudo apt upgrade -y 设置主机名与 FQDN(以mail.example.com为...
Ubuntu 邮件服务器搭建与配置步骤
一 准备与基础配置
- 更新系统并安装基础组件:sudo apt update & & sudo apt upgrade -y
- 设置主机名与 FQDN(以mail.example.com为例):sudo hostnamectl set-hostname mail.example.com,并在 /etc/hosts 添加 127.0.1.1 mail.example.com
- 申请并准备 TLS 证书(推荐 Let’s Encrypt):sudo apt install certbot,sudo certbot certonly --standalone -d mail.example.com(证书路径通常为 /etc/letsencrypt/live/mail.example.com/fullchain.pem 与 privkey.pem)
- 开放防火墙常用端口(示例):sudo ufw allow 25/tcp, 143/tcp, 110/tcp, 993/tcp, 995/tcp;如使用云厂商安全组,同步放行上述端口
二 安装与配置 Postfix
- 安装 Postfix:sudo apt install postfix
- 基本 main.cf 关键项(/etc/postfix/main.cf):
- myhostname = mail.example.com
- mydomain = example.com
- myorigin = $mydomain
- inet_interfaces = all
- inet_protocols = ipv4
- mydestination = $myhostname, localhost.$mydomain, $mydomain
- mynetworks = 127.0.0.0/8 [::1]/128
- home_mailbox = Maildir/
- smtpd_sasl_auth_enable = yes
- smtpd_sasl_security_options = noanonymous
- smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
- 应用配置:sudo systemctl restart postfix & & sudo systemctl enable postfix
三 安装与配置 Dovecot
- 安装 Dovecot:sudo apt install dovecot-core dovecot-imapd dovecot-pop3d
- 邮件存储(/etc/dovecot/conf.d/10-mail.conf):mail_location = maildir:~/Maildir
- 认证(/etc/dovecot/conf.d/10-auth.conf):disable_plaintext_auth = no;auth_mechanisms = plain login
- SASL 与 Postfix 对接(/etc/dovecot/conf.d/10-master.conf,service auth 段):
- unix_listener /var/spool/postfix/private/auth { mode = 0666; user = postfix; group = postfix }
- LMTP 交付(/etc/dovecot/conf.d/10-master.conf,service lmtp 段):
- unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600; user = postfix; group = postfix }
- 应用配置:sudo systemctl restart dovecot & & sudo systemctl enable dovecot
四 配置 DNS 与端口连通
- 必要 DNS 记录示例:
- A 记录:mail.example.com → 服务器公网IP
- MX 记录:example.com → 10 mail.example.com
- PTR 记录(反向解析):服务器IP → mail.example.com(向云厂商申请或自助配置)
- 连通性测试:
- SMTP:telnet mail.example.com 25 或 openssl s_client -connect mail.example.com:25 -starttls smtp
- IMAP/POP3:telnet mail.example.com 143/110;IMAPS/POP3S:openssl s_client -connect mail.example.com:993/995
- 建议同时发布邮件认证记录以提升到达率:SPF、DKIM、DMARC(可使用 opendkim、opendmarc 等组件)
五 安全加固与优化
- 启用 TLS 加密(Postfix 与 Dovecot 均使用 Let’s Encrypt 证书):
- Postfix(/etc/postfix/main.cf):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_use_tls=yes
- Dovecot(/etc/dovecot/conf.d/10-ssl.conf):ssl_cert = < /etc/letsencrypt/live/mail.example.com/fullchain.pem> ;ssl_key = < /etc/letsencrypt/live/mail.example.com/privkey.pem> ;ssl = required
- 反垃圾与合规:部署 SpamAssassin、OpenDKIM、OpenDMARC,并正确发布 SPF、DKIM、DMARC 记录
- 性能与可用性:启用 Postfix 的 postscreen、合理配置 DNS 缓存与连接限制,持续监控资源与日志(如 fail2ban、logwatch)
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: ubuntu邮件服务器设置步骤
本文地址: https://pptw.com/jishu/750817.html
