summarylogtreecommitdiffstats
path: root/config.yaml
blob: d35a2fc256eb76956c9bde5a4caa87a8b1fbc42a (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
log:
  level: debug
  file: ""

data_providers:
  - tag: geosite
    file: /usr/share/v2ray/geosite.dat
    auto_reload: true
  - tag: geoip
    file: /usr/share/v2ray/geoip.dat
    auto_reload: true

plugins:
  # 缓存
  - tag: cache
    type: cache
    args:
      size: 1024

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

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

  # 匹配本地域名的插件
  - tag: query_is_local_domain
    type: query_matcher
    args:
      domain:
        - 'provider:geosite:cn'

  # 匹配非本地域名的插件
  - tag: query_is_non_local_domain
    type: query_matcher
    args:
      domain:
        - 'provider:geosite:geolocation-!cn'

  # 匹配广告域名的插件
  - tag: query_is_ad_domain
    type: query_matcher
    args:
      domain:
        - 'provider:geosite:category-ads-all'

  # 匹配本地 IP 的插件
  - tag: response_has_local_ip
    type: response_matcher
    args:
      ip:
        - 'provider:geoip:cn'

  # 主要的运行逻辑插件
  # sequence 插件中调用的插件 tag 必须在 sequence 前定义,
  # 否则 sequence 找不到对应插件。
  - tag: main_sequence
    type: sequence
    args:
      exec:
        # 缓存
        - cache

        # 屏蔽广告域名
        - if: query_is_ad_domain
          exec:
            - _new_nxdomain_response
            - _return

        # 已知的本地域名用本地服务器解析
        - if: query_is_local_domain
          exec:
            - forward_local
            - _return

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

          # 剩下的未知域名用 IP 分流。
          # 这里借助了 `fallback` 工作机制。分流原理请参考 `fallback`
          # 的工作流程。
          # primary 从本地服务器获取应答,丢弃非本地 IP 的结果。
        - primary:
            - forward_local
            - if: "(! response_has_local_ip) && [_response_valid_answer]"
              exec:
                - _drop_response
          # secondary 从远程服务器获取应答。
          secondary:
            - _prefer_ipv4
            - forward_remote
          # 这里建议设置成 local 服务器正常延时的 2~5 倍。
          # 这个延时保证了 local 延时偶尔变高时,其结果不会被 remote 抢答。
          # 如果 local 超过这个延时还没响应,可以假设 local 出现了问题。
          # 这时用就采用 remote 的应答。单位: 毫秒。
          fast_fallback: 200

servers:
  - exec: main_sequence
    listeners:
      - 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"