-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathauto-redir-transparent-gateway.yaml
458 lines (378 loc) · 9.57 KB
/
auto-redir-transparent-gateway.yaml
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
####################################################################################
#
# Work on Linux, as a transparent proxy gateway, just replace the Subscription-1 URL.
#
# 运行在Linux机器上,作为透明代理网关使用,只需替换Subscription-1的订阅链接,
# 请把客户端的网关和DNS指向Linux机器的IP,客户端DNS为公网DNS时可不用指向网关的DNS。
#
####################################################################################
#mixed-port: 7890
#mitm-port: 7891
allow-lan: true
bind-address: '*'
# rule / script / global / direct (default value is rule)
mode: rule
# set log level to stdout (default value is info)
# debug / info / warning / error
log-level: warning
ipv6: false
sniffing: false
force-cert-verify: true
# enable debug API if true. API path: /debug/pprof/?token=xxxx
pprof: false
profile:
store-selected: true
store-fake-ip: true
tracing: false # default value is true
experimental:
# udp-fallback-policy: 'proxy' # a proxy that supports UDP
# A RESTful API for clash
external-controller: 0.0.0.0:9090
# A RESTful API server name, the RESTful API controller will serve at https scheme if not empty. (Optional)
#external-server-name: localhost
# Secret for RESTful API (Optional)
#secret: xxxx
external-ui: ./dashboard
# outbound interface name
interface-name: eth0
ebpf:
auto-redir:
- eth0 # gateway interface name, 网关对应的网卡接口名称
# - wlan0
tun:
enable: true
stack: system # system or gvisor
device: tun://utun
dns-hijack:
- any:53
- tcp://any:53
auto-route: true # auto set global route
# auto-detect-interface: true # conflict with interface-name
hosts:
'localhost': '127.0.0.1'
dns:
enable: true
use-hosts: true
ipv6: false
remote-dns-resolve: true # default value is true
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
listen: 0.0.0.0:53
# nameserver-policy:
# '+.example.com': 192.168.1.254
default-nameserver:
- 119.29.29.29
- 223.6.6.6
proxy-server-nameserver:
- https://1.12.12.12/dns-query
- https://223.5.5.5/dns-query
nameserver:
- https://120.53.53.53/dns-query
- tls://223.6.6.6:853
remote-nameserver:
- tls://8.8.8.8:853
- tls://1.1.1.1:853
fallback:
- tcp://8.8.8.8:53#DNS-Proxy # if set `remote-dns-resolve` to false, then enable it.
fake-ip-filter:
- '*.lan'
# - '+.example.com'
fallback-filter:
geoip: false
geosite:
- gfw
# domain:
# - '+.example.com'
ipcidr:
- 0.0.0.0/32
#mitm:
# hosts:
# - '+.google.cn'
# rules:
# - ^https?://(.*)google\.cn(.*) url 307 https://$1google.com$2
proxy-groups:
- name: Auto
type: url-test
interval: 1200
tolerance: 150
url: http://www.gstatic.com/generate_204
use: &Use
- Subscription-1
- name: Geo-HK
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "HongKong|HK|香港"
use: *Use
- name: Geo-TW
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "Taiwan|TW|台湾"
use: *Use
- name: Geo-SG
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "Singapore|SG|新加坡"
use: *Use
- name: Geo-JP
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "Japan|JP|日本"
use: *Use
- name: Geo-US
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "America|United States|US|美国"
use: *Use
- name: Geo-UK
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "Britain|England|UK|英国"
use: *Use
- name: Geo-DE
type: url-test
interval: 600
tolerance: 100
url: http://www.gstatic.com/generate_204
filter: "Germany|Deutsch|DE|德国"
use: *Use
- name: Geo-CN
type: select
disable-dns: true
filter: "China|CN|中国"
use: *Use
proxies:
- DIRECT
- name: Block
type: select
use: *Use
proxies:
- REJECT
- DIRECT
- Geo-HK
- Geo-TW
- Geo-SG
- Geo-JP
- Geo-US
- Geo-UK
- Geo-DE
- Geo-CN
- name: Proxy
type: select
use: *Use
proxies:
- Auto
- Geo-HK
- Geo-TW
- Geo-SG
- Geo-JP
- Geo-US
- Geo-UK
- Geo-DE
- Geo-CN
- DIRECT
- Block
- name: DNS-Proxy
type: select
use: *Use
proxies: &Proxy
- Proxy
- Auto
- Geo-HK
- Geo-TW
- Geo-SG
- Geo-JP
- Geo-US
- Geo-UK
- Geo-DE
- Geo-CN
- DIRECT
- Block
- name: Netflix
type: select
use: *Use
proxies: *Proxy
- name: Apple
type: select
use: *Use
proxies: *Proxy
- name: iCloud
type: select
use: *Use
proxies: *Proxy
- name: MicrosoftCN
type: select
use: *Use
proxies: *Proxy
- name: PayPal
type: select
use: *Use
proxies: *Proxy
- name: Steam
type: select
use: *Use
proxies: *Proxy
- name: Game
type: select
use: *Use
proxies: *Proxy
- name: Facebook
type: select
use: *Use
proxies: *Proxy
- name: Twitter
type: select
use: *Use
proxies: *Proxy
- name: Telegram
type: select
use: *Use
proxies: *Proxy
- name: GlobalTV
type: select
use: *Use
proxies: *Proxy
- name: YouTube
type: select
use: *Use
proxies: *Proxy
- name: Spotify
type: select
use: *Use
proxies: *Proxy
- name: SpeedTest
type: select
use: *Use
proxies: *Proxy
- name: Download
type: select
use: *Use
proxies: *Proxy
- name: CN
type: select
disable-dns: true
use: *Use
proxies: *Proxy
- name: Mismatch
type: select
use: *Use
proxies: *Proxy
proxy-providers:
Subscription-1:
type: http
url: "URL" # replace this URL with your provider's subscription link
path: ./providers/Subscription-1.yaml
interval: 6h
# prefix-name: "S-"
# url-proxy: true
# udp: true
header:
User-Agent:
- "Clash/v1.11.8"
health-check:
enable: false
interval: 0
url: http://www.gstatic.com/generate_204
# lazy: false # default value is true
script:
# path: ./script.star
code: |
blockHosts = ['analytics', 'adservice', 'firebase', 'bugly', 'safebrowsing', 'doubleclick']
directHosts = ['push.apple.com', 'iosapps.itunes.apple.com', 'jetbrains.com', 'msftconnecttest.com']
def main(ctx, metadata):
network = metadata["network"]
dst_port = int(metadata["dst_port"])
if network == 'udp' and dst_port == 443:
return "REJECT"
if network == "udp" and (dst_port == 123 or (dst_port >= 136 and dst_port <=139)):
return "DIRECT"
host = metadata["host"]
for kw in blockHosts:
if kw in host:
return "REJECT"
if ctx.rule_providers['category-ads-all'].match(metadata):
return "Block"
for kw in directHosts:
if kw in host:
return "DIRECT"
if ctx.rule_providers['icloud'].match(metadata):
return "iCloud"
if ctx.rule_providers['apple'].match(metadata):
return "Apple"
if ctx.rule_providers['microsoft@cn'].match(metadata):
return "MicrosoftCN"
if ctx.rule_providers['paypal@cn'].match(metadata):
return "CN"
if ctx.rule_providers['paypal'].match(metadata):
return "PayPal"
if ctx.rule_providers['twitter'].match(metadata):
return "Twitter"
if ctx.rule_providers['facebook'].match(metadata):
return "Facebook"
if ctx.rule_providers['youtube'].match(metadata):
return "YouTube"
if ctx.rule_providers['geolocation-!cn'].match(metadata):
return "Proxy"
if ctx.rule_providers['geolocation-cn'].match(metadata):
return "CN"
code = ""
ip = metadata["dst_ip"]
if ip != "":
code = ctx.geoip(ip)
if code == "PRIVATE" or code == "LAN":
return "DIRECT"
if code == "TELEGRAM":
return "Telegram"
else:
ip = ctx.resolve_ip(host)
if ip == "":
return "Mismatch"
code = ctx.geoip(ip) if code == "" else code
if code == "CN":
return "CN"
return "Mismatch" # default policy for requests which are not matched by any other script
engine: expr # or starlark (10x to 20x slower)
shortcuts:
QUIC: |
network == "udp" and dst_port == 443
Privacy: |
any(["analytics", "adservice", "firebase", "safebrowsing", "doubleclick", "bugly", "bugsnag"], host contains #)
BilibiliUdp: |
network == "udp" and match_provider("bilibili")
DirectUdp: |
network == "udp" and (dst_port == 123 or (dst_port >= 136 and dst_port <=139))
rules:
- GEOIP,private,DIRECT,no-resolve
- GEOIP,telegram,Telegram,no-resolve
- SCRIPT,QUIC,REJECT # Disable QUIC
- SCRIPT,Privacy,REJECT
- SCRIPT,BilibiliUdp,REJECT
- SCRIPT,DirectUdp,DIRECT
- DOMAIN-SUFFIX,push.apple.com,DIRECT
- GEOSITE,category-ads-all,Block
- DOMAIN-SUFFIX,jetbrains.com,DIRECT
- DOMAIN-SUFFIX,msftconnecttest.com,DIRECT
- DOMAIN,iosapps.itunes.apple.com,DIRECT
- GEOSITE,icloud,iCloud
- GEOSITE,apple,Apple
- GEOSITE,microsoft@cn,MicrosoftCN
- GEOSITE,paypal@cn,CN
- GEOSITE,paypal,PayPal
- GEOSITE,twitter,Twitter
- GEOSITE,facebook,Facebook
- GEOSITE,youtube,YouTube
- GEOSITE,geolocation-!cn,Proxy
- GEOSITE,geolocation-cn,CN
- GEOIP,cn,CN
- MATCH,Mismatch