summarylogtreecommitdiffstats
path: root/config.yaml
blob: e1c33d5224b87eba891633dfad4896ce66674a0d (plain)
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
log:
  level: info
  file: ""

plugin:
  ################# 服务插件 ################

  # 启动服务器的插件
  - tag: main_server
    type: server
    args:
      entry:
        - _default_cache # 缓存
        - main_sequence # 分流逻辑
      server:
        - protocol: udp
          addr: 127.0.0.1:53
        - protocol: tcp
          addr: 127.0.0.1:53
        - protocol: udp
          addr: "[::1]:53"
        - protocol: tcp
          addr: "[::1]:53"

  ################# 可执行插件 ################

  # 包含分流的逻辑的插件
  - tag: main_sequence
    type: sequence
    args:
      exec:
        - if:
            - query_is_ad_domain # 已知的广告域名
          exec:
            - _block_with_nxdomain # 用 NXDOMAIN 屏蔽
            - _return

        - if:
            - query_is_local_domain # 已知的本地域名
            - "!_query_is_common" # 和不常见的请求类型
          exec:
            - forward_local # 用本地服务器
            - _return

        - if:
            - query_is_non_local_domain # 已知的非本地域名
          exec:
            - forward_remote # 用远程服务器
            - _return

        # 剩下的未知域名用 IP 分流。以下是"顺序 IP 分流"方案。先转发至本地服务器,然后
        # 判断应答 IP 再决定是否转发至远程服务器。没有竞争,很稳定,不易出错。
        # <高级> 如果想用"并发 IP 分流"方案,从下文的 <并发 IP 分流示例> 里选择一个方案,
        # 然后将下面几行替换掉。复制时注意缩进。
        # 并发分流会同时请求本地和远程服务器,延时稍低些,但存在竞争,可能出现非期望的分流结果。
        - forward_local # 先请求转发至本地服务器
        - if:
            - response_has_local_ip # 如果(本地)应答包含本地 IP
          exec:
            - _return # 就直接采用结果
        - forward_remote # 否则去请求远程服务器的结果

  # 转发请求至本地服务器的插件
  - tag: forward_local
    type: "fast_forward"
    args:
      upstream:
        - addr: https://223.5.5.5/dns-query

  # 转发请求至远程服务器的插件
  - tag: forward_remote
    type: "fast_forward"
    args:
      upstream:
        - addr: https://1.1.1.1/dns-query

  ################ 匹配器插件 #################

  - tag: query_is_local_domain # 匹配本地域名的插件
    type: query_matcher
    args:
      domain:
        - ext:/usr/share/v2ray/geosite.dat:cn

  - tag: query_is_non_local_domain # 匹配非本地域名的插件
    type: query_matcher
    args:
      domain:
        - ext:/usr/share/v2ray/geosite.dat:geolocation-!cn

  - tag: query_is_ad_domain # 匹配广告域名的插件
    type: query_matcher
    args:
      domain:
        - ext:/usr/share/v2ray/geosite.dat:category-ads-all

  - tag: response_has_local_ip # 匹配本地 IP的插件
    type: response_matcher
    args:
      ip:
        - ext:/usr/share/v2ray/geoip.dat:cn

include: []