DNS: Correct Host behavior

This commit is contained in:
Fangliding
2026-08-31 15:35:40 +08:00
parent 090e425873
commit 5d4ddd2ac3
3 changed files with 6 additions and 3 deletions
+2 -1
View File
@@ -95,9 +95,10 @@ DNS 服务器默认进入路由系统进行匹配,除非其包含 `+local` 在
映射的目标可以是域名,当核心完成匹配,并且其中包含域名时行为会略有不同:
- 其中同时包含 IP 和域名时,删去其中的域名,只返回 IP 地址。
- 其中包含数个域名,存在歧义,查询失败,视为未命中,进入 DNS 查询阶段
- 其中包含数个域名,存在歧义,视为查询失败。
- 其中有且仅有一个域名时,这个域名将重新进入 Hosts 模块递归解析,重复上面的步骤,最大递归深度为 5。
- 上一条递归查询未查询到 IP,并且最终查询结果有且仅有一个域名,该域名替代原始请求域名,进入 DNS 查询阶段。
- 特别地,如果“域名”是井号后加数字的形式(如 `#3`),任何被该条目匹配到的请求,请求会立即失败。如果请求来自 DNS 出站,核心会返回空的响应以及该数字编号对应的 rcode 以拒绝请求。
其匹配格式(`domain:` `full:` 等等)同常用的 [路由系统](./routing.md#ruleobject) 中的 domain. 不同的是无前缀时此处默认使用 `full:` 前缀(类似常见的 hosts 文件写法)
+2 -1
View File
@@ -95,9 +95,10 @@ A static IP mapping. The value consists of entries in the form `"domain": "addre
The mapping target may be a domain name. When the core finishes matching and the mapping contains domain name(s), the behavior is slightly different:
- If the mapping contains both IP addresses and domain names, the domain names are removed and only the IP addresses are returned.
- If the mapping contains several domain names, the result is ambiguous: the match fails, is treated as a miss, and the DNS query phase is entered.
- If the mapping contains several domain names, the result is ambiguous: the query fails.
- If the mapping contains exactly one domain name, that domain will be fed back into the Hosts module for recursive resolution, repeating the above steps with a maximum recursion depth of 5.
- If the above recursive resolution yields no IPs, and the final resolution result contains exactly one domain name, that domain replaces the original requested domain and is sent to the DNS query phase.
- In particular, if the "domain" is in the form of a hash followed by a number (such as `#3`), any request matched by this entry will fail immediately. If the request comes from the DNS outbound, the core will return an empty response with the rcode corresponding to that number to reject the request.
The matching format (`domain:`, `full:`, etc.) is the same as the domain in the commonly used [Routing System](./routing.md#ruleobject). The difference is that without a prefix, it defaults to using the `full:` prefix (similar to the common hosts file syntax).
+2 -1
View File
@@ -95,9 +95,10 @@ DNS-сервер по умолчанию проходит сопоставлен
Целевое значение маппинга может быть доменом. Когда ядро завершает сопоставление и маппинг содержит доменное имя(а), поведение меняется следующим образом:
- Если маппинг содержит одновременно IP-адреса и доменные имена, доменные имена удаляются, и возвращаются только IP-адреса.
- Если маппинг содержит несколько доменных имен, возникает неоднозначность: сопоставление считается неудачным, рассматривается как пропуск, и выполняется этап DNS-запроса.
- Если маппинг содержит несколько доменных имен, возникает неоднозначность: запрос завершается неудачей.
- Если маппинг содержит ровно одно доменное имя, это доменное имя повторно передаётся в модуль Hosts для рекурсивного разрешения, повторяя описанные шаги; максимальная глубина рекурсии — 5.
- Если вышеописанная рекурсивная проверка не вернула IP, и итоговый результат содержит ровно одно доменное имя, это доменное имя заменяет исходный запрошенный домен и отправляется на этап DNS-запроса.
- В частности, если «домен» имеет формат знака решётки и следующего за ним числа (например, `#3`), любой запрос, совпавший с этой записью, немедленно завершается неудачей. Если запрос поступил от DNS outbound, ядро вернёт пустой ответ и соответствующий этому числу rcode, чтобы отклонить запрос.
Формат сопоставления (`domain:`, `full:` и т.д.) аналогичен `domain` в системе [маршрутизации](./routing.md#ruleobject). Отличие в том, что без префикса здесь по умолчанию используется `full:` (аналогично стандартному файлу hosts).