在基于 Debian/Ubuntu 等 Linux 发行版上安装 dae 大鹅裸核代理
Linux 平台使用 dae (大鹅) 搭建透明代理
在基于 Debian/Ubuntu 等 Linux 发行版上安装 dae 大鹅裸核代理
下载和安装 dae 大鹅
去 Github 下载对应架构的安装包,我的是 Debian 系统,下载 dae-linux-x86_64.deb;使用以下命令安装:
1
sudo dpkg -i dae-linux-x86_64.deb
1
sudo apt install dae-linux-x86_64.deb
以上两个命令随便选一个就行。
dae 大鹅配置文件
编辑或者创建 /etc/dae/config.dae
1
vi /etc/dae/config.dae
复制粘贴以下内容
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
# You can split the configuration into multiple files with `include { ... }`.
# include {}
global {
##### Software options.
tproxy_port: 12345
tproxy_port_protect: true
pprof_port: 0
so_mark_from_dae: 0
log_level: info
disable_waiting_network: false
##### Interface and kernel options.
# lan_interface: eth0
wan_interface: auto
auto_config_kernel_parameter: true
##### Node connectivity check.
tcp_check_url: 'http://www.google.com/gen_204,216.58.200.36,2404:6800:4005:809::2004'
tcp_check_http_method: GET
udp_check_dns: 'dns.google:53,8.8.8.8,2001:4860:4860::8888'
check_interval: 30s
check_tolerance: 0ms
##### Connecting options.
dial_mode: domain
allow_insecure: true
sniffing_timeout: 100ms
# TLS & uTLS 客户端特征伪装
tls_implementation: utls
utls_imitate: chrome_auto
tls_fragment: false
# 带宽塑形
bandwidth_max_tx: '200 mbps'
bandwidth_max_rx: '1 gbps'
}
subscription {
my_sub: 'https-file://example.com/sub/url'
}
# 节点配置
node {
local_socks5: 'socks5://127.0.0.1:1080'
my_vless: 'vless://auto%uuid@ip:端口?encryption=none&security=tls&sni=域名&fp=edge#🇳🇱 荷兰 re'
my_vmess: 'vmess://uuid@域名:端口?encryption=auto&type=ws&security=tls&host=de010.域名&path=%2Fprofile%2Fde09#🇩🇪 德国 10'
}
# 分组配置
group {
proxy {
# 🇺🇸 节点选择策略
policy: min_moving_avg
# 指定机场节点
filter: subtag(my_sub) && name(keyword: '美国 01')
}
# 💬 社媒专用分组
social_proxy {
# 可根据需要选择 min_moving_avg 或 latency
policy: min_moving_avg
# 自建家庭宽带线路适合流媒体/社媒的节点
filter: name(keyword: '德国 10')
}
}
# DNS 配置:upstream 与 DNS 分流规则必须嵌套在 dns{} 内,
dns {
upstream {
cnnicdns: 'tcp+udp://1.8.8.8:53'
onedns: 'tcp+udp://52.80.66.66:53'
localdns: 'tcp+udp://192.168.1.1:53'
googledns: 'h3://8.8.8.8/dns-query'
securedns: 'https://doh.360.cn/dns-query'
cloudflare-dns: 'h3://1.1.1.1/dns-query'
}
routing {
request {
qname(geosite:adobe, geosite:linkedin, geosite:meta, geosite:github, geosite:google, geosite:x) -> cloudflare-dns
qname(geosite:cn, geosite:alibaba, geosite:debian, geosite:category-ru) -> localdns
qname(geosite:adguard, geosite:amazon, geosite:apple, geosite:microsoft, geosite:mozilla) -> securedns
qname(geosite:lark, geosite:category-games, geosite:category-dev) -> cnnicdns
qname(suffix:bjxuejing.cn, suffix: meixi-mgo.com, suffix: xzmgo.com, suffix:tuyoo.com, suffix:wanyiwan.top) -> onedns
fallback: googledns
}
}
}
# 路由匹配核心
routing {
### Preset rules.
pname(NetworkManager, systemd-resolved, dnsmasq, gnome-weather, sing-box) -> must_direct
dip(224.0.0.0/3, 'ff00::/8') -> direct
dip(geoip:private) -> direct
### 自定义规则
domain(suffix:cfysoft.cc, suffix:cndhl.com, suffix:huohua.icu, suffix:jisuimage.com, suffix:mytvapp.cc, suffix:scdn.co, suffix:xmfyy.com) -> direct
domain(suffix:cdnbuild.net, suffix:cdngslb.com, suffix:ibytedapm.com, suffix:icoa.cn, suffix:icoa.vip, suffix:tigress.cc) -> direct
domain(suffix:bjxuejing.cn, suffix:edu.kg, suffix:hdcdn.online, suffix:ip.sb, suffix:open-meteo.com, suffix:wanyiwan.top) -> direct
domain(suffix:beacondb.net, suffix:dmcdn.net, suffix:fuckcloudnative.io, suffix:localsend.org, suffix:oceansaver.in, suffix:rustdesk.com) -> direct
domain(suffix:dynadot.com, suffix: frantech.ca, suffix: gnome.org, suffix: gwdg.de, suffix: meixi-mgo.com, suffix: xzmgo.com) -> direct
domain(suffix: accuweather.com, suffix:aviationweather.gov, suffix:met.no, suffix:openweathermap.org, suffix:qweather.com, suffix:weatherapi.com) -> direct
domain(suffix:analytics.google.com, suffix:ads.google.com, suffix:tpc.googlesyndication.com) -> proxy
domain(suffix:addons.mozilla.org, suffix:onedrive.live.com, suffix:primevideo.com) -> proxy
domain(suffix:flathub.org, suffix:ml0987.com, suffix:openwrt.org, suffix:steamcommunity.com) -> proxy
domain(geosite:category-ads) -> block
dip(geoip:cn, geoip:private, 8.219.1.15, 47.245.124.74) -> direct
dip(91.108.4.0/22, 91.108.8.0/22, 91.108.12.0/22, 91.108.16.0/22, 91.108.20.0/22, 91.108.36.0/23, 91.108.38.0/23, 91.108.56.0/22) -> proxy
dip(149.154.160.0/20, 149.154.164.0/22, 149.154.168.0/22, 149.154.172.0/22, 185.76.192.0/22) -> proxy
dip('2001:b28:f23c::/47', '2001:b28:f23f::/48', '2001:67c:4e8::/48') -> proxy
domain(geosite:github, geosite:google, geosite:linkedin, geosite:meta, geosite:paypal, geosite:telegram, geosite:tiktok, geosite:x) -> proxy
domain(geosite:alibaba, geosite:cn, geosite:adobe, geosite:category-ru) -> direct
domain(geosite:amazon, geosite:apple, geosite:microsoft, geosite:mozilla) -> direct
domain(geosite:category-games, geosite:category-dev, geosite:category-browser-!cn) -> direct
fallback: proxy
}
如果你是软路由,应该取消注释 # lan_interface: eth0,并使用以下命令查看所有网卡及其 IP 地址
1
ip addr
或者
1
ip route show default
WAN 口:通常连接光猫或上级路由器,获取的是运营商的公网 IP/运营商内网 IP,或者是通过 PPPoE 拨号的网卡。
LAN 口:通常连接 ap 或下级设备,上面配置的是你本地局域网的网关 IP(例如 192.168.x.1)。我这里是 Debian 桌面系统,所以只要设置 wan 口 就可以了。
配置里的机场订阅部分,把引号里的内容换成你的订阅链接。’https’ 后加上 ‘-file’,这样在启动 dae 服务后,会向 /etc/dae/persist.d/my_sub.sub 这个文件写入节点信息。
1
2
3
subscription {
my_sub: 'https-file://example.com/sub/url'
}
检查一下配置信息是否有错
1
dae validate -c /etc/dae/config.dae
没有错误不会有任何输出
启动 dae 服务,开启科学上网之旅
启动 dae 服务
1
systemctl start dae
查看 dae 服务状态
1
systemctl status dae
重启和停止 dae 服务
1
systemctl restart dae
1
systemctl stop dae
选择特定节点
要更改节点,首先需要解码 dae 下载的 Base64 订阅,创建以下脚本
1
vi /etc/dae/convert-sub-view.sh
复制粘贴以下内容
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#!/bin/sh
# ============================================================
# dae 订阅可读版生成脚本
#
# 输入:
# /etc/dae/persist.d/my_sub.sub
#
# 输出:
# /etc/dae/cnsub.sub
#
# 功能:
# 1. 解码 dae 下载的 Base64 订阅
# 2. 自动识别多种代理协议
# 3. VMess 从 JSON 的 ps 字段读取节点名称
# 4. VLESS / AnyTLS / Trojan / SS / SSR / Hysteria2 /
# TUIC / Juicity 等从 URI #fragment 读取节点名称
# 5. URL 解码中文、emoji 等节点名称
# 6. 保留原始节点 URI,不修改节点参数
#
# 注意:
# cnsub.sub 仅供人工查看
# 不加入 config.dae
# 不会影响 dae 运行
# ============================================================
SRC="/etc/dae/persist.d/my_sub.sub"
DST="/etc/dae/cnsub.sub"
if [ ! -f "$SRC" ]; then
echo "错误:找不到源文件:"
echo " $SRC"
exit 1
fi
python3 - "$SRC" "$DST" <<'PY'
import sys
import base64
import json
import urllib.parse
import re
from pathlib import Path
SRC = Path(sys.argv[1])
DST = Path(sys.argv[2])
# ============================================================
# Base64 解码
# ============================================================
def b64decode(data):
"""
自动处理:
- 普通 Base64
- URL-safe Base64
- 缺少 =
- 换行/空白
"""
data = data.strip()
data = re.sub(r"\s+", "", data)
# 自动补齐 Base64 padding
data += "=" * (-len(data) % 4)
try:
return base64.urlsafe_b64decode(data)
except Exception:
return base64.b64decode(data)
# ============================================================
# URL fragment 解码
# ============================================================
def decode_fragment(fragment):
"""
将:
%F0%9F%87%BA%F0%9F%87%B8%20%E7%BE%8E%E5%9B%BD
转换成:
🇺🇸 美国
"""
try:
return urllib.parse.unquote(fragment)
except Exception:
return fragment
# ============================================================
# 判断是否像代理 URI
# ============================================================
PROTOCOLS = (
"vmess://",
"vless://",
"anytls://",
"trojan://",
"ss://",
"ssr://",
"hysteria://",
"hysteria2://",
"hy2://",
"tuic://",
"juicity://",
"socks://",
"socks5://",
)
def is_proxy_uri(line):
line_lower = line.lower()
return line_lower.startswith(PROTOCOLS)
# ============================================================
# 获取 URI fragment 名称
# ============================================================
def get_uri_name(uri):
"""
从:
anytls://[email protected]:443/?insecure=1#%E7%BE%8E%E5%9B%BD
获取:
美国
"""
try:
if "#" not in uri:
return ""
fragment = uri.split("#", 1)[1]
return decode_fragment(fragment).strip()
except Exception:
return ""
# ============================================================
# VMess 节点解析
# ============================================================
def get_vmess_info(uri):
"""
VMess 格式:
vmess://BASE64(JSON)
返回:
节点名称
JSON 对象
"""
try:
payload = uri[len("vmess://"):].strip()
raw = b64decode(payload)
obj = json.loads(
raw.decode(
"utf-8",
errors="replace"
)
)
name = obj.get("ps", "")
if name is None:
name = ""
name = str(name).strip()
return name, obj
except Exception as e:
return "", None
# ============================================================
# 解析一个节点
# ============================================================
def parse_node(uri):
uri = uri.strip()
# --------------------------------------------------------
# VMess
# --------------------------------------------------------
if uri.lower().startswith("vmess://"):
name, obj = get_vmess_info(uri)
if name:
return "VMess", name
# 如果 VMess 内部没有 ps
fragment_name = get_uri_name(uri)
if fragment_name:
return "VMess", fragment_name
return "VMess", "未命名节点"
# --------------------------------------------------------
# VLESS
# --------------------------------------------------------
if uri.lower().startswith("vless://"):
name = get_uri_name(uri)
return "VLESS", name or "未命名节点"
# --------------------------------------------------------
# AnyTLS
# --------------------------------------------------------
if uri.lower().startswith("anytls://"):
name = get_uri_name(uri)
return "AnyTLS", name or "未命名节点"
# --------------------------------------------------------
# Trojan
# --------------------------------------------------------
if uri.lower().startswith("trojan://"):
name = get_uri_name(uri)
return "Trojan", name or "未命名节点"
# --------------------------------------------------------
# Shadowsocks
# --------------------------------------------------------
if uri.lower().startswith("ss://"):
name = get_uri_name(uri)
return "Shadowsocks", name or "未命名节点"
# --------------------------------------------------------
# ShadowsocksR
# --------------------------------------------------------
if uri.lower().startswith("ssr://"):
name = get_uri_name(uri)
return "ShadowsocksR", name or "未命名节点"
# --------------------------------------------------------
# Hysteria
# --------------------------------------------------------
if uri.lower().startswith("hysteria://"):
name = get_uri_name(uri)
return "Hysteria", name or "未命名节点"
# --------------------------------------------------------
# Hysteria2
# --------------------------------------------------------
if uri.lower().startswith("hysteria2://"):
name = get_uri_name(uri)
return "Hysteria2", name or "未命名节点"
# --------------------------------------------------------
# HY2
# --------------------------------------------------------
if uri.lower().startswith("hy2://"):
name = get_uri_name(uri)
return "Hysteria2", name or "未命名节点"
# --------------------------------------------------------
# TUIC
# --------------------------------------------------------
if uri.lower().startswith("tuic://"):
name = get_uri_name(uri)
return "TUIC", name or "未命名节点"
# --------------------------------------------------------
# Juicity
# --------------------------------------------------------
if uri.lower().startswith("juicity://"):
name = get_uri_name(uri)
return "Juicity", name or "未命名节点"
# --------------------------------------------------------
# SOCKS
# --------------------------------------------------------
if uri.lower().startswith(("socks://", "socks5://")):
name = get_uri_name(uri)
return "SOCKS", name or "未命名节点"
# --------------------------------------------------------
# 未知协议
# --------------------------------------------------------
return "Unknown", get_uri_name(uri) or "未命名节点"
# ============================================================
# 读取原始文件
# ============================================================
raw = SRC.read_text(
encoding="utf-8",
errors="replace"
).strip()
if not raw:
print("错误:源文件为空")
sys.exit(1)
# ============================================================
# 解码最外层 Base64
# ============================================================
def decode_subscription(data):
# 如果已经是明文 URI 列表
if any(
data.startswith(protocol)
for protocol in PROTOCOLS
):
return data
try:
decoded = b64decode(data).decode(
"utf-8",
errors="replace"
)
# 判断解码后是否确实像节点列表
if any(
line.strip().lower().startswith(PROTOCOLS)
for line in decoded.splitlines()
):
return decoded
# 有些订阅可能多套 Base64
# 再尝试一次
try:
decoded2 = b64decode(decoded).decode(
"utf-8",
errors="replace"
)
if any(
line.strip().lower().startswith(PROTOCOLS)
for line in decoded2.splitlines()
):
return decoded2
except Exception:
pass
return decoded
except Exception:
return data
decoded = decode_subscription(raw)
# ============================================================
# 逐行解析
# ============================================================
nodes = []
status_lines = []
unknown_lines = []
for line in decoded.splitlines():
line = line.strip()
if not line:
continue
# --------------------------------------------------------
# STATUS
# --------------------------------------------------------
if line.startswith("STATUS="):
status_lines.append(line)
continue
# --------------------------------------------------------
# 标准代理 URI
# --------------------------------------------------------
if is_proxy_uri(line):
protocol, name = parse_node(line)
nodes.append({
"protocol": protocol,
"name": name,
"uri": line
})
continue
# --------------------------------------------------------
# 其他未知内容
# --------------------------------------------------------
unknown_lines.append(line)
# ============================================================
# 生成 cnsub.sub
# ============================================================
with DST.open(
"w",
encoding="utf-8"
) as f:
f.write("# ============================================================\n")
f.write("# dae 订阅人类可读版\n")
f.write("# ============================================================\n")
f.write("#\n")
f.write("# 本文件仅供人工查看。\n")
f.write("# 不参与 dae 运行。\n")
f.write("# 不要将本文件加入 config.dae 的 subscription。\n")
f.write("#\n")
f.write(f"# 原始文件:{SRC}\n")
f.write("# ============================================================\n\n")
# --------------------------------------------------------
# STATUS
# --------------------------------------------------------
if status_lines:
f.write("# -------------------- 订阅状态 --------------------\n")
for status in status_lines:
f.write(f"# {status}\n")
f.write("\n")
# --------------------------------------------------------
# 节点
# --------------------------------------------------------
f.write("# -------------------- 节点列表 --------------------\n\n")
for index, node in enumerate(nodes, 1):
f.write(
f"# {index:03d}. "
f"[{node['protocol']}] "
f"{node['name']}\n"
)
f.write(node["uri"])
f.write("\n\n")
# --------------------------------------------------------
# 未知内容
# --------------------------------------------------------
if unknown_lines:
f.write(
"# -------------------- 未识别内容 --------------------\n"
)
for line in unknown_lines:
f.write(f"# {line}\n")
f.write("\n")
# ============================================================
# 输出统计
# ============================================================
print()
print("============================================================")
print(" dae 订阅人类可读版生成完成")
print("============================================================")
print(f"源文件:{SRC}")
print(f"输出文件:{DST}")
print()
print(f"节点总数:{len(nodes)}")
print()
# 按协议统计
protocol_count = {}
for node in nodes:
protocol = node["protocol"]
protocol_count[protocol] = (
protocol_count.get(protocol, 0) + 1
)
for protocol, count in protocol_count.items():
print(
f" {protocol:<15} {count:>4}"
)
print()
print("节点列表:")
print("------------------------------------------------------------")
for index, node in enumerate(nodes, 1):
print(
f"{index:03d}. "
f"[{node['protocol']}] "
f"{node['name']}"
)
print("------------------------------------------------------------")
print()
print(f"已生成:{DST}")
print()
PY
exit $?
更改一下脚本权限
1
chmod +x /etc/dae/convert-sub-view.sh
运行脚本,脚本会在终端输出节点内容,并把节点信息写入到 /etc/dae/cnsub.sub。
1
./convert-sub-view.sh
查看 /etc/dae/cnsub.sub 内容
1
cat /etc/dae/cnsub.sub
节点信息类似下面的格式,
1
vless://auto%uuid@ip:端口?encryption=none&security=tls&sni=域名&fp=edge#🇳🇱 荷兰 re
在 dae 大鹅的配置 /etc/dae/config.dae 中,修改指定机场节点的名称关键词即可完成修改,例如。
1
2
3
4
5
6
7
proxy {
# 节点选择策略
policy: min_moving_avg
# 指定机场节点
filter: subtag(my_sub) && name(keyword: '荷兰 re')
}
This post is licensed under CC BY 4.0 by the author.
