# mosdns v5

版本: v5.3

## 功能概述

mosdns 是一个插件化的 DNS 转发器。用户可以按需定制自己的 DNS 处理逻辑。

mosdns 自带的功能:

* 匹配器:
  * 匹配请求的特性。域名，类型，来源 IP  等。
  * 匹配应答的特性。应答 IP，CNAME 等。
* 功能:
  * UDP, TCP, DoT, DoH(支持H3), DoQ 客户端和服务器。
  * 缓存应答 (不支持 ECS)。
  * 自动判断域名是否是双栈域名然后屏蔽 IPv4/6 请求，不会影响纯 IPv6/4 域名。
  * 在请求上附加预设 ECS。
  * 修改应答的 TTL。
  * 为域名设定 IP。(hosts)
  * 返回包含特定 IP 应答。(blackhole)
  * 替换(重定向)请求的域名。请求域名 A，但返回域名 B 的记录。(redirect)
  * 手动构建包含任意记录的应答。(arbitrary)
  * 用 IP 反查经过 mosdns 处理的域名。可响应 PTR 请求，也可通过 HTTP 接口查询。(reverse\_lookup)
  * 动态路由: 将应答 IP 写入 ipset 和 nftables。

## 如何配置

配置说明和示例，详见:

{% content-ref url="/pages/oOfL7kIYdLGpwDHYoj3t" %}
[如何配置 mosdns](/mosdns-wiki/mosdns-v5/ru-he-pei-zhi-mosdns.md)
{% endcontent-ref %}

## 如何使用

mosdns 只有一个二进制文件，命令行运行即可。

```bash
mosdns start -c config_file -d working_dir​
```

mosdns 还附带一些常用小工具命令。

* probe 可以探测 TCP/TLS 服务器是否支持连接复用，pipeline 连接复用，空闲连接保持时间。
* config 可以生成 yaml 配置文件模板，转换配置文件格式。
* service 可以将 mosdns 安装成系统服务。

详见各个子命令的帮助。

```bash
mosdns -h
mosdns probe -h
```

### 安装至系统服务

mosdns service 内置一个简单的系统服务管理工具。可将 mosdns 安装成系统服务实现自启。需要管理员或 root 权限。理论上可用于 Windows XP+, Linux/(systemd | Upstart | SysV), 和 OSX/Launchd 平台。Windows，Ubuntu，Debian 实测可用。Openwrt 不可用。

注意: 此功能是 [kardianos/service](https://github.com/kardianos/service) 实现的，mosdns 不保证其可用性。

```bash
# 安装服务
mosdns service install -d 工作目录绝对路径 -c 配置文件路径
# 安装成功后手动运行服务。(服务仅设定为随系统自启，安装成功后并不会马上自动运行)
mosdns service start

# 卸载
mosdns service stop
mosdns service uninstall
```

## 更多工具

开放列表，排名不分前后。欢迎提交 issue 编辑本列表。

### Openwrt

用于 Openwrt 系统的 mosdns。自带 Luci 管理界面。

[sbwml / luci-app-mosdns](https://github.com/sbwml/luci-app-mosdns)

[QiuSimons/openwrt-mos](https://github.com/QiuSimons/openwrt-mos)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
