Skip to content

Instantly share code, notes, and snippets.

@rampageX
Created December 25, 2021 03:03
Show Gist options
  • Save rampageX/65813cc7cfec1467466f267dec7a400c to your computer and use it in GitHub Desktop.
Save rampageX/65813cc7cfec1467466f267dec7a400c to your computer and use it in GitHub Desktop.

Revisions

  1. rampageX created this gist Dec 25, 2021.
    220 changes: 220 additions & 0 deletions mosdns_public.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,220 @@
    log:
    level: error # 日志级别。可选 `debug` `info` `warn` `error`。默认 `info`。
    file: "/var/log/mosdns.log" # 记录日志到文件。
    #level: debug
    #file: ""

    plugin:
    ## 启动 sequence 服务器 DoT
    # - tag: dot_server
    # type: server
    # args:
    # max_concurrent_queries: 0
    # entry: main_sequence
    # server:
    # - protocol: 'dot' # 服务器协议。可以是 `udp`, `tcp`, `dot/tls`, `doh/https`, `http`。必需。
    # addr: '0.0.0.0:8533' # 服务器监听地址。必需。
    # timeout: 5 # 请求处理超时时间。单位: 秒。默认: 5。
    # idle_timeout: 30 # 空连接超时时间。单位: 秒。默认: 10。适用于除了 `udp` 以外的协议。
    # cert: '/usr/local/nginx/conf/ssl/34567.com.fullchain.cer' # 证书文件。适用于 `dot`, `doh`。必需。
    # key: '/usr/local/nginx/conf/ssl/34567.com.key' # 证书密钥文件。适用于 `dot`, `doh`。必需。
    # url_path: '/dns-query' # url 路径。适用于 `doh`, `http`。如果为空,则任意路径的请求都能被处理。
    # get_user_ip_from_header: 'X-Forwarded-For' # 适用于 `doh`, `http`。尝试从 HTTP 头获取用户 IP。

    ## 启动 parallel 服务器 DoH
    # - tag: doh_server
    # type: server
    # args:
    # max_concurrent_queries: 0
    # entry: main_parallel
    # server:
    # - protocol: 'doh'
    # addr: '[::]:4433'
    # timeout: 5
    # idle_timeout: 30
    # cert: '/usr/local/nginx/conf/ssl/34567.com.fullchain.cer'
    # key: '/usr/local/nginx/conf/ssl/34567.com.key'
    # url_path: '/dns-query'
    # get_user_ip_from_header: 'X-Forwarded-For'

    ## 启动 parallel 服务器
    - tag: parallel_server
    type: server
    args:
    max_concurrent_queries: 0
    entry: main_sequence
    server:
    - protocol: udp
    addr: 0.0.0.0:5353
    - protocol: tcp
    addr: 0.0.0.0:5353

    ## 可执行插件-顺序
    - tag: main_sequence
    type: sequence
    args:
    exec:
    - edns0
    - _default_cache # 缓存
    - if:
    - match_local_domain # 处理已知的本地域名
    - "!_query_is_common" # 和不常见的请求类型
    exec:
    - ecs_local
    - forward_local
    - _end

    - if:
    - match_non_local_domain # 处理已知的非本地域名
    exec:
    - ecs_remote
    - forward_remote
    - _end

    - sequence_bypass_local # 分流未知域名。有两种方案:顺序或并行。这是顺序执行。


    ## 两种分流逻辑
    - tag: sequence_bypass_local # 顺序执行的分流逻辑
    type: sequence
    args:
    exec:
    - forward_local # 先请求转发至本地服务器
    - if:
    - match_local_ip # 如果应答包含本地 IP
    exec:
    - _end # 就直接采用结果
    - forward_remote # 否则用远程服务器的结果


    ## 匹配器插件
    # - tag: match_qtype_HTTPS # 匹配 HTTPS 请求
    # type: query_matcher
    # args:
    # type: [65]

    - tag: match_local_domain # 匹配请求域名是否是本地域名
    type: query_matcher
    args:
    domain:
    - ext:/root/cfg/geosite.dat:cn
    - ext:/root/cfg/domain_acclist.txt

    - tag: match_non_local_domain # 匹配请求域名是否是境外域名
    type: query_matcher
    args:
    domain:
    - ext:/root/cfg/domain_gfwlist.txt

    - tag: match_local_ip # 匹配应答的 IP 是否是本地 IP
    type: response_matcher
    args:
    ip:
    - ext:/root/cfg/geoip-only-cn-private.dat:cn

    ## ECS
    - tag: ecs_local
    type: ecs
    args:
    auto: true # 是否根据客户端地址自动附加 ECS。如果为 true,则预设地址不会被使用。
    force_overwrite: false # 如果请求已有 ECS,是否覆盖。
    mask4: 24 # 用于 ipv4 地址的掩码。
    mask6: 32 # 用于 ipv6 地址的掩码。
    ipv4: "" # 预设的 ipv4 地址。如果非空,会附加在 A 请求中。
    ipv6: "" # 预设的 ipv6 地址。如果非空,会附加在 AAAA 请求中。

    - tag: ecs_remote
    type: ecs
    args:
    auto: true
    force_overwrite: false
    mask4: 24
    mask6: 32
    ipv4: ""
    ipv6: ""

    - tag: edns0
    type: bufsize
    args:
    size: 4096 # 修改 EDNS0 UDP 负载大小。默认 512。最大 4096。

    ## 功能性插件
    - tag: forward_local # 转发至本地服务器
    type: forward
    args:
    upstream:
    - addr: https://i.233py.com/dns-query
    - addr: tls://dns.alidns.com
    trusted: true
    - addr: tls://dns.pub
    trusted: true
    insecure_skip_verify: false # 禁用 TLS 身份验证。
    fastest_ip: false # 最快 IP 模式。
    timeout: 6 # 超时时间,单位: 秒。
    # 用于解析上游服务器域名的 bootstrap 服务器地址。可配置多个。必须没有域名。可以为空,会使用系统设置。
    bootstrap:
    - 9.9.9.9:9953
    - 208.67.220.220:443

    - tag: forward_remote # 转发至远程服务器
    type: forward
    args:
    upstream:
    - addr: https://dns11.quad9.net/dns-query
    trusted: true
    - addr: https://dns.twnic.tw/dns-query
    trusted: true
    - addr: tls://dns.google
    trusted: true
    - addr: tls://dns.sb
    trusted: true
    insecure_skip_verify: false
    fastest_ip: false
    timeout: 6
    bootstrap:
    - 9.9.9.9:9953
    - 208.67.220.220:443

    # - tag: fast_forward_local
    # type: fast_forward
    # args:
    # ca: [ ] # 用于 TLS 验证的 CA 证书。适用于 `dot`,`doh` 协议。为空默认使用系统证书。
    # timeout: 5 # 请求超时时间。单位: 秒。默认 5。
    # upstream: # 上游服务器。至少要配置一个。可配置多个,会并发请求全部服务器。
    # - addr: 'tls://dns.alidns.com' # 服务器地址。必需。
    # dial_addr: 223.5.5.5:853 # 指定服务器网络地址。格式 `host:port`,端口不可省略。
    # trusted: false # 是否是可信服务器。仅配置了多个服务器时生效。
    # socks5: "" # socks5 服务器地址。格式 `host:port`。`:port` 不可省略。
    # max_conns: 1 # 最大连接数。目前仅适用于 `doh` 协议。默认: 1。
    # idle_timeout: 10 # 空连接超时时间。单位: 秒。
    # insecure_skip_verify: false # 是否禁用 TLS 验证。适用于 `dot`,`doh` 协议。

    # - addr: 'tls://dns.pub'
    # dial_addr: 162.14.21.56:853
    # trusted: false
    # socks5: ""
    # max_conns: 1
    # idle_timeout: 10
    # insecure_skip_verify: false

    # - tag: fast_forward_remote
    # type: fast_forward
    # args:
    # ca: [ ]
    # timeout: 5
    # upstream:
    # - addr: 'tls://dns11.quad9.net'
    # dial_addr: 9.9.9.11:853
    # trusted: true
    # socks5: ""
    # max_conns: 1
    # idle_timeout: 30
    # insecure_skip_verify: false

    # - addr: 'tls://dns.google'
    # dial_addr: 8.8.4.4:853
    # trusted: true
    # socks5: ""
    # max_conns: 1
    # idle_timeout: 30
    # insecure_skip_verify: false