Problem
After upgrading to RouterOS 7.22:
-
TUN gateway inside container stops working
-
Traffic does NOT enter container
-
Setting container as gateway has no effect
Works fine on 7.20.8 / 7.21, broken on 7.22+
If your TUN gateway does not work on RouterOS 7.22+,
DO NOT debug proxy config first — check ip rule.
Root Cause
RouterOS 7.22 changed default ip rule priorities inside container:
1: from all lookup local
2: from all lookup main
3: from all lookup default
This breaks:
-
policy routing
-
fwmark routing
-
TUN-based proxy cores
Fix
Normalize ip rule order before launching proxy core:
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
Provided
-
Prebuilt sing-box container (fixed)
-
Prebuilt mihomo container (fixed)
-
Full deployment guide (RB5009 tested)
Tested
-
Device: RB5009
-
OS: RouterOS 7.22
-
Mode: Container + TUN Gateway
-
Result:
Fully working
Conclusion
This is NOT:
-
sing-box issue
-
mihomo issue
-
config issue
This is a RouterOS container routing regression
RB5009 / RouterOS 7.22+ Container TUN Fix**(sing-box / mihomo)**
Root cause: default ip rule priority regression in RouterOS container environment
Fix: normalize ip rule order before launching proxy core
Many thanks to CGGXANNX and Gundolf for their replies. The issue of container tun0 failing on version 7.22.1 has been completely fixed, and the latest versions of the singbox and mihomo images have been backed up. They can be imported directly and will work. The shared directory contains a detailed workflow document, RB5009-ROS722-TUN-Final Instructions.pdf, which you can check out if you're interested.
Additionally, I recommend using a node conversion tool to generate the configuration file:https://sublink.works
mihomo For tun mode, you need to add a tun configuration endpoint; simply paste it below the DNS section. The code is as follows:
entrypoint=/entrypoint.sh,No other settings required:
tun:
enable: true
device: tun0
stack: system
auto-route: true
auto-detect-interface: true
strict-route: true
dns-hijack:
- any:53
This is the complete IP rule startup command for entrypoint.sh. If you are creating your own image, you can refer to it directly:
#!/bin/sh
set -eu
LOG_FILE="/startup.log"
log() {
printf '%s\n' "$*" | tee -a "$LOG_FILE"
}
ensure_ip_rule_priorities() {
while ip rule show | grep -Eq '^1:\s+from all lookup local'; do
ip rule del pref 1 >/dev/null 2>&1 || break
done
while ip rule show | grep -Eq '^2:\s+from all lookup main'; do
ip rule del pref 2 >/dev/null 2>&1 || break
done
while ip rule show | grep -Eq '^3:\s+from all lookup default'; do
ip rule del pref 3 >/dev/null 2>&1 || break
done
ip rule add pref 200 from all lookup local >/dev/null 2>&1 || true
ip rule add pref 2147483646 from all lookup main >/dev/null 2>&1 || true
ip rule add pref 2147483647 from all lookup default >/dev/null 2>&1 || true
}
: > "$LOG_FILE"
log "[start]"
ensure_ip_rule_priorities
# fake-ip 开启才需要
ip route add 198.18.0.0/15 dev tun0 >/dev/null 2>&1 || true
log "[launch sing-box]"
exec /bin/sing-box run -c /config.json --disable-color
RB5009UG+S+ 7.22 singbox+mihomo Download :
https://drive.google.com/drive/folders/1YTVe9rqMn2YzbFZPkyYn6zjeUQKpf-uT?usp=sharing
Detailed workflow:
https://drive.google.com/file/d/14fn8Llyzc28fwrHptqLZr7Nx9gYXbniq/view?usp=sharing

