|
| 1 | ++++ |
| 2 | +date = '2026-01-06T10:05:49+08:00' |
| 3 | +draft = true |
| 4 | +title = 'mihomo裸核配置不完全指北' |
| 5 | ++++ |
| 6 | + |
| 7 | +之前配置了很多,形成了一套自洽的规则,但是回头看根本没看懂自己当时写的什么,所以还是记录一下。 |
| 8 | + |
| 9 | +## fake-ip or redir-host |
| 10 | + |
| 11 | +这两者究竟用什么,大家总是争论不休。 |
| 12 | + |
| 13 | +- fake-ip 会使得 DNS 缓存全部变成 fake-ip,意味着你每次重启 mihomo 的时候,如果缓存没有清除,那么就没法上网。在我早期使用时,甚至还经常出现睡眠唤醒后无法上网的问题,不知道现在解决了没有。 |
| 14 | +- fake-ip 使得 `dig/nslookup` 废了,而我使用这些工具频率还挺高。当然也可以打补丁,比如对国内站使用 `fake-ip-filter`,但是国外站还是不可能。 |
| 15 | + |
| 16 | +这么听上去,那么 redir-host 似乎不错?非也,这玩意比 fake-ip 历史还早,也曾经出过很多问题,但是现在通过一些手段续上命了。 |
| 17 | + |
| 18 | +- redir-host 要求得到域名的时候必须进行解析 DNS,如果你的 DNS 没有配好的话,很容易导致 DNS 泄露,相对而言,fake-ip 的 DNS 配置门槛就小得多,无脑加 `no-resolve` 基本都解决问题。 |
| 19 | +- redir-host 早期没法实现多个域名指向同一个 IP 的情况,尤其对于 UDP 包。现在 mihomo 强大的 sniffer 缓解了这个问题,但是只是补丁,可能在第一个包上面会剧烈抖动,对于更复杂的包可能也会出现嗅探失败的情况。 |
| 20 | + |
| 21 | +两种技术,没有绝对优势,任君选择。看你是要真实的国外 ip,还是更好的兼容性和性能。 |
| 22 | + |
| 23 | +## 全局 |
| 24 | + |
| 25 | +懒得介绍咯,看看就行: |
| 26 | + |
| 27 | +```yaml |
| 28 | +# 设备自定义配置 |
| 29 | +mode: rule |
| 30 | +mixed-port: 7890 |
| 31 | +allow-lan: false # 如果要开启,强烈建议使用防火墙! |
| 32 | +#bind-address: '*' |
| 33 | +log-level: warning |
| 34 | +ipv6: true |
| 35 | +unified-delay: true |
| 36 | + |
| 37 | +secret: '<your-secret>' |
| 38 | +external-controller: 127.0.0.1:9099 |
| 39 | +external-ui: "<your-borad-path>" |
| 40 | +external-controller-cors: |
| 41 | + allow-private-network: true |
| 42 | + allow-origins: |
| 43 | + - 'localhost:9099' |
| 44 | + |
| 45 | +experimental: |
| 46 | + dialer-ip4p-convert: true # 啊...ip4p没什么用,支持的太少了 |
| 47 | + |
| 48 | +profile: |
| 49 | + store-selected: true |
| 50 | + store-fake-ip: true # 存储 fake-ip 一定要开啊,你也不想重启mihomo断网吧? |
| 51 | + |
| 52 | +``` |
| 53 | + |
| 54 | +## tun |
| 55 | + |
| 56 | +对于追求体验的人来说,绝对逃不掉 tun 的,因为系统/socks代理毕竟不是所有东西都走。 |
| 57 | + |
| 58 | + |
| 59 | +```yaml |
| 60 | +tun: |
| 61 | + enable: true |
| 62 | + dns-hijack: |
| 63 | + - any:53 |
| 64 | + auto-detect-interface: true |
| 65 | + auto-route: true |
| 66 | + device: Mihomo |
| 67 | + mtu: 1500 |
| 68 | + stack: system # 出现问题就改 gvisor ,但是 system 的性能最高 |
| 69 | + strict-route: true # 开启多宿主的时候,就开这个 |
| 70 | + exclude-interface: |
| 71 | + - Tailscale |
| 72 | +``` |
| 73 | +
|
| 74 | +## DNS 和规则 |
| 75 | +
|
| 76 | +有一句老话: |
| 77 | +
|
| 78 | +> “不要玩弄 DNS,否则你就会被 DNS 玩弄。” |
| 79 | +
|
| 80 | +这是真的,我有时候睡不着就在想我的分流规则是怎么匹配的。 |
| 81 | +
|
| 82 | +### fake-ip |
| 83 | +
|
| 84 | +#### 复杂版本(支持小众国内网站) |
| 85 | +
|
| 86 | +为了获取小众域名的 ip 从而通过 ip 正确分流,用远程服务器解析得到 ip,那么 DNS 就只能复杂点了。 |
| 87 | +
|
| 88 | +- 我希望把所有不是国内的东西全部打到 `MATCH`,就必须让 geosite:!cn 的 DNS 解析用代理服务器打到谷歌,从而避免泄露。 |
| 89 | +- 由于使用的 `proxy-providers`,在获取订阅的时候会遇到解析走代理 DNS - 代理列表为空的死循环,所以手动加入国内的 DOH。 |
| 90 | +- 因为遵守规则就得配 `proxy-server-nameserver`,导致又多出了一长串。 |
| 91 | + |
| 92 | +```yaml |
| 93 | +dns: |
| 94 | + listen: :1053 |
| 95 | + enable: true |
| 96 | + ipv6: true |
| 97 | + enhanced-mode: fake-ip |
| 98 | + fake-ip-filter: |
| 99 | + - '+.lan' |
| 100 | + - '+.local' |
| 101 | + - 'geosite:cn' |
| 102 | + default-nameserver: |
| 103 | + - 119.29.29.29 |
| 104 | + - 223.5.5.5 |
| 105 | + respect-rules: true # 遵守规则,把googledns发给远端,远端用googledns来解析,然后返回ip |
| 106 | + nameserver: |
| 107 | + - https://dns.google/dns-query |
| 108 | + nameserver-policy: |
| 109 | + '<your-airport-sub-url>': # 防止死锁,让小众域名走国内dns获取ip(订阅不走proxy-server-nameserver),以便开始。 |
| 110 | + - https://doh.pub/dns-quer |
| 111 | + geosite:cn,apple,private: |
| 112 | + - system # 如果不稳定,那么就注释掉,直接用doh吧 |
| 113 | + - https://dns.alidns.com/dns-query#ecs=<your-real-ip-range> |
| 114 | + - https://doh.pub/dns-query#ecs=<your-real-ip-range> # 用于cdn优 |
| 115 | + proxy-server-nameserver: # 不配不能远程解析dns |
| 116 | + - https://doh.pub/dns-query |
| 117 | + - https://dns.alidns.com/dns-query |
| 118 | + |
| 119 | +
|
| 120 | +rules: |
| 121 | + - GEOSITE,CN,DIRECT |
| 122 | + - GEOIP,LAN,DIRECT,no-resolve |
| 123 | + - GEOIP,CN,DIRECT # 这一个是为小众网站准备的 |
| 124 | + - MATCH,select |
| 125 | +``` |
| 126 | + |
| 127 | +#### 简单版本 |
| 128 | + |
| 129 | +这个版本不支持国内小众网站,好处就是配置清晰明了。 |
| 130 | + |
| 131 | +~~不好意思,ns多就可以为所欲为~~ |
| 132 | + |
| 133 | +```yaml |
| 134 | +dns: |
| 135 | + listen: :1053 |
| 136 | + enable: true |
| 137 | + ipv6: true |
| 138 | + enhanced-mode: fake-ip |
| 139 | + default-nameserver: |
| 140 | + - 119.29.29.29 |
| 141 | + - 223.5.5.5 |
| 142 | + nameserver: |
| 143 | + - tls://8.8.8.8:853 |
| 144 | + - tls://8.8.4.4:853 |
| 145 | + - tls://dns.alidns.com |
| 146 | + - tls://223.5.5.5 |
| 147 | + - tls://223.6.6.6 |
| 148 | + - tls://dot.pub |
| 149 | + - tls://1.12.12.12 |
| 150 | + - tls://120.53.53.53 |
| 151 | + - https://cloudflare-dns.com/dns-query |
| 152 | + - https://dns.google/dns-query |
| 153 | + - https://8.8.8.8/dns-query |
| 154 | + - https://8.8.4.4/dns-query |
| 155 | + - https://dns.alidns.com/dns-query |
| 156 | + - https://223.5.5.5/dns-query |
| 157 | + - https://223.6.6.6/dns-query |
| 158 | + - https://doh.pub/dns-query |
| 159 | + - https://1.12.12.12/dns-query |
| 160 | + - https://120.53.53.53/dns-query |
| 161 | +
|
| 162 | +rules: |
| 163 | + - GEOSITE,CN,DIRECT |
| 164 | + - GEOIP,LAN,DIRECT,no-resolve |
| 165 | + - GEOIP,CN,DIRECT,no-resolve |
| 166 | + - MATCH,select |
| 167 | +``` |
| 168 | + |
| 169 | +### redir-host |
| 170 | + |
| 171 | +redir-host 的思路其实跟 fake-ip 类似,既然都折腾 redir-host,就用复杂那一套吧。 |
| 172 | + |
| 173 | +相比 fake-ip,少了 fake-ip-filter,多了 sniffer 。 |
| 174 | + |
| 175 | +```yaml |
| 176 | +dns: |
| 177 | + listen: :1053 |
| 178 | + enable: true |
| 179 | + ipv6: true |
| 180 | + use-system-hosts: true |
| 181 | + enhanced-mode: redir-host |
| 182 | + default-nameserver: |
| 183 | + - 119.29.29.29 |
| 184 | + - 223.5.5.5 |
| 185 | + respect-rules: true # 遵守规则,把googledns发给远端,远端用googledns来解析,然后返回域名 |
| 186 | + nameserver: |
| 187 | + - https://dns.google/dns-query |
| 188 | + nameserver-policy: |
| 189 | + '<your-airport-sub-url>': # 防止死锁,让小众域名走国内dns获取ip(订阅不走proxy-server-nameserver),以便开始。 |
| 190 | + - https://doh.pub/dns-query |
| 191 | + geosite:cn: |
| 192 | + - system # 如果不稳定,那么就注释掉,直接用doh吧 |
| 193 | + - https://dns.alidns.com/dns-query#ecs=<your-real-ip-range> |
| 194 | + - https://doh.pub/dns-query#ecs=<your-real-ip-range> # 用于cdn优化 |
| 195 | + proxy-server-nameserver: |
| 196 | + - https://doh.pub/dns-query |
| 197 | + - https://dns.alidns.com/dns-query |
| 198 | +
|
| 199 | +sniffer: |
| 200 | + enable: true |
| 201 | + sniff: |
| 202 | + HTTP: |
| 203 | + ports: [80, 8080-8880] |
| 204 | + override-destination: true |
| 205 | + TLS: |
| 206 | + ports: [443, 8443] |
| 207 | + QUIC: |
| 208 | + ports: [443, 8443] |
| 209 | + skip-domain: |
| 210 | + - "Mijia Cloud" |
| 211 | + - "+.push.apple.com" |
| 212 | +
|
| 213 | +rules: # 非常简单,有嗅探器的存在无需GEOSITE,CN |
| 214 | + - GEOIP,LAN,DIRECT |
| 215 | + - GEOIP,CN,DIRECT |
| 216 | + - MATCH,select |
| 217 | +``` |
| 218 | + |
| 219 | +### 服务器上使用 |
| 220 | + |
| 221 | +上面讲完的是你在本地的配置,这时候一般需要外部数据库的支持,如果你是通过包管理器安装的,可以直接引入不需要链接。 |
| 222 | + |
| 223 | +```yaml |
| 224 | +geodata-loader: standard |
| 225 | +geo-auto-update: true |
| 226 | +geox-url: |
| 227 | + geoip: "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat" |
| 228 | + geosite: "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat" |
| 229 | + mmdb: "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/country.mmdb" |
| 230 | + asn: "https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb" |
| 231 | +``` |
| 232 | + |
| 233 | +如果你是想丢两个文件到服务器上面,然后直接 `mihomo -f <file>` 启动的话,就不推荐这么用了,硬编码规则会爽很多。 |
| 234 | + |
| 235 | +我搓了一个模板,要用的时候替换 proxies 和 secret 就行。 |
| 236 | + |
| 237 | +[gist](https://gist.github.com/minortex/9b2fb8fe6b2a61477558844bcf65fd62) |
| 238 | + |
| 239 | +## 代理分组 |
| 240 | + |
| 241 | +按照机场和地区分组,地区自动选择,机场手动选择。 |
| 242 | + |
| 243 | +```yaml |
| 244 | +proxy-groups: |
| 245 | + - name: "select" |
| 246 | + type: "select" |
| 247 | + proxies: |
| 248 | + - "日本-自动选择" |
| 249 | + - "新加坡-自动选择" |
| 250 | + - "provider_A" |
| 251 | + - "provider_B" |
| 252 | +
|
| 253 | + - name: 日本-自动选择 |
| 254 | + type: url-test |
| 255 | + url: http://www.gstatic.com/generate_204 |
| 256 | + interval: 300 |
| 257 | + tolerance: 80 |
| 258 | + use: |
| 259 | + - "provider_A" |
| 260 | + filter: "(?i)日本|JP|Japan" # 自动正则筛选所有机场中的日本节点 |
| 261 | +
|
| 262 | + - name: 新加坡-自动选择 |
| 263 | + type: url-test |
| 264 | + url: http://www.gstatic.com/generate_204 |
| 265 | + interval: 300 |
| 266 | + tolerance: 80 |
| 267 | + use: |
| 268 | + - "provider_A" |
| 269 | + filter: "(?i)新加坡|SG|Singapore" |
| 270 | +
|
| 271 | +# 付费机场 |
| 272 | +
|
| 273 | + - name: "A" |
| 274 | + type: "select" |
| 275 | + use: |
| 276 | + - "provider_A" |
| 277 | +
|
| 278 | + - name: "B" |
| 279 | + type: "select" |
| 280 | + use: |
| 281 | + - "provider_B" |
| 282 | +
|
| 283 | +# 免费机场 |
| 284 | + - name: "free" |
| 285 | + type: "select" |
| 286 | + lazy: true |
| 287 | + use: |
| 288 | + - "provider_C" |
| 289 | + - "provider_D" |
| 290 | + - "provider_E" |
| 291 | +``` |
| 292 | + |
| 293 | +然后引入代理提供商: |
| 294 | + |
| 295 | +```yaml |
| 296 | +proxy-providers: |
| 297 | + "provider_A": |
| 298 | + type: http |
| 299 | + url: "<your_sub_url>" |
| 300 | + interval: 600 |
| 301 | + # proxy: select # 代理更新订阅 |
| 302 | + path: ./provide/provider_A.yml |
| 303 | + health-check: |
| 304 | + enable: true |
| 305 | + url: https://cp.cloudflare.com/generate_204 |
| 306 | + interval: 300 |
| 307 | + |
| 308 | + # ... |
| 309 | +``` |
| 310 | + |
| 311 | +注意,引入代理提供商的节点,测速是在提供商的 `health-check` 中配置的,`proxy-group` 只是引用了它的结果而已。 |
| 312 | + |
| 313 | +如果你是使用的 `proxies:`,那么测速就是在 `proxy-group` 里面配置的,不要搞混了。 |
0 commit comments