<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[RouterOS 7.22+ 容器 TUN 网关失效：sing-box 和 mihomo 无法使用，附修复方案]]></title><description><![CDATA[<blockquote>
<p dir="auto"><span class="w10-text-size" style="--w10-text-size:20px"><span class="w10-text-color" style="--w10-text-color:#c0392b">RouterOS 升级到 7.22 之后，容器里的 sing-box 和 mihomo 突然不能用了 —— 流量根本进不了容器。折腾了半天才发现，问题不在代理配置，在 RouterOS 自己身上。</span></span></p>
</blockquote>
<p dir="auto">这个坑我踩过，也把完整的定位过程和修复脚本整理出来了，写在这里给同样卡住的人省点时间。</p>
<p dir="auto"><img src="https://wlite.cn/assets/uploads/mt2-page1.png" alt="封面" class=" img-fluid img-markdown" /></p>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f"><img src="https://wlite.cn/assets/plugins/nodebb-plugin-emoji/emoji/android/1f4cc.png?v=2a372b6da06" class="not-responsive emoji emoji-android emoji--pushpin" style="height:23px;width:auto;vertical-align:middle" title="📌" alt="📌" /> 问题现象</span></h2>
<p dir="auto">升级到 RouterOS 7.22 之后出现这些症状：</p>
<ul>
<li>容器里的 TUN 网关停止工作</li>
<li>流量<strong>不会进入容器</strong></li>
<li>把容器设置为网关<strong>没有任何效果</strong></li>
</ul>
<p dir="auto">在 <strong>7.20.8 / 7.21</strong> 上一切正常，从 <strong>7.22</strong> 开始失效。</p>
<p dir="auto"><span class="w10-text-color" style="--w10-text-color:#c0392b"><strong>如果你的 TUN 网关在 7.22+ 上不工作，不要先去调代理配置 —— 先检查 <code>ip rule</code>。</strong></span></p>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f"><img src="https://wlite.cn/assets/plugins/nodebb-plugin-emoji/emoji/android/1f50d.png?v=2a372b6da06" class="not-responsive emoji emoji-android emoji--mag" style="height:23px;width:auto;vertical-align:middle" title="🔍" alt="🔍" /> 根因：容器内 ip rule 优先级被改了</span></h2>
<p dir="auto">RouterOS 7.22 修改了容器内默认的 <code>ip rule</code> 优先级，变成了这样：</p>
<pre><code>1:  from all lookup local
2:  from all lookup main
3:  from all lookup default
</code></pre>
<p dir="auto">这个改动会直接破坏：</p>
<ul>
<li>策略路由（policy routing）</li>
<li>fwmark 路由</li>
<li>基于 TUN 的代理核心</li>
</ul>
<p dir="auto"><strong>为什么 1/2/3 就会坏？</strong></p>
<p dir="auto">在 7.20.x 里，容器的默认规则是：</p>
<pre><code>200:        from all lookup local
2147483646: from all lookup main
2147483647: from all lookup default
</code></pre>
<p dir="auto">关键在 <code>200</code> 和 <code>2147483646</code> 之间<strong>留出了巨大的数字空间</strong>，sing-box、mihomo 这类代理核心会把自己的路由规则插到这两条之间，策略路由才能正常工作。</p>
<p dir="auto">而 7.22+ 改成 <code>1</code> / <code>2</code> / <code>3</code> 之后，留给第三方插入的空间几乎没有了。代理核心添加的规则只能排到<strong>表的最底部</strong>，优先级低于默认规则，于是完全失效。</p>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f"><img src="https://wlite.cn/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=2a372b6da06" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:23px;width:auto;vertical-align:middle" title="✅" alt="✅" /> 修复方法</span></h2>
<p dir="auto">思路很简单：<strong>在启动代理核心之前，把 <code>ip rule</code> 的顺序规范化</strong>，恢复成 7.21 那种留有充足插入空间的布局。</p>
<p dir="auto"><strong>基础命令：</strong></p>
<pre><code>ip rule del pref 1
ip rule del pref 2
ip rule del pref 3

ip rule add pref 200        from all lookup local
ip rule add pref 2147483646 from all lookup main
ip rule add pref 2147483647 from all lookup default
</code></pre>
<p dir="auto"><strong>推荐用带健壮性检查的版本</strong> —— 直接删可能因为规则不存在而报错，下面这个可以安全地重复执行：</p>
<pre><code>ensure_ip_rule_priorities() {
    while ip rule show | grep -Eq '^1:\s+from all lookup local(\s|$)'; do
        ip rule del pref 1 &gt;/dev/null 2&gt;&amp;1 || break
    done
    while ip rule show | grep -Eq '^2:\s+from all lookup main(\s|$)'; do
        ip rule del pref 2 &gt;/dev/null 2&gt;&amp;1 || break
    done
    while ip rule show | grep -Eq '^3:\s+from all lookup default(\s|$)'; do
        ip rule del pref 3 &gt;/dev/null 2&gt;&amp;1 || break
    done

    if ! ip rule show | grep -Eq '^200:\s+from all lookup local(\s|$)'; then
        ip rule add pref 200 from all lookup local &gt;/dev/null 2&gt;&amp;1 || true
    fi
    if ! ip rule show | grep -Eq '^2147483646:\s+from all lookup main(\s|$)'; then
        ip rule add pref 2147483646 from all lookup main &gt;/dev/null 2&gt;&amp;1 || true
    fi
    if ! ip rule show | grep -Eq '^2147483647:\s+from all lookup default(\s|$)'; then
        ip rule add pref 2147483647 from all lookup default &gt;/dev/null 2&gt;&amp;1 || true
    fi
}

ensure_ip_rule_priorities
</code></pre>
<p dir="auto">实测<strong>在 7.22.1 上同样有效</strong>。</p>
<p dir="auto"><span class="w10-text-color" style="--w10-text-color:#7a7a7a"><strong>关于 fake-ip</strong></span>：如果启用了 fake-ip，还需要补一条路由 <code>ip route add 198.18.0.0/15 dev tun0</code>。也可以在容器启动命令里加一段延迟执行：</p>
<pre><code>-c "sleep 3 &amp;&amp; ip route add 198.18.0.0/15 dev tun0"
</code></pre>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f"><img src="https://wlite.cn/assets/plugins/nodebb-plugin-emoji/emoji/android/2699.png?v=2a372b6da06" class="not-responsive emoji emoji-android emoji--gear" style="height:23px;width:auto;vertical-align:middle" title="⚙" alt="⚙" />️ mihomo 的 TUN 配置</span></h2>
<p dir="auto">用 mihomo 的 TUN 模式时，需要额外加一段 <code>tun</code> 配置。把下面这段粘贴到配置文件的 <strong>DNS 段之后</strong>：</p>
<pre><code>tun:
  enable: true
  device: tun0
  stack: system
  auto-route: true
  auto-detect-interface: true
  strict-route: true
  dns-hijack:
    - any:53
</code></pre>
<p dir="auto">容器入口保持 <code>entrypoint=/entrypoint.sh</code>，不需要其他额外设置。</p>
<p dir="auto">节点配置可以用转换工具生成，比如 <span class="w10-text-color" style="--w10-text-color:#1f6fb2">sublink.works</span>。</p>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f">🧩 官方的修复</span></h2>
<p dir="auto"><strong>容器内的路由规则优先级已经在 7.23rc2 中由官方修正。</strong></p>
<p dir="auto">MikroTik 在 7.23rc2 的发布说明里写道：</p>
<pre><code>route - revert to old routing rule priorities for containers
        (introduced in v7.22);
</code></pre>
<p dir="auto">也就是说，官方<strong>回退了 7.22 引入的这次改动</strong>，恢复到旧行为。</p>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f"><img src="https://wlite.cn/assets/plugins/nodebb-plugin-emoji/emoji/android/1f4c4.png?v=2a372b6da06" class="not-responsive emoji emoji-android emoji--page_facing_up" style="height:23px;width:auto;vertical-align:middle" title="📄" alt="📄" /> 完整文档</span></h2>
<p dir="auto">上面只是要点。完整的分析过程、社区讨论记录（包括 MikroTik 官方是如何被说服去修的）、以及可以直接用的完整 <code>entrypoint.sh</code> 脚本，我整理成了一份 PDF：</p>
<blockquote>
<p dir="auto"><span class="w10-text-size" style="--w10-text-size:20px"><span class="w10-text-color" style="--w10-text-color:#c0392b">RouterOS 7.22+ 容器 TUN 网关失效 — 根因分析与修复</span></span></p>
</blockquote>
<p dir="auto">内容包括封面、目录、问题现象、根因定位、修复方案、mihomo 配置要点、社区讨论全文、官方修复跟进、附录脚本，共 12 页。</p>
<p dir="auto"><strong>下载地址（Google Drive）</strong></p>
<p dir="auto">预构建容器（sing-box / mihomo，已修复）—— 可直接导入使用。</p>
<p dir="auto"><span class="w10-text-color" style="--w10-text-color:#5b8d4a"><strong>网盘内附容器说明，这些容器在最新版本的 RouterOS 中同样可以正常使用。</strong></span></p>
<p dir="auto"><a href="https://drive.google.com/drive/folders/1YTVe9rqMn2YzbFZPkyYn6zjeUQKpf-uT" rel="nofollow ugc">https://drive.google.com/drive/folders/1YTVe9rqMn2YzbFZPkyYn6zjeUQKpf-uT</a></p>
<p dir="auto">详细流程文档（PDF）：</p>
<p dir="auto"><a href="https://drive.google.com/file/d/14fn8Llyzc28fwrHptqLZr7Nx9gYXbniq/view" rel="nofollow ugc">https://drive.google.com/file/d/14fn8Llyzc28fwrHptqLZr7Nx9gYXbniq/view</a></p>
<hr />
<h2><span class="w10-text-color" style="--w10-text-color:#b7791f"><img src="https://wlite.cn/assets/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=2a372b6da06" class="not-responsive emoji emoji-android emoji--warning" style="height:23px;width:auto;vertical-align:middle" title="⚠" alt="⚠" />️ 一句话总结</span></h2>
<p dir="auto">这不是 sing-box 的问题，不是 mihomo 的问题，也不是配置问题 ——</p>
<p dir="auto"><span class="w10-text-color" style="--w10-text-color:#c0392b"><strong>这是 RouterOS 容器路由的一次回归，只在 7.22 ~ 7.23rc1 之间出现，7.23rc2 已修复。</strong></span></p>
<p dir="auto">如果你的设备还在这个版本区间，要么用上面的脚本兜住，要么就停在能用的版本别升。</p>
]]></description><link>https://wlite.cn/topic/472/routeros-7.22-容器-tun-网关失效-sing-box-和-mihomo-无法使用-附修复方案</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 04:06:38 GMT</lastBuildDate><atom:link href="https://wlite.cn/topic/472.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Sep 2026 08:23:56 GMT</pubDate><ttl>60</ttl></channel></rss>