精读笔记(RHCA 英文教材)· RH358 Chapter 6 Configuring Email Transmission
精读笔记(RHCA 英文教材)· RH358 Chapter 6 Configuring Email Transmission
教材原文:RHCA 官方英文教材(教材第 13~14 页)(OCR 整书版已从本站移除,本页为章节精读) 说明:本教材到手版本为 Instructor Guide(讲师手册),第 6 章含 Schedule/Objectives/Key Takeaways,无 Instructor Tips;正文细节需配合学生手册与实验。本笔记按“讲义要点 + 必要补充”双语整理(Postfix 细节参考 RHEL8 官方文档)。 关联知识:
RHCE9精读笔记\精读-第16章-文件服务器(对照服务类配置思路)、02-08-Ansible自动化;前置:RH358 Chapter 1 systemd 服务管理
Chapter 6 | Configuring Email Transmission(配置邮件发送)
- 一句话目标:Discuss how mail servers operate, and configure a server to use system tools and Postfix to send email messages through an outbound mail relay.(讨论邮件服务器如何工作;配置服务器用系统工具与 Postfix 通过出站中继发送邮件)
Chapter Objectives(本章目标,双语)
By the end of this chapter, students should be able to:
- Configure a server to send all email through an outbound SMTP gateway.(配置服务器把所有邮件经由出站 SMTP 网关发送)
- Automate the configuration of Postfix to send all outbound email through an SMTP gateway.(用 Ansible 自动化 Postfix 的“全部出站邮件走 SMTP 网关”配置)
Chapter Schedule(课时表,共 95 分钟)
| Section | 主题 | 方法 |
|---|---|---|
| 1 | Configuring a Send-only Email Service | Lecture 25 分钟 + Guided Exercise 20 分钟 |
| 2 | Automating Postfix Configuration | Lecture 5 分钟 + Guided Exercise 20 分钟 |
| - | Lab(Performance Checklist) | 25 分钟 |
Key Takeaways(本章要点 5 条)
Many system applications can send email by using the helper application /usr/sbin/sendmail or by connecting to a local mail server on localhost port 25/TCP.(很多系统应用通过 /usr/sbin/sendmail 助手或连本机 25/TCP 来发邮件) Postfix provides /usr/sbin/sendmail and the local mail server by default on Red Hat Enterprise Linux 8.(RHEL8 上 Postfix 默认同时提供 /usr/sbin/sendmail 与本地邮件服务器) A null client is a local mail server that does not accept email for local delivery and submits all outbound email to a mail relay for delivery to other servers.(null client 是“不收本地投递、把所有出站邮件交给中继”的本地邮件服务器) The main Postfix configuration file, /etc/postfix/main.cf, can be edited by hand or by using the postconf command.(主配置 /etc/postfix/main.cf 可手改或用 postconf 命令改) The Ansible Role rhel-system-roles.postfix, also called linux-system-roles.postfix, provides an easy way to automate Postfix configuration.(rhel-system-roles.postfix(又名 linux-system-roles.postfix)角色可轻松自动化 Postfix 配置) 中文归纳考点:① sendmail 助手与 localhost:25;② Postfix = sendmail + 本地 MTA;③ null client 概念;④ main.cf 手改或 postconf;⑤ 系统角色自动化。
补充精讲 A:邮件系统基础(Section 1 概念铺垫)
- 角色分工速记:MUA(用户代理:mail/mutt/图形客户端)→ MTA(传输代理:Postfix,收/发/中转)→ MDA(投递代理:送进用户邮箱);SMTP 是 MTA 之间及 MUA 提交时用的协议。
- 端口:SMTP 25/tcp(MTA 间与本地提交)、submission 587/tcp(客户端认证提交,带 STARTTLS)、SMTPS 465/tcp(隐式 TLS,客户端提交用);RHEL8 默认只在本机监听 25。
- 应用如何发信(Key Takeaway 1):① 调用
/usr/sbin/sendmail兼容助手(Postfix 提供,其它程序通过它发);② 直接连接localhost:25的本地 MTA。系统里mail(mailx 包)等工具都用这条链。 - 发信流程(出站):应用 → 本地 Postfix → 查 MX/按 relayhost → 交给目标服务器或中继网关。
- 检查当前 MTA:
alternatives --display mta/alternatives --config mta(RHEL8 默认 sendmail→postfix 的兼容实现)。
补充精讲 B:配置 send-only / null client(Section 1 核心)
- null client 定义(Key Takeaway 3,考点):一台“只发不收”的邮件服务器——不接受本地投递、不接收外来邮件,把所有出站邮件交给一个指定的 relay(中继)转发。
- 典型场景:监控/备份/脚本服务器要发告警邮件,但不愿(也不该)直接对公网做 MX;把邮件统一丢给公司 SMTP 网关。
- 需要理解的 main.cf 参数: | 参数 | null client 取值 | 说明 | | --- | --- | --- | |
myhostname| 本机 FQDN | 邮件头/HELO 用身份 | |myorigin|$myhostname(或域名) | 出站邮件“发件域”后缀 | |inet_interfaces|loopback-only| 只监听本机,不对外收信 | |mydestination| (空,不写本地域) | 不接受本地域投递 → 实现“不收” | |relayhost|[smtp.gateway.example.com]| 所有出站邮件交给该网关(方括号=跳过 MX 直连) | |mynetworks| 默认信任回环即可 | 控制谁能用本机转发 | - 实操修改(Key Takeaway 4):
postconf -e 'relayhost = [smtp.example.com]'、postconf -e 'inet_interfaces = loopback-only'等(-e等价改 main.cf 并做兼容处理),或直接 vim 编辑/etc/postfix/main.cf;改完systemctl reload postfix(或 restart)。 - 查看配置:
postconf -n(只显示非默认项)、postconf -d(显示默认值)、postconf myorigin(查单项)。 - 服务启停:
systemctl enable --now postfix。 - 验证发送:
echo "body" | mail -s "subject" recipient@example.com(mail 来自 mailx);看日志tail -f /var/log/maillog(qmail/postfix 记录);mailq看队列有没有积压、postqueue -f立即冲刷。 - 防火墙:纯发送无需对外开 25;只有要收信/被中继的服务器才
firewall-cmd --add-service=smtp。
补充精讲 C:用 Ansible 自动化(Section 2 对应知识)
- 首选官方系统角色 rhel-system-roles.postfix(同 linux-system-roles.postfix):声明式设置 main.cf 参数,角色负责装包、生成配置、启动并开机自启。
- 核心变量(概念示例,具体字段以角色 README 为准):(
# vars postfix_conf: - name: relayhost value: "[smtp.gateway.example.com]" - name: myorigin value: "$myhostname" - name: inet_interfaces value: "loopback-only"postfix_conf是“参数名/值”列表;角色按列表渲染进 main.cf。) - 通用退路(无角色/想手控时):
dnf(装 postfix)→template/copy覆盖 main.cf 或command: postconf -e逐项设置 →service(enable+start)→ 改配置notifyhandlersystemctl reload postfix。 - 章节 Lab(推断口径):把一台服务器配成 null client(loopback-only + mydestination 空 + relayhost 指向网关),用 mail 发测试信并在 maillog/邮件网关侧确认收到;再写 playbook 复现同样配置。
核心词汇表
| 英文 | 中文速记 |
|---|---|
| MUA / MTA / MDA | 邮件用户代理 / 传输代理 / 投递代理 |
| SMTP | 简单邮件传输协议(25 提交/587 submission/465 SMTPS) |
| Postfix | RHEL8 默认 MTA(提供 sendmail 兼容) |
| /usr/sbin/sendmail | 发信兼容助手(应用统一入口) |
| mailx(mail 命令) | 命令行发信工具 |
| null client | 只发不收的本地邮件服务器(全交中继) |
| mail relay / relayhost | 出站中继网关([] 表示直连不查 MX) |
| myorigin / myhostname | 发件域 / 主机身份 |
| inet_interfaces | 监听接口(null client=loopback-only) |
| mydestination | 本地接收域列表(null client 置空) |
| postconf | main.cf 配置命令(-n/-d/-e/单项查) |
| /etc/postfix/main.cf | Postfix 主配置 |
| /var/log/maillog | 邮件日志 |
| mailq / postqueue -f | 队列查看 / 立即冲刷 |
| rhel-system-roles.postfix | Postfix 自动化系统角色(postfix_conf) |
本章自测
- 系统应用发邮件有哪两条路径?RHEL8 上 /usr/sbin/sendmail 是谁提供的?
- 什么是 null client?对照普通 MTA,它的三个关键 main.cf 参数取值?
- relayhost 写法里的方括号(如
[smtp.example.com])起什么作用? - postconf -n / -d / -e 各做什么?手改 main.cf 后怎么让配置生效?
- 如何验证一封测试信真的发出去了(命令 + 日志)?队列积压了怎么处理?
- 纯发送服务器要不要在防火墙放行 25?什么时候才需要?
- 自动化首选哪个角色?postfix_conf 变量表达什么?没有角色时的退路模块组合?
- Key Takeaways 五条与 Objectives 两条如何对应?
