Skip to content

Commit 30e6ca4

Browse files
committed
add tun mode
1 parent 400955b commit 30e6ca4

8 files changed

Lines changed: 110 additions & 70 deletions

File tree

config/hypr/hyprland.conf

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -290,25 +290,24 @@ submap=reset
290290
source = ~/.config/hypr/workspaces.conf
291291

292292
# See https://wiki.hypr.land/Configuring/Workspace-Rules/ for workspace rules
293-
windowrule = float, class:^(clash_win)$
294-
windowrule = float, class:^(ario)$
295-
windowrule = float, class:^(QQ)$
296-
windowrule = float, title:^(Picture in picture)$
297-
windowrule = float, title:^(Picture-in-Picture)$
298-
windowrule = float, class:(io.crow_translate.CrowTranslate)
299-
windowrule = float, class:(pot), title:(Translate|Translator|OCR|PopClip|Screenshot Translate) # Translation window floating
300-
windowrule = move cursor 0 0, class:(pot), title:(Translate|Translator|PopClip|Screenshot Translate) # Translation window follows the mouse position.
301-
windowrule = float, class:^(org.telegram.desktop)$,title:^(Media viewer)$
302-
windowrule = float, title:^Demo-
303-
windowrule = size 30% 50%, class:^(org.fcitx.fcitx5-config-qt)$,title:^(Classic User Interface — Fcitx Configuration)$
304-
windowrule = float, class:^(org.fcitx.fcitx5-config-qt)$,title:^(Fcitx Configuration)$
305-
windowrule = float, class:^(Zotero)$,title:^(Zotero Settings)$
306-
windowrule = float, class:^(xdg-desktop-portal-gtk)$
307-
windowrule = float, class:^(Meeting)$,title:^(Feishu Meetings)$
308-
windowrule = noblur, title:^(LarkSSPromptWindow)$
309-
windowrule = nofocus, title:^(LarkSSPromptWindow)$
310-
# windowrule = noblur, title:^(wemeetapp)$
311-
# windowrule = nofocus, title:^(wemeetapp)$
293+
windowrule = match:class ^(clash_win)$, float on
294+
windowrule = match:class ^(ario)$, float on
295+
windowrule = match:class ^(QQ)$, float on
296+
windowrule = match:title ^(Picture in picture)$, float on
297+
windowrule = match:title ^(Picture-in-Picture)$, float on
298+
windowrule = match:class ^(io.crow_translate.CrowTranslate)$, float on
299+
windowrule = match:class (pot), match:title (Translate|Translator|OCR|PopClip|Screenshot Translate), float on
300+
windowrule = match:class ^(org.telegram.desktop)$, match:title ^(Media viewer)$, float on
301+
windowrule = match:title ^(Demo-Mode)$, float on
302+
windowrule = match:class ^(org.fcitx.fcitx5-config-qt)$, match:title ^(Classic User Interface — Fcitx Configuration)$, size 30% 50%
303+
windowrule = match:class ^(org.fcitx.fcitx5-config-qt)$, match:title ^(Fcitx Configuration)$, float on
304+
windowrule = match:class ^(Zotero)$, match:title ^(Zotero Settings)$, float on
305+
windowrule = match:class ^(xdg-desktop-portal-gtk)$, float on
306+
windowrule = match:class ^(Meeting)$, match:title ^(Feishu Meetings)$, float on
307+
windowrule = match:title ^(LarkSSPromptWindow)$, no_blur on
308+
windowrule = match:title ^(LarkSSPromptWindow)$, no_focus on
309+
windowrule = match:title ^(wemeetapp)$, no_blur on
310+
windowrule = match:title ^(wemeetapp)$, no_focus on
312311

313312
##############################
314313
### PLUGINS ###

mise.toml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ docker run --rm --device /dev/net/tun --cap-add NET_ADMIN -ti \
360360
depends = ["install go-yq"]
361361
usage = '''
362362
arg "<action>" help="action: up | down | restart | logs"
363-
flag "-e --easyconnect" help="start easyconnect vpn before starting the proxy service"
363+
flag "-t --enable-tun" help="enable system tuning"
364+
flag "-e --enable-easyconnect" help="start easyconnect vpn before starting the proxy service"
364365
flag "--ec-domain <domain>" help="easyconnect VPN domain"
365366
flag "--ec-username <username>" help="easyconnect VPN username"
366367
flag "--ec-password <password>" help="easyconnect VPN password"
@@ -369,34 +370,48 @@ flag "--ec-password <password>" help="easyconnect VPN password"
369370

370371
run = '''
371372
#!/usr/bin/env bash
373+
set -e pipefail
372374
373375
pushd ./service/proxy/
374376
if [ ! -f mihomo/config.local.yaml ]; then
375377
# 参考config.example.yaml 创建
376378
echo "Please create the config.local.yaml file in the service/proxy/mihomo directory based on the config.example.yaml"
377379
exit 1
378380
fi
381+
mihomo_configs=(mihomo/config.base.yaml)
382+
compose_files=(docker-compose.base.yaml)
383+
379384
380385
# 检查变量是否定义
381386
if [ "${usage_easyconnect}" == "true" ]; then
387+
# 插入 easyconnect 配置文件
382388
if [ -z "${usage_ec_domain}" ] || [ -z "${usage_ec_username}" ] || [ -z "${usage_ec_password}" ]; then
383389
echo "When --easyconnect is specified, --ec-domain, --ec-username, and --ec-password must also be provided."
384390
exit 1
385391
fi
386392
393+
mihomo_configs+=("mihomo/config.easyconnect.yaml")
394+
compose_files+=("docker-compose.easyconnect.yaml")
387395
388-
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1) * select(fileIndex == 2)' mihomo/config.base.yaml mihomo/config.easyconnect.yaml mihomo/config.local.yaml > mihomo/config.yaml
389396
export EC_DOMAIN="${usage_ec_domain}"
390397
export EC_USERNAME="${usage_ec_username}"
391398
export EC_PASSWORD="${usage_ec_password}"
392-
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' docker-compose.base.yaml docker-compose.easyconnect.yaml > docker-compose.yaml
393-
else
394-
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' mihomo/config.base.yaml mihomo/config.local.yaml > mihomo/config.yaml
395-
cp docker-compose.base.yaml docker-compose.yaml
396399
fi
397400
401+
if [ "${usage_enable_tun}" == "true" ]; then
402+
mihomo_configs+=("mihomo/config.tun.yaml")
403+
fi
404+
405+
mihomo_configs+=("mihomo/config.local.yaml")
398406
407+
# 使用yq合并配置文件与docker compose文件
408+
yq ea '. as $item ireduce ({}; . * $item )' "${mihomo_configs[@]}" > mihomo/config.yaml
399409
410+
if [ "${usage_action}" == "down" ] || [ "${usage_action}" == "restart" ]; then
411+
echo "Bringing down existing proxy service..."
412+
else
413+
yq ea '. as $item ireduce ({}; . * $item )' "${compose_files[@]}" > docker-compose.yaml
414+
fi
400415
docker compose ${usage_action}
401416
402417
'''

service/proxy/docker-compose.base.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ services:
44
image: ghcr.io/metacubex/metacubexd:latest
55
restart: always
66
ports:
7-
- '8091:80'
7+
- "8091:80"
88
environment:
9-
- DEFAULT_BACKEND_URL=http://127.0.0.1:8092
10-
11-
# Optional: mihomo instance
9+
DEFAULT_BACKEND_URL: http://127.0.0.1:8092
1210
mihomo:
1311
container_name: mihomo
1412
image: docker.io/metacubex/mihomo:Alpha
@@ -19,4 +17,5 @@ services:
1917
volumes:
2018
- ./mihomo/config.yaml:/root/.config/mihomo/config.yaml
2119
- /dev/net/tun:/dev/net/tun
22-
20+
- /etc/timezone:/etc/timezone:ro
21+
- /etc/localtime:/etc/localtime:ro
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
2-
3-
# docker run --rm --device /dev/net/tun --cap-add NET_ADMIN -ti \
4-
# -p 127.0.0.1:${usage_socks_port}:1080 \
5-
# -p 127.0.0.1:${usage_http_port}:8888 \
6-
# -e EC_VER=7.6.7 \
7-
# -e CLI_OPTS="-d ${usage_domain} -u ${usage_username} -p ${usage_password}" \
81
services:
92
easyconnect:
103
container_name: easyconnect
@@ -17,7 +10,6 @@ services:
1710
environment:
1811
EC_VER: 7.6.7
1912
CLI_OPTS: "-d ${EC_DOMAIN} -u ${EC_USERNAME} -p ${EC_PASSWORD}"
20-
2113
ports:
22-
- '8093:1080'
23-
- '8094:8888'
14+
- "8093:1080"
15+
- "8094:8888"
Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,83 @@
11
mixed-port: 8090
22
external-controller: 127.0.0.1:8092
3-
43
geodata-mode: true
54
geo-auto-update: false
6-
75
rule-providers:
86
reject:
97
type: http
108
behavior: domain
119
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt"
1210
path: ./ruleset/reject.yaml
1311
interval: 86400
14-
1512
icloud:
1613
type: http
1714
behavior: domain
1815
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt"
1916
path: ./ruleset/icloud.yaml
2017
interval: 86400
21-
2218
apple:
2319
type: http
2420
behavior: domain
2521
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt"
2622
path: ./ruleset/apple.yaml
2723
interval: 86400
28-
2924
google:
3025
type: http
3126
behavior: domain
3227
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt"
3328
path: ./ruleset/google.yaml
3429
interval: 86400
35-
3630
proxy:
3731
type: http
3832
behavior: domain
3933
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt"
4034
path: ./ruleset/proxy.yaml
4135
interval: 86400
42-
4336
direct:
4437
type: http
4538
behavior: domain
4639
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt"
4740
path: ./ruleset/direct.yaml
4841
interval: 86400
49-
5042
private:
5143
type: http
5244
behavior: domain
5345
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt"
5446
path: ./ruleset/private.yaml
5547
interval: 86400
56-
5748
gfw:
5849
type: http
5950
behavior: domain
6051
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt"
6152
path: ./ruleset/gfw.yaml
6253
interval: 86400
63-
6454
tld-not-cn:
6555
type: http
6656
behavior: domain
6757
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt"
6858
path: ./ruleset/tld-not-cn.yaml
6959
interval: 86400
70-
7160
telegramcidr:
7261
type: http
7362
behavior: ipcidr
7463
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt"
7564
path: ./ruleset/telegramcidr.yaml
7665
interval: 86400
77-
7866
cncidr:
7967
type: http
8068
behavior: ipcidr
8169
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt"
8270
path: ./ruleset/cncidr.yaml
8371
interval: 86400
84-
8572
lancidr:
8673
type: http
8774
behavior: ipcidr
8875
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
8976
path: ./ruleset/lancidr.yaml
9077
interval: 86400
91-
9278
applications:
9379
type: http
9480
behavior: classical
9581
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt"
9682
path: ./ruleset/applications.yaml
9783
interval: 86400
98-
99-
100-
tun:
101-
enable: true
102-
auto-route: true
103-
auto-redirect: true
104-
auto-detect-interface: true
105-
device: utun-mihomo
106-
107-
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
proxies:
2-
- name: "easyconnect"
3-
type: http
4-
server: 127.0.0.1
5-
port: 8094
6-
2+
- name: "easyconnect"
3+
type: http
4+
server: 127.0.0.1
5+
port: 8094

service/proxy/mihomo/config.local.example.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ proxy-providers:
44
url: "https://xxxx"
55
type: http
66
interval: 86400
7-
health-check: {enable: true, url: "https://www.gstatic.com/generate_204", interval: 300}
7+
health-check:
8+
{
9+
enable: true,
10+
url: "https://www.gstatic.com/generate_204",
11+
interval: 300,
12+
}
813
exclude-filter: "套餐|流量|群组|频道|官网|推荐使用|测试|电报|订阅|地址"
914
header:
1015
User-Agent:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#------------------------TUN 配置------------------------#
3+
tun:
4+
enable: true
5+
stack: system
6+
auto-route: true
7+
auto-detect-interface: true
8+
dns-hijack:
9+
- any:53
10+
- tcp://any:53
11+
12+
#------------------------DNS 配置------------------------#
13+
dns:
14+
enable: true # 启用DNS服务器
15+
prefer-h3: true # 优先使用HTTP/3查询
16+
ipv6: false # DNS解析IPv6
17+
listen: 0.0.0.0:53 # DNS监听地址
18+
enhanced-mode: redir-host # DNS模式: fake-ip或redir-host
19+
use-hosts: true # 使用hosts文件
20+
21+
# 默认DNS服务器(用于解析其他DNS服务器的域名)
22+
default-nameserver:
23+
- 223.5.5.5 # 阿里DNS
24+
- 119.29.29.29 # 腾讯DNS
25+
26+
# DNS服务器分流策略
27+
nameserver-policy:
28+
'www.google.com': 'https://dns.google/dns-query' # Google域名使用Google DNS
29+
'www.facebook.com': 'https://dns.google/dns-query' # Facebook域名使用Google DNS
30+
'.cn': 'https://doh.pub/dns-query' # 中国域名使用国内DNS
31+
32+
# Fake-IP配置
33+
fake-ip-range: 198.18.0.1/16 # Fake-IP地址段
34+
fake-ip-filter: # Fake-IP过滤清单
35+
- "*.lan" # 本地域名
36+
- "localhost.ptlogin2.qq.com" # QQ登录
37+
38+
# 主要DNS服务器
39+
nameserver:
40+
# 国内DNS服务器
41+
- https://doh.pub/dns-query#h3=true # DNSPod DOH
42+
- https://dns.alidns.com/dns-query#h3=true # 阿里 DOH
43+
- tls://223.5.5.5:853 # 阿里 DOT
44+
45+
# 国外DNS服务器
46+
- https://dns.google/dns-query#h3=true # Google DOH
47+
- https://cloudflare-dns.com/dns-query#h3=true # Cloudflare DOH
48+
- quic://dns.adguard.com:784 # AdGuard DOQ
49+
50+
# 备用DNS服务器(用于解析国外域名)
51+
fallback:
52+
- https://dns.google/dns-query#h3=true
53+
- https://1.1.1.1/dns-query#h3=true
54+
- tls://8.8.8.8:853
55+

0 commit comments

Comments
 (0)