最近给MacBook更换了机场和工具,体验更流畅,遂打算把Linux开发机(Rocky Linux)的v2ray翻墙工具也换了,所以有了下面的内容。

https://wiki.metacubex.one/startup/ 已经把主要内容讲清楚了,我只是记录一些注意事项。

检查本机上是否有DHCP服务

比如你在本机上启动了libvirtd服务,则会开启DHCP服务且占用53端口,跟mihomo TUN模式有冲突,所以建议关闭DHCP服务。

# 停止可能冲突的服务 (以 Ubuntu/CentOS 为例)
systemctl stop systemd-resolved  # 如果有的话
systemctl stop dnsmasq           # 关闭 dnsmasq,或是使用其他方式

编写配置文件

在下载和安装rpm包并配置systemd配置文件后,需要写配置文件,重新写一个不划算,可以从自己的MacBook上的Clash Verge 仪表板->订阅->右键点击订阅文件->编辑文件->复制里面的所有内容。

把内容粘贴到 /etc/mihomo/config.yaml 里面。

支持TUN模式,修改Mihomo配置以接管DNS

需要修改配置文件,以便支持TUN模式,编辑config.yaml文件,然后注意修改在proxies之前的内容

mixed-port: 7890
allow-lan: true
bind-address: "*"
mode: rule
log-level: info
external-controller: "127.0.0.1:9090"
tun:
  enable: true
  stack: mixed            # 建议使用 mixed(混合栈),TCP 用系统栈,UDP 用 gvisor,性能与兼容性均衡
  auto-route: true        # 自动设置全局路由,无需手动操作 ip route
  auto-redirect: true     # Linux 特有:自动配置 iptables/nftables 重定向 TCP 连接
  auto-detect-interface: true # 自动检测出口网卡
  dns-hijack:
    - "any:53"            # 劫持所有 53 端口的 DNS 请求到 mihomo 内部 DNS
  strict-route: true      # 严格路由,防止流量泄露
  gso: true               # Linux 特有:启用通用分段卸载,提升性能
dns:
  enable: true
  ipv6: false
  listen: 0.0.0.0:53       #注意这里需要填写53端口
  default-nameserver: [223.5.5.5, 119.29.29.29]
  enhanced-mode: fake-ip
  fake-ip-range: 198.88.0.1/16     #注意这里需要填写你开发机所使用的IP段
  use-hosts: true
  nameserver: 
    [
      "https://doh.pub/dns-query",
      "https://dns.alidns.com/dns-query",
      "223.5.5.5",
      "119.29.29.29",
    ]
  fake-ip-filter: ["一堆内容,别复制这个"]
proxies:

重启 mihomo 服务。

强制本地系统向本机发送DNS请求

修改 /etc/resolv.conf 文件

nameserver 127.0.0.1

为了避免Linux重启后会重置这个文件,建议

systemctl stop systemd-resolved
systemctl disable systemd-resolved

验证是否成功

使用dig x.com命令验证测试,假如返回的IP是198.88.x.x形式的地址,说明TUN模式+Fake-IP DNS劫持配置成功。

curl https://x.com 命令测试能否成功访问花花世界。