### qname Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Matches the QNAME of the request. It supports domain rules, domain set tags, and domain list files. Domain rules support extensions. ```plaintext qname google.com full:google.com $local_domains &./local_domains.txt ``` -------------------------------- ### Rate Limiter Usage Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/ke-zhi-xing-cha-jian.md Use the rate_limiter plugin in a sequence to match requests and reject those exceeding the QPS limit. ```yaml - matches: "!$rate_limit" exec: reject 3 ``` -------------------------------- ### qclass Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Matches the QCLASS of the request. Accepts one or more uint16 values. ```plaintext qclass 1 2 3 ``` -------------------------------- ### random Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Returns true with a specified probability. The probability is given as a float64. ```plaintext random 0.5 ``` -------------------------------- ### string_exp Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md A string matching matcher. It supports matching against URL path, server name (SNI), or environment variables. Supported operations include eq, prefix, suffix, contains, regexp, and zl (zero length). Rules can include multiple strings; any match returns true. Note: rules with spaces are not supported due to format limitations. ```plaintext string_exp server_name eq a.b.c d.e.f ``` -------------------------------- ### env Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Checks for the existence and value of environment variables. If env_value is omitted, it returns true if env_key exists. If env_value is provided, it returns true if the environment variable's value matches env_value. ```plaintext env CACHE_ENABLED ``` ```plaintext env NETWORK_TYPE lan ``` -------------------------------- ### mark Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Returns true if the request has any of the specified marks. Accepts one or more uint32 values. ```plaintext mark 1 2 3 ``` -------------------------------- ### resp_ip Matcher Example Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Matches IP addresses in A and AAAA records of the response. It returns true if any IP in the response matches the provided IP, CIDR, IP set tag, or IP list file. ```plaintext resp_ip 192.168.1.1/24 8.8.8.8 $local_ips &./local_ips.txt ``` -------------------------------- ### Download Memory and Goroutine Profiles Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/debug-nei-cun-yu-xing-neng-wen-ti.md Download memory and goroutine sampling data by accessing specific URLs. Ensure the API server is enabled in the configuration. ```shell http:///debug/pprof/allocs http:///debug/pprof/goroutine http:///debug/pprof/heap ``` -------------------------------- ### Rate Limiter Configuration Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/ke-zhi-xing-cha-jian.md Configure the rate_limiter plugin to control client request rates. Set QPS, burst, and network masks. ```yaml tag: "" type: "rate_limiter" args: qps: 20 # 客户端的请求 qps 限制。默认 20 burst: 40 # 突发数。允许客户端瞬间突发请求数。默认 40 mask4: 32 # IPv4 网段掩码。来自同网段的请求会被视为来自同一客户端。默认 32 mask6: 48 # IPv6 网段掩码。默认 48 ``` -------------------------------- ### mosdns 基本配置文件结构 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns.md 展示了 mosdns 的基本 YAML 配置文件结构,包括日志设置、API 入口、外部配置文件包含以及插件配置的占位符。 ```yaml log: level: info # 日志级别。可选 "debug" "info" "warn" "error"。默认 "info"。 production: false # 纯 json 输出。 file: "/path/to/log/file" # (实验性) 记录日志到文件。默认输出至 stderr。 # 注意: 日志应由守护进程处理而不是直接写入文件。 # 此选项仅用于调试。panic 日志不会被记录,其内容仍会 # 输出至 stderr 。 # (实验性) API 入口设置 api: http: "127.0.0.1:8080" # 在该地址启动 api 接口。 # []string, 从其他配置文件载入 plugins 插件设置。 # include 的插件会比本配置文件中的插件先初始化。 include: [] # 插件设置 plugins: - tag: tag1 # 插件的 tag。由用户自由设定但不能重复。可省略。 type: type1 # 插件类型。详见下文。 args: # 插件参数。取决于插件类型。详见下文。 key1: value1 ``` -------------------------------- ### Download CPU Profile Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/debug-nei-cun-yu-xing-neng-wen-ti.md Download CPU sampling data for analysis when CPU usage is abnormally high. This requires the API server to be enabled and the sampling duration to be specified. ```shell http:///debug/pprof/profile?seconds=5 ``` -------------------------------- ### Fallback Plugin Configuration Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/ke-zhi-xing-cha-jian.md Configure the fallback plugin for failover. Specify primary and secondary executables, and a rollback threshold. ```yaml tag: "" type: "fallback" args: primary: executable_tag # 主可执行插件的 tag secondary: executable_tag # 副可执行插件的 tag threshold: 500 # 无响应回滚阈值。单位毫秒。默认 500 。 always_standby: true # 副可执行插件始终待命。 ``` -------------------------------- ### 简单转发器配置示例 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns.md 配置一个简单的 mosdns 转发器,仅用于将不加密的 DNS53 请求通过 DoH 转发至 Google 服务器。适用于只需要进行 DNS 转发而无需其他复杂功能的场景。 ```yaml log: level: info plugins: # 转发至 Google 服务器的插件 - tag: forward_google type: forward args: upstreams: - addr: https://8.8.8.8/dns-query # 在同一端口启动 udp 和 tcp 服务器。 - type: udp_server args: entry: forward_google listen: 127.0.0.1:5533 - type: tcp_server args: entry: forward_google listen: 127.0.0.1:5533 ``` -------------------------------- ### UDP 服务器配置 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/fu-wu-qi-cha-jian.md 配置一个 UDP 服务器插件,指定要使用的可执行插件和监听地址。 ```yaml tag: "" type: "udp_server" args: entry: executable_tag # 可执行插件的 tag。 listen: 127.0.0.1:5353 # 监听地址。 ``` -------------------------------- ### 多功能转发器配置示例 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns.md 配置一个多功能的 mosdns 转发器,具备缓存加速、广告屏蔽和转发至 Google DoH 的功能。适用于需要同时处理缓存、广告过滤和外部解析的场景。 ```yaml log: level: info plugins: - tag: main type: sequence args: - matches: # 如果 - qname &./oisd_dbl_basic.txt # 如果请求的域名在广告列表内。 exec: reject 3 # 执行 直接返回 NXDOMAIN(3) 屏蔽。 - exec: cache 1024 # 然后。查找 cache。 - matches: # 如果 - has_resp # 有应答了(上一步 cache 找到应答) exec: accept # 结束。 # 上一步没有找到缓存,就会到这一步,转发至 Google 获取应答。 - exec: forward https://8.8.8.8/dns-query # sequence 结束(被 reject,accept,或者运行到末尾)后就会返回调用者。在这个配置文件中 # 调用者是下面的服务器。服务器就会返回应答至客户端。 # 启动 udp 和 tcp 服务器。 - type: udp_server args: entry: main # 收到的请求会执行上面的逻辑 listen: 127.0.0.1:5533 - type: tcp_server args: entry: main listen: 127.0.0.1:5533 ``` -------------------------------- ### QUIC 服务器配置 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/fu-wu-qi-cha-jian.md 配置一个实验性的 QUIC 服务器插件,支持 TLS 和空连接超时。 ```yaml tag: "" type: "quic_server" args: entry: executable_tag # 可执行插件的 tag。 listen: 127.0.0.1:853 # 监听地址。 cert: "./path/to/cert" key: "./path/to/key" idle_timeout: 30 # 空连接超时。单位秒。默认 30。 ``` -------------------------------- ### TCP 服务器配置 (Unix Domain Socket) Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/fu-wu-qi-cha-jian.md 配置一个 TCP 服务器插件,使用 Unix abstract domain socket 进行监听。 ```yaml tag: "" type: "tcp_server" args: entry: executable_tag # 可执行插件的 tag。 listen: "@tcp_socket" # 监听地址。 cert: "./path/to/cert" # 配置 cert 和 key 后会启用 TLS (DoT)。 key: "./path/to/key" idle_timeout: 10 # 空连接超时。单位秒。默认 10。 ``` -------------------------------- ### HTTP 服务器配置 (Unix Domain Socket) Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/fu-wu-qi-cha-jian.md 配置一个 HTTP 服务器插件,使用 Unix abstract domain socket 进行监听。 ```yaml tag: "" type: "http_server" args: entries: # []extry - path: /dns-query # 本路径执行 exec: executable_tag # 可执行插件的 tag。 src_ip_header: "X-Forwarded-For" # 从 HTTP 头获取用户 IP。 listen: "@http_socket" # 监听地址。 cert: "./path/to/cert" # 留空 cert 和 key 后会禁用 TLS。 key: "./path/to/key" idle_timeout: 10 # 空连接超时。单位秒。默认 30。 ``` -------------------------------- ### TCP 服务器配置 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/fu-wu-qi-cha-jian.md 配置一个 TCP 服务器插件,支持 TLS (DoT) 和空连接超时。 ```yaml tag: "" type: "tcp_server" args: entry: executable_tag # 可执行插件的 tag。 listen: 127.0.0.1:5353 # 监听地址。 cert: "./path/to/cert" # 配置 cert 和 key 后会启用 TLS (DoT)。 key: "./path/to/key" idle_timeout: 10 # 空连接超时。单位秒。默认 10。 ``` -------------------------------- ### HTTP 服务器配置 Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/fu-wu-qi-cha-jian.md 配置一个 HTTP 服务器插件,支持多路径映射、TLS 和从 HTTP 头获取用户 IP。 ```yaml tag: "" type: "http_server" args: entries: # []extry - path: /dns-query # 本路径执行 exec: executable_tag # 可执行插件的 tag。 src_ip_header: "X-Forwarded-For" # 从 HTTP 头获取用户 IP。 listen: 127.0.0.1:443 # 监听地址。 cert: "./path/to/cert" # 留空 cert 和 key 后会禁用 TLS。 key: "./path/to/key" idle_timeout: 10 # 空连接超时。单位秒。默认 30。 ``` -------------------------------- ### ECS Handler Plugin Configuration Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/ke-zhi-xing-cha-jian.md Configure the ecs_handler plugin to manage EDNS0 Client Subnet information. Control forwarding, preset ECS, and sending client addresses. ```yaml tag: "" type: "ecs_handler" args: forward: false # 是否转发来自下游的 ecs preset: 1.2.3.4 # 发送预设 ecs send: false # 是否发送 ecs mask4: 24 # ipv4 掩码。默认 24 mask6: 48 # ipv6 掩码。默认 48 ``` -------------------------------- ### has_resp Matcher Source: https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns/sequence-cha-jian.md Returns true if the response contains any records. === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.