温馨提示×

怎样调试debian邮件服务

小樊
52
2026-09-08 14:51:31
栏目: 智能运维

调试 Debian 上的邮件服务(如 Postfix、Exim、Sendmail 或 Dovecot)通常需要从 服务状态、日志、配置、网络、DNS 等多个方面入手。下面以 Postfix(最常见) 为主,给你一套系统化的调试思路。


一、确认邮件服务类型

先确认你用的是哪种 MTA:

systemctl list-units --type=service | grep -E 'postfix|exim|sendmail|dovecot'

常见组合:

  • Postfix + Dovecot(最主流)
  • Exim(Debian 默认有时是 Exim)
  • Sendmail(较少)

下面以 Postfix 为例。


二、检查服务是否运行

systemctl status postfix
systemctl status dovecot

如果没启动:

systemctl start postfix
systemctl enable postfix

三、查看邮件日志(最重要)

Debian 默认日志位置:

journalctl -u postfix -f
# 或
tail -f /var/log/mail.log

常见关键词:

  • status=sent ✅ 发送成功
  • status=deferred ⏳ 临时失败
  • status=bounced ❌ 永久失败
  • connection timed out
  • relay access denied
  • Sender address rejected

四、测试本地邮件发送

echo "test" | mail -s "test mail" user@localhost

或:

sendmail user@localhost
Subject: test
test
.

然后查看:

tail -f /var/log/mail.log

五、检查 Postfix 配置

postconf -n

常见问题点:

myhostname =
mydomain =
myorigin =
inet_interfaces =
mydestination =
relayhost =

测试配置语法:

postfix check

重载配置:

systemctl reload postfix

六、检查端口与防火墙

邮件常用端口:

  • 25(SMTP)
  • 465(SMTPS)
  • 587(Submission)
  • 110 / 143(POP/IMAP)

查看监听:

ss -tulnp | grep -E '25|465|587|110|143'

防火墙(如启用):

ufw status

七、DNS 与反垃圾邮件检查

如果是公网邮件服务器,必须检查:

1. MX 记录

dig MX yourdomain.com

2. PTR 反向解析

dig -x 你的服务器IP

3. SPF / DKIM / DMARC

  • SPF:TXT 记录
  • DKIM:opendkim
  • DMARC:TXT 记录

八、使用 telnet 手动测试 SMTP

telnet localhost 25

示例:

HELO test
MAIL FROM: test@localhost
RCPT TO: user@localhost
DATA
Subject: test
hello
.
QUIT

九、常见问题速查表

问题 原因
邮件发不出去 relayhost 未配置
外部收不到 防火墙 / DNS / 被当成垃圾邮件
认证失败 SASL / Dovecot 配置错误
本地能发不能收 dovecot 未运行
队列堆积 postqueue -p

查看队列:

postqueue -p
postsuper -d ALL deferred

十、如果你愿意,我可以进一步帮你

你可以直接贴出:

  • postconf -n
  • /var/log/mail.log 报错片段
  • 是 本地邮件 / 内网 / 公网

我可以帮你精确定位问题。

0 踩