花了一些时间,参考了 LINUX DO 社区的文章和不少个人博客,也请教了几位朋友的建议,最终整理出了这份配置。
参考了这位大佬的配置:Mihomo 之通用配置与规则集-SA的自留地
开头直接先把自用配置放出来吧:
mihomo配置(暂时还不包含分组选择和规则分流等部分)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
| allow-lan: false mode: rule log-level: warning external-controller: "127.0.0.1:9090" ipv6: false mixed-port: 7890 redir-port: 0 tproxy-port: 0 unified-delay: true tcp-concurrent: true find-process-mode: always tun: enable: true device: Mihomo stack: mixed auto-route: true auto-redirect: true auto-detect-interface: true strict-route: true dns-hijack: - any:53 - tcp://any:53 route-exclude-address: [] mtu: 1500 dns: enable: true ipv6: false listen: 0.0.0.0:1053 use-hosts: true use-system-hosts: true prefer-h3: false enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 fake-ip-filter-mode: blacklist fake-ip-filter: - 'geosite:connectivity-check' - 'geosite:private' - '*.*.xboxlive.com' - '+.126.net' - '+.3gppnetwork.org' - '+.battle.net' - '+.battlenet.com.cn' - '+.cdn.nintendo.net' - '+.cmbchina.com' - '+.cmbimg.com' - '+.direct' - '+.dynv6.net' - '+.example' - '+.ff14.sdo.com' - '+.ffxiv.com' - '+.finalfantasyxiv.com' - '+.gcloudcs.com' - '+.gcloudsdk.com' - '+.home.arpa' - '+.invalid' - '+.kk-rays.com' - '+.kuwo.cn' - '+.lan' - '+.linksys.com' - '+.linksyssmartwifi.com' - '+.local' - '+.localdomain' - '+.localhost' - '+.market.xiaomi.com' - '+.mcdn.bilivideo.cn' - '+.media.dssott.com' - '+.msftconnecttest.com' - '+.msftncsi.com' - '+.music.163.com' - '+.music.migu.cn' - '+.n0808.com' - '+.ntp.org.cn' - '+.oray.com' - '+.orayimg.com' - '+.pool.ntp.org' - '+.router.asus.com' - '+.sandai.net' - '+.square-enix.com' - '+.srv.nintendo.net' - '+.steamcontent.com' - '+.stun.*.*' - '+.stun.*.*.*' - '+.stun.*.*.*.*' - '+.stun.*.*.*.*.*' - '+.test' - '+.time.edu.cn' - '+.uu.163.com' - '+.wargaming.net' - '+.wggames.cn' - '+.wotgame.cn' - '+.wowsgame.cn' - '+.xiami.com' - '+.y.qq.com' - adguardteam.github.io - adrules.top - amobile.music.tc.qq.com - anti-ad.net - api-jooxtt.sanook.com - api.joox.com - aqqmusic.tc.qq.com - dl.stream.qqmusic.qq.com - ff.dorado.sdo.com - heartbeat.belkin.com - isure.stream.qqmusic.qq.com - joox.com - lens.l.google.com - local.adguard.org - 'localhost.*.weixin.qq.com' - localhost.ptlogin2.qq.com - localhost.sec.qq.com - mesu.apple.com - Mijia Cloud - mobileoc.music.tc.qq.com - music.taihe.com - musicapi.taihe.com - na.b.g-tun.com - 'ntp.*.com' - 'ntp1.*.com' - 'ntp2.*.com' - 'ntp3.*.com' - 'ntp4.*.com' - 'ntp5.*.com' - 'ntp6.*.com' - 'ntp7.*.com' - proxy.golang.org - ps.res.netease.com - shark007.net - songsearch.kugou.com - static.adtidy.org - streamoc.music.tc.qq.com - swcdn.apple.com - swdist.apple.com - swdownload.apple.com - swquery.apple.com - swscan.apple.com - time-ios.apple.com - 'time.*.apple.com' - 'time.*.com' - 'time.*.edu.cn' - 'time.*.gov' - 'time1.*.com' - time1.cloud.tencent.com - 'time2.*.com' - 'time3.*.com' - 'time4.*.com' - 'time5.*.com' - 'time6.*.com' - 'time7.*.com' - trackercdn.kugou.com - 'xbox.*.*.microsoft.com' - 'xbox.*.microsoft.com' - xnotify.xboxlive.com nameserver: - https://1.1.1.1/dns-query - https://8.8.8.8/dns-query proxy-server-nameserver: - https://223.5.5.5/dns-query - https://223.6.6.6/dns-query direct-nameserver: - https://223.5.5.5/dns-query - https://223.6.6.6/dns-query respect-rules: true sniffer: enable: true parse-pure-ip: true force-dns-mapping: true override-destination: true sniff: HTTP: ports: - 80 - 8080-8880 override-destination: true TLS: ports: - 443 - 5228 - 8443 QUIC: ports: - 443 - 8443 force-domain: - +.v2ex.com skip-domain: - Mijia Cloud - +.push.apple.com skip-src-address: - 192.168.5.1/24 skip-dst-address: - 91.105.192.0/23 - 91.108.4.0/22 - 91.108.8.0/21 - 91.108.16.0/21 - 91.108.56.0/22 - 95.161.64.0/20 - 149.154.160.0/20 - 185.76.151.0/24 - 2001:67c:4e8::/48 - 2001:b28:f23c::/47 - 2001:b28:f23f::/48 - 2a0a:f280:203::/48 profile: store-selected: true store-fake-ip: true geo-auto-update: false geo-update-interval: 24 geodata-mode: false geox-url: geoip: https://hk.gh-proxy.org/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat geosite: https://hk.gh-proxy.org/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat mmdb: https://hk.gh-proxy.org/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb asn: https://hk.gh-proxy.org/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb proxy-providers: p1: type: http url: "example.com" path: ./p1.yaml interval: 86400 proxy: DIRECT p2: type: http url: "example.com" path: ./p2.yaml interval: 86400 proxy: DIRECT
|
mihomo裸核启动关闭脚本
分成两个文件:
1.start.vbs
1 2
| set mihomo = CreateObject("WScript.Shell") mihomo.Run "mihomo.exe -d .", 0
|
2.Stop.bat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| @echo off :menu cls echo ================================= echo Mihomo 控制面板 (TUN) echo ================================= echo 1. 启动 Mihomo (后台运行) echo 2. 关闭 Mihomo (安全清理) echo 3. 退出 echo ================================= set /p opt="请选择操作 (1-3): "
if "%opt%"=="1" goto start_mihomo if "%opt%"=="2" goto stop_mihomo if "%opt%"=="3" goto end goto menu
:start_mihomo echo 正在调用 vbs 启动 Mihomo... :: 运行你现有的 vbs 文件 start wscript.exe "Aastart.vbs" echo 启动指令已发出。 timeout /t 2 >nul exit
:stop_mihomo echo 正在安全停止 Mihomo (TUN 模式)... :: 不带 /f 参数,发送关闭信号以清理路由表 taskkill /im mihomo.exe >nul 2>&1 if %errorlevel% neq 0 ( echo [错误] 未发现正在运行的 mihomo.exe ) else ( timeout /t 3 /nobreak >nul echo 网络已恢复,Mihomo 已关闭。 ) pause goto menu
:end exit
|
3.如果是linux的话更简单了,直接创建一个自启动的系统服务就行。
(windows也可以注册成服务,可以手搓也可以用WinSW)
1
| vim /etc/systemd/system/mihomo.service
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| [Unit] Description=mihomo Daemon, Another Clash Kernel. After=network.target NetworkManager.service systemd-networkd.service iwd.service
[Service] Type=simple LimitNPROC=500 LimitNOFILE=1000000 CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE Restart=always ExecStartPre=/usr/bin/sleep 1s ExecStart=/usr/local/bin/mihomo -d /etc/mihomo ExecReload=/bin/kill -HUP $MAINPID
[Install] WantedBy=multi-user.target
|
ExecStart字段的前半段和后半段分别是mihomo程序的位置和config配置的位置,自己看着来修改路径。
1 2 3
| systemctl daemon-reload systemctl enable mihomo systemctl start mihomo
|
Windows使用这套配置前,先要检查mihomo目录下的文件情况。
每个文件右键属性,确保右下角没有解除锁定的按钮。如果有,则勾选并点击确定退出以解锁。
(文件是从网络上下载下来的很容易出现这种情况)
接着确保mihomo主程序右键属性,兼容性一栏勾选了以管理员权限身份运行。(TUN创建虚拟网卡需要管理员权限)
脚本里指定了程序和配置的名字,确定程序的名字是mihomo.exe,配置是config.yaml。
否则运行会报错,或者你修改脚本里对应的名字也可以。
**win11环境下:**打开bat文件启动mihomo时候,直接双击打开即可,不要右键以管理员模式打开,否则vbs路径会跳到system32提示找不到文件。关闭mihomo的时候,要右键以管理员模式打开,否则会提示权限不够关闭。
如果你像我一样使用web面板比如zashboard来操控,建议把配置文件(如zashboard-settings.json)保存下来,比如保留到mihomo目录下。不然浏览器缓存被清空后面板的设置都会被重置。
上面这些都是开箱即用的解释,想直接用的直接看上面就行了。
接下来开始解释这些配置。
Tailscale和mihomo共存
derp和mihomo共存