Skip to content
aBER

Environment and Installation

System Environment

Linux distribution: Ubuntu 24.04.4 LTS

Installing Mihomo

The official Mihomo project is:

MetaCubeX/mihomo

It’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.30

Download via GitHub CLI:

Terminal window
cd /tmp
gh release download v1.19.30 -R MetaCubeX/mihomo -p 'mihomo-linux-amd64-v1-v1.19.30.gz'

Once the download completes:

Terminal window
gunzip mihomo-linux-amd64-v1-v1.19.30.gz

Installation:

Terminal window
install -m 755 mihomo-linux-amd64-v1-v1.19.30 /usr/local/bin/mihomo

Check:

Terminal window
mihomo -v

The 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 2026
Use tags: with_gvisor

Configuration directory

Move all Mihomo data to:

/etc/mihomo

Create:

Terminal window
mkdir -p /etc/mihomo

Main config:

/etc/mihomo/config.yaml

When Mihomo starts:

Terminal window
mihomo -d /etc/mihomo

Mihomo 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: 300

This 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: 50

Manually select a region for overseas traffic:

- name: overseas sites
type: select
proxies:
- Auto-select
- Japan
- Hong Kong
- Singapore
- United States
- All nodes
- DIRECT

Automatically 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: 20

The same logic applies to other regions:

Hong Kong
Japan
Singapore
United 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.*.com

Domestic DNS:

nameserver:
- https://120.53.53.53/dns-query
- https://223.5.5.5/dns-query

And 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.114

On the server, restrict DNS listening to:

listen: 127.0.0.1:7874

Instead of:

listen: :7874

This 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
- DIRECT

Google:

- name: Google
type: select
proxies:
- Sites blocked by the GFW
- DIRECT

OpenAI:

- name: openAi
type: select
proxies:
- All nodes
- Sites blocked by the GFW
- DIRECT

You can also set up separate routing for these services:

YouTube
Netflix
Twitter
TikTok
Facebook
Discord
OneDrive
Microsoft
Steam
Cloudflare
...

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.yaml

Then:

rules:
- RULE-SET,GitHub-rule,GitHub

Ad:

- RULE-SET,Ad Blocking-rule,Ad Blocking

The 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 sites

The overall logic is roughly:

Advertisement
↓
REJECT
Domestic Websites / CN IP
↓
DIRECT
Foreign Services
↓
Proxy
Unrecognized Traffic
↓
Proxy

Finally, use:

MATCH,blocked by the GFW

There’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: false

Among them:

stack: mixed

It 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/16

Among them:

10.0.0.0/8
172.16.0.0/12
192.168.0.0/16

It’s a common private network.

Docker is usually in the same boat:

172.16.0.0/12

Within scope.

Tailscale, on the other hand, uses:

100.64.0.0/10

So after excluding these addresses:

SSH
Docker
Local Area Network
Tailscale

It 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: 9870

Because even if you already have TUN, having an explicit proxy port is still handy for testing, Docker, or certain programs.

For example:

Terminal window
curl -x http://127.0.0.1:9870 https://github.com

If you need to allow access from Docker or the local network, then:

allow-lan: true
bind-address: "*"

But don’t just:

lan-allowed-ips:
- 0.0.0.0/0

Otherwise, 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/16

If it’s just for local use, it’s even simpler:

allow-lan: false
bind-address: 127.0.0.1

Service Management

systemd Background Service

Create:

/etc/systemd/system/mihomo.service

The 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 Service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/mihomo -d /etc/mihomo
Restart=on-failure
RestartSec=3
LimitNOFILE=1048576
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target

Loading:

Terminal window
systemctl daemon-reload

Start:

Terminal window
systemctl enable --now mihomo

Check status:

Terminal window
systemctl status mihomo --no-pager

View real-time logs:

Terminal window
journalctl -u mihomo -f

Reboot:

Terminal window
systemctl restart mihomo

Configuration Check and Restart

Terminal window
mihomo -t -d /etc/mihomo

Later on:

Terminal window
systemctl restart mihomo

MetaCubeXD 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:

Terminal window
mihomo -t -d /etc/mihomo
systemctl restart mihomo

Test API:

Terminal window
curl http://127.0.0.1:9090/version

Normally, it will return something like:

{
"meta": true,
"version": "1.19.30"
}

Testing WebUI:

Terminal window
curl -I http://127.0.0.1:9090/ui/

I should return:

HTTP/1.1 200 OK

If you want to use it with Tailscale, you can:

external-controller: 0.0.0.0:9090

Final 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