软路由配置 mihomo tun 模式后,局域网主机如果也是用 mihomo 的情况下,无法访问网络

237 天前
 kolok

情况是这样的,最近入手了一个 4 口工控机,配置了 ubuntu 系统,使用 kea-dhcp 以及 iptables 进行 SNAT 转发来组成局域网. 然后软路由上安装了 mihomo 并配置了 tun 模式后进行爬墙,这样就家里就不用每台设备都进行配置单独的 mihomo 了.

固定的设备还行没多大问题,但是手里有一台 mba,偶尔要带出去,所以也需要配置上 mihomo,软路由和 mba 上的 mihomo 配置是一样的.

但是这样有一样的问题,如果 mba 启动了 mihomo 并且连上了软路由的网络,这样 mba 的网络就无法访问了,看了日志类似形成了回环的感觉,但是又没法确认. 如果 mba 没启动 mihomo,连软路由的网络,也是可以单独使用的. 也就是说两个只能启动一个. 有没大哥可以指导一下

mihomo 的 tun 配置大概是这样的.

sniffer:
  enable: true
  force-dns-mapping: true
  parse-pure-ip: true
  override-destination: false
  sniff:
    HTTP:
      ports: [80, 8080-8880]
      override-destination: true
    TLS:
      ports: [443, 8443]
    QUIC:
      ports: [443, 8443]
tun:
  enable: true
  stack: system # or gvisor
  dns-hijack:
    - any:53
  auto-redir: true # manage nftable REDIRECT
  auto-route: true # auto set global route
  auto-redirect: true
  strict-route: true
  auto-detect-interface: true # conflict with interface-name
2434 次点击
所在节点    宽带症候群
8 条回复
dbak
237 天前
你软路由 mihomo 开启了 tun ,auto-redir 、auto-route 、auto-redirect 都是 true ,就不用 iptables 做 nat 了吧。

官方文档:
auto-redirect
仅支持 Linux ,自动配置 iptables/nftables 以重定向 TCP 连接,需要 auto-route 已启用

在 Android 中:

仅转发本地 IPv4 连接。要通过热点或中继共享您的 VPN 连接,请使用 VPNHotspot 。

在 Linux 中:

带有 auto-route 的 auto-redirect 现在可以在路由器上按预期工作,无需干预。
kolok
236 天前
@dbak 原来这样,我在软路由上取消了 iptables 的 snat 配置,也是可以

但是目前还是会存在 软路由和 mba 上同时开 mihomo 的话,mba 上就无法正常访问网络了
dbak
236 天前
@kolok 我家里手机和电脑开启 mihomo 走我的 mihomo 软路由是没问题的 你可以看一下你 mba 的的 mihomo 日志 把 log-level: debug 看看有什么报错之类的
kolok
236 天前
@dbak
既然老哥可以,大大肯定了这个方案是没问题的,再我多次尝试下,
软路由配置
```
tun:
stack: system
```
mac 配置
```
tun:
stack: gvisor
```
这样就可以,但是什么原理不清楚
kolok
236 天前
如果软路由配置
tun:
stack: system

mac 也是配置
tun:
stack: system
就不行
dbak
236 天前
@kolok 问了下 deepseek∶

Linux:默认使用  system  堆栈(直接依赖内核原生网络能力)。

macOS:默认使用  gvisor  或  mixed  堆栈(因 macOS 原生网络栈限制,需通过用户态实现增强兼容性)。
SenLief
236 天前
system 兼容性一般,gvisor 兼容性好一些。
zhenjiachen
236 天前
刚好上周才搭建过网关,用的 mihomo ,如果你开了 tun 局域网不能访问可以是你网关的机器路由没配置好,然后要开启 auto-route 。但是我建议不要用软件自带的 tun ,用 nftables 来做透明网关,因为我还需要从外网访问内网,开启 tun 外网进不来,只能用 nftables 。我是参照这个人的写法来做的,你可以看看
https://www.arloor.com/posts/clash-tpproxy/

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1114153

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX