<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>IRedMail on HiDa</title><link>https://www.0niu.cn/tags/iredmail/</link><description>Recent content in IRedMail on HiDa</description><generator>Hugo -- gohugo.io</generator><language>zh</language><lastBuildDate>Wed, 25 May 2022 22:44:57 +0800</lastBuildDate><atom:link href="https://www.0niu.cn/tags/iredmail/index.xml" rel="self" type="application/rss+xml"/><item><title>iRedMail配置静态路由</title><link>https://www.0niu.cn/posts/iredmail%E9%85%8D%E7%BD%AE%E9%9D%99%E6%80%81%E8%B7%AF%E7%94%B1/</link><pubDate>Wed, 25 May 2022 22:44:57 +0800</pubDate><guid>https://www.0niu.cn/posts/iredmail%E9%85%8D%E7%BD%AE%E9%9D%99%E6%80%81%E8%B7%AF%E7%94%B1/</guid><description>背景 邮箱默认 MX 记录指向梭子鱼邮件网关，所有外部邮件先经过网关过滤再投递到邮箱服务器。同时在 O365 上配置了 Connector，允许直接投递到网关。</description><content>&lt;h2 id="背景">背景&lt;/h2>
&lt;p>邮箱默认 MX 记录指向梭子鱼邮件网关，所有外部邮件先经过网关过滤再投递到邮箱服务器。同时在 O365 上配置了 Connector，允许直接投递到网关。&lt;/p>
&lt;p>需要将特定域的邮件通过静态路由（transport map）转发到指定地址，绕过默认投递逻辑。&lt;/p>
&lt;h2 id="配置步骤">配置步骤&lt;/h2>
&lt;h3 id="1-新建路由表文件">1. 新建路由表文件&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo touch /etc/postfix/staticroute
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-编辑路由规则">2. 编辑路由规则&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo vi /etc/postfix/staticroute
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>格式为 &lt;code>目标域/收件人 转发目标&lt;/code>：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span># 整个域转发
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>example.com smtp:[mail-gateway.example.com]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span># 特定用户转发
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>user@example.com smtp:[internal-server.example.com]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>&lt;strong>注意&lt;/strong>：&lt;code>[]&lt;/code> 表示直接使用 IP/主机名解析，不查找 MX 记录。&lt;/p>
&lt;/blockquote>
&lt;h3 id="3-注册-transport_maps">3. 注册 transport_maps&lt;/h3>
&lt;p>编辑 &lt;code>/etc/postfix/main.cf&lt;/code>，找到 &lt;code>transport_maps&lt;/code> 行，在其下方添加：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>transport_maps = hash:/etc/postfix/transport
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> hash:/etc/postfix/staticroute
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>如果文件中已有 &lt;code>transport_maps&lt;/code>，在末尾追加即可（多个映射源用空格分隔）。&lt;/p>
&lt;h3 id="4-生成哈希文件并重载">4. 生成哈希文件并重载&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo postmap /etc/postfix/staticroute
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo systemctl reload postfix
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="5-验证">5. 验证&lt;/h3>
&lt;p>查看当前路由是否生效：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>postmap -q example.com /etc/postfix/staticroute
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>发送测试邮件，检查 maillog：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tail -f /var/log/mail.log | grep &lt;span style="color:#e6db74">&amp;#39;staticroute&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="排查">排查&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>修改路由后不生效&lt;/strong> → 确认执行了 &lt;code>postmap&lt;/code> 生成 &lt;code>.db&lt;/code> 文件&lt;/li>
&lt;li>&lt;strong>转发目标不可达&lt;/strong> → 检查目标服务器是否开放 25 端口，防火墙是否放行&lt;/li>
&lt;li>&lt;strong>格式错误&lt;/strong> → &lt;code>postfix check&lt;/code> 可检查配置语法&lt;/li>
&lt;/ul>
&lt;h3 id="参考文档">参考文档&lt;/h3>
&lt;p>&lt;a href="https://www.linuxbabe.com/mail-server/postfix-transport-map-relay-map-flexible-email-delivery">Postfix Transport Map - Flexible Email Delivery&lt;/a>&lt;/p></content></item></channel></rss>