Environment and Installation
System Environment
Linux distribution: Ubuntu 24.04.4 LTS
Installing Mihomo
The official Mihomo project is:
MetaCubeX/mihomoIt’s a binary compiled in Go, so it doesn’t require Python or pip.
My server is linux amd64, and what I’ve installed is:
Mihomo Meta v1.19.30Download via GitHub CLI:
cd /tmp
gh release download v1.19.30 -R MetaCubeX/mihomo -p 'mihomo-linux-amd64-v1-v1.19.30.gz'Once the download completes:
gunzip mihomo-linux-amd64-v1-v1.19.30.gzInstallation:
install -m 755 mihomo-linux-amd64-v1-v1.19.30 /usr/local/bin/mihomoCheck:
mihomo -vThe Q20 I bought comes with a heavily customized Android system. I plan to flash a stock ROM to get rid of the bloatware.
Mihomo Meta v1.19.30 linux amd64 with go1.26.6 Sun Aug 16 10:02:19 UTC 2026Use tags: with_gvisorConfiguration directory
Move all Mihomo data to:
/etc/mihomoCreate:
mkdir -p /etc/mihomoMain config:
/etc/mihomo/config.yamlWhen Mihomo starts:
mihomo -d /etc/mihomoMihomo Configuration
Subscription Management
Nodes aren’t written directly into the main config; instead, they’re managed via proxy-providers:
proxy-providers: Proxy provider subscription: type: http url: "your subscription URL" path: ./sublinks/airport.yaml interval: 86400
health-check: enable: true url: https://www.gstatic.com/generate_204 interval: 300This way, the main config handles the rules, while the subscription handles the nodes. After updating the subscription, you don’t need to regenerate the entire config.
I use Sublink to aggregate subscriptions, so I’ve named this directory
sublinks/.
Automatic node selection
- name: Auto-select type: url-test use: - Proxy provider subscription
exclude-filter: "(?i)plan|expiration|remaining|traffic|reset|official site|documentation|download|notification"
url: https://www.gstatic.com/generate_204 interval: 300 tolerance: 50Manually select a region for overseas traffic:
- name: overseas sites type: select proxies: - Auto-select - Japan - Hong Kong - Singapore - United States - All nodes - DIRECTAutomatically filter nodes by region
Different countries and regions use url-test to select nodes.
For example, Japan:
- name: Japan type: url-test
use: - Proxy provider subscription
filter: "(?i)Japan|Tokyo|Osaka|Japan|\\bJP\\b|🇯🇵"
exclude-filter: "(?i)plan|expiration|remaining|traffic|reset|official site|documentation|download|Hong Kong|Singapore|Taiwan|United States"
url: https://www.gstatic.com/generate_204
interval: 300 tolerance: 20The same logic applies to other regions:
Hong KongJapanSingaporeUnited States...DNS and Fake-IP
DNS is managed by Mihomo itself:
dns: enable: true listen: 127.0.0.1:7874
ipv6: false prefer-h3: false
enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16
fake-ip-filter: - +.lan - +.local - time.*.com - ntp.*.comDomestic DNS:
nameserver: - https://120.53.53.53/dns-query - https://223.5.5.5/dns-queryAnd specify separately for domestic sites:
nameserver-policy: geosite:private: system
geosite:cn,steam@cn,category-games@cn,microsoft@cn,apple@cn: - 119.29.29.29 - 223.5.5.5 - 1.12.12.12 - 114.114.114.114On the server, restrict DNS listening to:
listen: 127.0.0.1:7874Instead of:
listen: :7874This way, you can avoid accidentally exposing the DNS service.
Service Routing
In addition to domestic and overseas traffic, you can also create separate policy groups for a few frequently used services.
For example, GitHub:
- name: GitHub type: select proxies: - overseas sites - DIRECTGoogle:
- name: Google type: select proxies: - Sites blocked by the GFW - DIRECTOpenAI:
- name: openAi type: select proxies: - All nodes - Sites blocked by the GFW - DIRECTYou can also set up separate routing for these services:
YouTubeNetflixTwitterTikTokFacebookDiscordOneDriveMicrosoftSteamCloudflare...Rule Provider
The rules themselves aren’t all written into config.yaml; instead, they’re managed via a remote Rule Provider.
For example:
GitHub-rule: type: http interval: 86400 behavior: classical format: yaml
url: https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/GitHub/GitHub.yaml
path: ./ruleset/blackmatrix7/GitHub.yamlThen:
rules: - RULE-SET,GitHub-rule,GitHubAd:
- RULE-SET,Ad Blocking-rule,Ad BlockingThe final fallback logic:
- RULE-SET,cncidr,DIRECT,no-resolve- RULE-SET,direct,DIRECT
- GEOSITE,gfw,blocked by the GFW sites- GEOIP,CN,domestic sites
- MATCH,blocked by the GFW sitesThe overall logic is roughly:
Advertisement ↓REJECT
Domestic Websites / CN IP ↓DIRECT
Foreign Services ↓Proxy
Unrecognized Traffic ↓ProxyFinally, use:
MATCH,blocked by the GFWThere’s a practical benefit: even if a particular overseas site isn’t on GFWList, it won’t accidentally fall back to a direct connection.
TUN Transparent Proxy
TUN Configuration
What truly makes Mihomo the core system proxy for Linux servers is TUN.
My configuration:
tun: enable: true
stack: mixed
auto-route: true auto-redirect: false auto-detect-interface: true
dns-hijack: - any:53 - tcp://any:53
mtu: 1500 device: mihomo
strict-route: falseAmong them:
stack: mixedIt works pretty well with the current Mihomo.
Once auto-route is enabled, system traffic will automatically go into Mihomo TUN.
Exclude Docker, Tailscale, and internal networks
route-exclude-address: - 10.0.0.0/8 - 100.64.0.0/10 - 169.254.0.0/16 - 172.16.0.0/12 - 192.168.0.0/16Among them:
10.0.0.0/8172.16.0.0/12192.168.0.0/16It’s a common private network.
Docker is usually in the same boat:
172.16.0.0/12Within scope.
Tailscale, on the other hand, uses:
100.64.0.0/10So after excluding these addresses:
SSHDockerLocal Area NetworkTailscaleIt won’t rewrite the routing for Mihomo TUN.
The overall structure becomes:
flowchart TD A[Linux Server] --> B[LAN / Docker / Tailscale] B --> C[DIRECT] A --> D[Internet] D --> E[Mihomo TUN] E --> F[Rule Matching] F --> G[DIRECT] F --> H[Proxy]
Proxy ports on the server
I’m keeping a Mixed Port:
mixed-port: 9870Because even if you already have TUN, having an explicit proxy port is still handy for testing, Docker, or certain programs.
For example:
curl -x http://127.0.0.1:9870 https://github.comIf you need to allow access from Docker or the local network, then:
allow-lan: truebind-address: "*"But don’t just:
lan-allowed-ips: - 0.0.0.0/0Otherwise, a public server can easily become an open proxy by accident.
You can restrict it like this:
lan-allowed-ips: - 127.0.0.0/8 - 10.0.0.0/8 - 172.16.0.0/12 - 192.168.0.0/16If it’s just for local use, it’s even simpler:
allow-lan: falsebind-address: 127.0.0.1Service Management
systemd Background Service
Create:
/etc/systemd/system/mihomo.serviceThe input has exactly 5 lines. Your output MUST also have exactly 5 lines — one output line per input line, never merge or split lines.
[Unit]Description=Mihomo Proxy ServiceAfter=network-online.targetWants=network-online.target
[Service]Type=simpleUser=root
ExecStart=/usr/local/bin/mihomo -d /etc/mihomo
Restart=on-failureRestartSec=3
LimitNOFILE=1048576
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICECapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE
NoNewPrivileges=true
[Install]WantedBy=multi-user.targetLoading:
systemctl daemon-reloadStart:
systemctl enable --now mihomoCheck status:
systemctl status mihomo --no-pagerView real-time logs:
journalctl -u mihomo -fReboot:
systemctl restart mihomoConfiguration Check and Restart
mihomo -t -d /etc/mihomoLater on:
systemctl restart mihomoMetaCubeXD WebUI
Mihomo itself provides a Controller API, but it doesn’t come with a management page in the traditional sense.
Here, I’m using MetaCubeXD.
Configuration:
external-controller: 0.0.0.0:9090
external-ui: /etc/mihomo/ui
secret: "Set your own password"You can also have Mihomo download it automatically:
external-ui: ui
external-ui-url: "https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip"Then:
mihomo -t -d /etc/mihomosystemctl restart mihomoTest API:
curl http://127.0.0.1:9090/versionNormally, it will return something like:
{ "meta": true, "version": "1.19.30"}Testing WebUI:
curl -I http://127.0.0.1:9090/ui/I should return:
HTTP/1.1 200 OKIf you want to use it with Tailscale, you can:
external-controller: 0.0.0.0:9090Final network structure
flowchart TD A[Ubuntu Server] A --> B[Private Network] B --> C[Docker / LAN] B --> D[Tailscale / SSH] C --> E[Does not enter TUN] D --> E A --> F[Internet] F --> G[Mihomo TUN] G --> H[Rule Engine] H --> I[DIRECT] H --> J[Proxy] J --> K[Auto-select node]
As for the management side:
flowchart TD A[Mac] -->|Tailscale| B[Ubuntu Server] B --> C[SSH] B --> D[9090/ui/] D --> E[MetaCubeXD]
References
- mihomo
- sublink pro
- Clash Verge’s extension script (The YAML config was converted using this script; I can’t quite find the original source for the secondary configuration anymore.)