mcp-xray-pilot 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +502 -0
  3. package/data/docs/_index.json +533 -0
  4. package/data/docs/basic__api.md +148 -0
  5. package/data/docs/basic__dns.md +366 -0
  6. package/data/docs/basic__fakedns.md +202 -0
  7. package/data/docs/basic__geodata.md +64 -0
  8. package/data/docs/basic__inbound.md +159 -0
  9. package/data/docs/basic__index.md +136 -0
  10. package/data/docs/basic__log.md +67 -0
  11. package/data/docs/basic__metrics.md +262 -0
  12. package/data/docs/basic__observatory.md +115 -0
  13. package/data/docs/basic__outbound.md +164 -0
  14. package/data/docs/basic__policy.md +140 -0
  15. package/data/docs/basic__reverse.md +268 -0
  16. package/data/docs/basic__routing.md +474 -0
  17. package/data/docs/basic__stats.md +61 -0
  18. package/data/docs/basic__transport.md +1283 -0
  19. package/data/docs/features__features_browser_dialer.md +61 -0
  20. package/data/docs/features__features_env.md +66 -0
  21. package/data/docs/features__features_fallback.md +110 -0
  22. package/data/docs/features__features_index.md +17 -0
  23. package/data/docs/features__features_multiple.md +144 -0
  24. package/data/docs/features__features_xtls.md +13 -0
  25. package/data/docs/inbounds__inbounds_dokodemo.md +11 -0
  26. package/data/docs/inbounds__inbounds_http.md +80 -0
  27. package/data/docs/inbounds__inbounds_hysteria.md +60 -0
  28. package/data/docs/inbounds__inbounds_index.md +22 -0
  29. package/data/docs/inbounds__inbounds_shadowsocks.md +118 -0
  30. package/data/docs/inbounds__inbounds_socks.md +87 -0
  31. package/data/docs/inbounds__inbounds_trojan.md +78 -0
  32. package/data/docs/inbounds__inbounds_tun.md +47 -0
  33. package/data/docs/inbounds__inbounds_tunnel.md +86 -0
  34. package/data/docs/inbounds__inbounds_vless.md +135 -0
  35. package/data/docs/inbounds__inbounds_vmess.md +95 -0
  36. package/data/docs/inbounds__inbounds_wireguard.md +78 -0
  37. package/data/docs/outbounds__outbounds_blackhole.md +42 -0
  38. package/data/docs/outbounds__outbounds_dns.md +97 -0
  39. package/data/docs/outbounds__outbounds_freedom.md +170 -0
  40. package/data/docs/outbounds__outbounds_http.md +70 -0
  41. package/data/docs/outbounds__outbounds_hysteria.md +39 -0
  42. package/data/docs/outbounds__outbounds_index.md +24 -0
  43. package/data/docs/outbounds__outbounds_loopback.md +65 -0
  44. package/data/docs/outbounds__outbounds_shadowsocks.md +105 -0
  45. package/data/docs/outbounds__outbounds_socks.md +58 -0
  46. package/data/docs/outbounds__outbounds_trojan.md +49 -0
  47. package/data/docs/outbounds__outbounds_vless.md +122 -0
  48. package/data/docs/outbounds__outbounds_vmess.md +76 -0
  49. package/data/docs/outbounds__outbounds_wireguard.md +141 -0
  50. package/data/docs/transports__transports_grpc.md +137 -0
  51. package/data/docs/transports__transports_h2.md +11 -0
  52. package/data/docs/transports__transports_http.md +11 -0
  53. package/data/docs/transports__transports_httpupgrade.md +61 -0
  54. package/data/docs/transports__transports_hysteria.md +110 -0
  55. package/data/docs/transports__transports_index.md +19 -0
  56. package/data/docs/transports__transports_mkcp.md +125 -0
  57. package/data/docs/transports__transports_quic.md +11 -0
  58. package/data/docs/transports__transports_raw.md +156 -0
  59. package/data/docs/transports__transports_splithttp.md +11 -0
  60. package/data/docs/transports__transports_tcp.md +11 -0
  61. package/data/docs/transports__transports_websocket.md +75 -0
  62. package/data/docs/transports__transports_xhttp.md +11 -0
  63. package/dist/data/compatibility.js +170 -0
  64. package/dist/data/compatibility.js.map +1 -0
  65. package/dist/data/geocatalogue.js +191 -0
  66. package/dist/data/geocatalogue.js.map +1 -0
  67. package/dist/docs.js +339 -0
  68. package/dist/docs.js.map +1 -0
  69. package/dist/handlers.js +217 -0
  70. package/dist/handlers.js.map +1 -0
  71. package/dist/index.js +66 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/lint.js +737 -0
  74. package/dist/lint.js.map +1 -0
  75. package/dist/schemas/protocols/blackhole.js +16 -0
  76. package/dist/schemas/protocols/blackhole.js.map +1 -0
  77. package/dist/schemas/protocols/common.js +32 -0
  78. package/dist/schemas/protocols/common.js.map +1 -0
  79. package/dist/schemas/protocols/dns.js +14 -0
  80. package/dist/schemas/protocols/dns.js.map +1 -0
  81. package/dist/schemas/protocols/dokodemo.js +17 -0
  82. package/dist/schemas/protocols/dokodemo.js.map +1 -0
  83. package/dist/schemas/protocols/freedom.js +45 -0
  84. package/dist/schemas/protocols/freedom.js.map +1 -0
  85. package/dist/schemas/protocols/http.js +38 -0
  86. package/dist/schemas/protocols/http.js.map +1 -0
  87. package/dist/schemas/protocols/hysteria.js +51 -0
  88. package/dist/schemas/protocols/hysteria.js.map +1 -0
  89. package/dist/schemas/protocols/index.js +50 -0
  90. package/dist/schemas/protocols/index.js.map +1 -0
  91. package/dist/schemas/protocols/loopback.js +11 -0
  92. package/dist/schemas/protocols/loopback.js.map +1 -0
  93. package/dist/schemas/protocols/shadowsocks.js +60 -0
  94. package/dist/schemas/protocols/shadowsocks.js.map +1 -0
  95. package/dist/schemas/protocols/socks.js +42 -0
  96. package/dist/schemas/protocols/socks.js.map +1 -0
  97. package/dist/schemas/protocols/trojan.js +34 -0
  98. package/dist/schemas/protocols/trojan.js.map +1 -0
  99. package/dist/schemas/protocols/tun.js +19 -0
  100. package/dist/schemas/protocols/tun.js.map +1 -0
  101. package/dist/schemas/protocols/vless.js +44 -0
  102. package/dist/schemas/protocols/vless.js.map +1 -0
  103. package/dist/schemas/protocols/vmess.js +48 -0
  104. package/dist/schemas/protocols/vmess.js.map +1 -0
  105. package/dist/schemas/protocols/wireguard.js +34 -0
  106. package/dist/schemas/protocols/wireguard.js.map +1 -0
  107. package/dist/schemas/security/index.js +16 -0
  108. package/dist/schemas/security/index.js.map +1 -0
  109. package/dist/schemas/security/reality.js +35 -0
  110. package/dist/schemas/security/reality.js.map +1 -0
  111. package/dist/schemas/security/tls.js +46 -0
  112. package/dist/schemas/security/tls.js.map +1 -0
  113. package/dist/schemas/security/xtls.js +17 -0
  114. package/dist/schemas/security/xtls.js.map +1 -0
  115. package/dist/schemas/transports/grpc.js +18 -0
  116. package/dist/schemas/transports/grpc.js.map +1 -0
  117. package/dist/schemas/transports/httpupgrade.js +14 -0
  118. package/dist/schemas/transports/httpupgrade.js.map +1 -0
  119. package/dist/schemas/transports/hysteria.js +25 -0
  120. package/dist/schemas/transports/hysteria.js.map +1 -0
  121. package/dist/schemas/transports/index.js +32 -0
  122. package/dist/schemas/transports/index.js.map +1 -0
  123. package/dist/schemas/transports/mkcp.js +34 -0
  124. package/dist/schemas/transports/mkcp.js.map +1 -0
  125. package/dist/schemas/transports/raw.js +19 -0
  126. package/dist/schemas/transports/raw.js.map +1 -0
  127. package/dist/schemas/transports/websocket.js +15 -0
  128. package/dist/schemas/transports/websocket.js.map +1 -0
  129. package/dist/schemas/transports/xhttp.js +34 -0
  130. package/dist/schemas/transports/xhttp.js.map +1 -0
  131. package/dist/search.js +78 -0
  132. package/dist/search.js.map +1 -0
  133. package/dist/state.js +87 -0
  134. package/dist/state.js.map +1 -0
  135. package/dist/tools.js +274 -0
  136. package/dist/tools.js.map +1 -0
  137. package/dist/tools_impl/diff.js +55 -0
  138. package/dist/tools_impl/diff.js.map +1 -0
  139. package/dist/tools_impl/github.js +416 -0
  140. package/dist/tools_impl/github.js.map +1 -0
  141. package/dist/tools_impl/merge.js +181 -0
  142. package/dist/tools_impl/merge.js.map +1 -0
  143. package/dist/tools_impl/refresh.js +46 -0
  144. package/dist/tools_impl/refresh.js.map +1 -0
  145. package/dist/tools_impl/suggest.js +169 -0
  146. package/dist/tools_impl/suggest.js.map +1 -0
  147. package/dist/types.js +10 -0
  148. package/dist/types.js.map +1 -0
  149. package/dist/utils.js +81 -0
  150. package/dist/utils.js.map +1 -0
  151. package/dist/validate.js +408 -0
  152. package/dist/validate.js.map +1 -0
  153. package/package.json +62 -0
@@ -0,0 +1,148 @@
1
+ ---
2
+ url: https://xtls.github.io/en/config/api.html
3
+ source_url: https://raw.githubusercontent.com/XTLS/Xray-docs-next/main/docs/en/config/api.md
4
+ title: API Interface
5
+ category: basic
6
+ slug: api
7
+ fetched_at: 2026-05-04T18:42:38.451Z
8
+ ---
9
+ # API Interface
10
+
11
+ The API interface configuration provides [gRPC](https://grpc.io/)-based API interfaces for remote procedure calls.
12
+
13
+ You can enable the interface through the `api` configuration module. When the `api` configuration is enabled, Xray will automatically build an outbound proxy with the same name as the `tag`. You must manually route all API inbound connections to this outbound proxy via [Routing Configuration](./routing.md). Please refer to [Relevant Configuration](#relevant-configuration) in this section.
14
+
15
+ Since [v1.8.12](https://github.com/XTLS/Xray-core/releases/tag/v1.8.12), a simplified configuration mode is supported. You only need to configure the `ApiObject`, without needing to configure `inbounds` and `routing`. However, when using the simplified configuration, the traffic statistics feature does not count the traffic of API inbound connections.
16
+
17
+ ::: warning
18
+ Most users will not need this API; beginners can skip this section.
19
+ :::
20
+
21
+ ## ApiObject
22
+
23
+ `ApiObject` corresponds to the `api` field in the configuration file.
24
+
25
+ ```json
26
+ {
27
+ "api": {
28
+ "tag": "api",
29
+ "listen": "127.0.0.1:8080",
30
+ "services": [
31
+ "HandlerService",
32
+ "LoggerService",
33
+ "StatsService",
34
+ "RoutingService"
35
+ ]
36
+ }
37
+ }
38
+ ```
39
+
40
+ > `tag`: string
41
+
42
+ The identifier of the outbound proxy.
43
+
44
+ > `listen`: string
45
+
46
+ The IP and port for the API service to listen on. This is an optional configuration item.
47
+
48
+ If this item is omitted, you need to add `inbounds` and `routing` configurations according to the example in [Relevant Configuration](#relevant-configuration) below.
49
+
50
+ > `services`: \[string\]
51
+
52
+ The list of enabled APIs. See [API List](#supported-api-list) for available values.
53
+
54
+ ## Relevant Configuration
55
+
56
+ You can add an `api` inbound in the `inbounds` configuration:
57
+
58
+ ```json
59
+ "inbounds": [
60
+ {
61
+ "listen": "127.0.0.1",
62
+ "port": 10085,
63
+ "protocol": "dokodemo-door",
64
+ "settings": {
65
+ "address": "127.0.0.1"
66
+ },
67
+ "tag": "api"
68
+ }
69
+ ]
70
+ ```
71
+
72
+ Add a routing rule for the `api` inbound in the `routing` configuration:
73
+
74
+ ```json
75
+ "routing": {
76
+ "rules": [
77
+ {
78
+ "inboundTag": [
79
+ "api"
80
+ ],
81
+ "outboundTag": "api"
82
+ }
83
+ ]
84
+ }
85
+ ```
86
+
87
+ Add `api` in the basic configuration:
88
+
89
+ ```json
90
+ "api": {
91
+ "tag": "api",
92
+ "services": [
93
+ "StatsService"
94
+ ]
95
+ }
96
+ ```
97
+
98
+ ## Supported API List
99
+
100
+ ### HandlerService
101
+
102
+ APIs for modifying inbound and outbound proxies. Available functions are as follows:
103
+
104
+ - Add a new inbound;
105
+ - Add a new outbound;
106
+ - Remove an existing inbound;
107
+ - Remove an existing outbound;
108
+ - List outbounds;
109
+ - List inbounds;
110
+ - Add a user to an inbound (supports VMess, VLESS, Trojan, Shadowsocks only);
111
+ - Remove a user from an inbound (supports VMess, VLESS, Trojan, Shadowsocks only);
112
+
113
+ ### RoutingService
114
+
115
+ APIs for adding, removing, replacing routing rules, and querying balancer statistics. Available functions are as follows:
116
+
117
+ - `adrules`: Add or replace routing configuration
118
+ - `rmrules`: Remove routing rules
119
+ - `sib`: Disconnect connections from a source IP
120
+ - `bi`: Query balancer statistics
121
+ - `bo`: Force balancer to select a specific `outboundTag`
122
+
123
+ You can use commands like `./xray help api bi` to query specific usage.
124
+
125
+ ### LoggerService
126
+
127
+ Supports restarting the built-in Logger, which can be used with `logrotate` to perform operations on log files.
128
+
129
+ ### StatsService
130
+
131
+ Built-in data statistics service. See [Statistics](./stats.md) for details.
132
+
133
+ ### ReflectionService
134
+
135
+ Allows gRPC clients to retrieve the list of APIs on the server.
136
+
137
+ ```bash
138
+ $ grpcurl -plaintext localhost:10085 list
139
+ grpc.reflection.v1alpha.ServerReflection
140
+ v2ray.core.app.proxyman.command.HandlerService
141
+ v2ray.core.app.stats.command.StatsService
142
+ xray.app.proxyman.command.HandlerService
143
+ xray.app.stats.command.StatsService
144
+ ```
145
+
146
+ ## API Call Examples
147
+
148
+ [Xray-API-documents](https://github.com/XTLS/Xray-API-documents) @crossfw
@@ -0,0 +1,366 @@
1
+ ---
2
+ url: https://xtls.github.io/en/config/dns.html
3
+ source_url: https://raw.githubusercontent.com/XTLS/Xray-docs-next/main/docs/en/config/dns.md
4
+ title: Built-in DNS Server
5
+ category: basic
6
+ slug: dns
7
+ fetched_at: 2026-05-04T18:42:38.958Z
8
+ ---
9
+ # Built-in DNS Server
10
+
11
+ ## DNS Server
12
+
13
+ The built-in DNS module in Xray has three main purposes:
14
+
15
+ - **Routing Phase:** Resolves domain names to IPs and matches rules based on the resolved IPs for traffic splitting. Whether to resolve the domain and split traffic depends on the `domainStrategy` setting in the routing configuration module. The built-in DNS server is used for DNS queries only when the following two values are set:
16
+ - `"IPIfNonMatch"`: When a domain is requested, Xray attempts to match it against the `domain` rules in the routing configuration. If no match is found, the built-in DNS server is used to resolve the domain, and the returned IP address is used to match against IP routing rules.
17
+ - `"IPOnDemand"`: When any IP-based rule is encountered during matching, the domain is immediately resolved to an IP for matching.
18
+
19
+ - **Resolving Target Addresses for Connections:**
20
+ - For example, in a `freedom` outbound, if `domainStrategy` is set to `UseIP`, requests sent from this outbound will first resolve the domain to an IP using the built-in server before connecting.
21
+ - For example, in `sockopt`, if `domainStrategy` is set to `UseIP`, system connections initiated by this outbound will first resolve to an IP using the built-in server before connecting.
22
+
23
+ - **TUN/Transparent Proxy DNS Traffic Hijacking:** Combines routing with the DNS outbound to hijack DNS traffic into this module; or directly exposes port 53 to act as a recursive DNS server.
24
+
25
+ ::: tip TIP 1
26
+ The DNS server enters the routing system for matching by default unless it contains `+local`. When using domain names within it, be aware of potential routing loops; `hosts` may help.
27
+ :::
28
+
29
+ ::: tip TIP 2
30
+ Only basic IP queries (A and AAAA records) are supported. CNAME records will be queried repeatedly until an A/AAAA record is returned. Other queries will not enter the built-in DNS server; instead, they may be discarded or transparently forwarded to other servers depending on your outbound configuration.
31
+ :::
32
+
33
+ ## DNS Processing Flow
34
+
35
+ The domain first undergoes a Hosts mapping check (see the `hosts` field). If the required IP is not found, the DNS server is used for the query.
36
+
37
+ The core then begins to build a list of servers, sorting them according to the requested domain based on the following rules.
38
+
39
+ - Build List 1: Contains servers where the `domains` field successfully matches the requested domain, in the order they appear in the configuration file.
40
+ - Check `disableFallback`: If true, skip building List 2.
41
+ - Check `disableFallbackIfMatch`: If true and List 1 is not empty, skip building List 2.
42
+ - Build List 2: Contains servers not in List 1 where `skipFallback` is not true, in the order they appear in the configuration file.
43
+ - Final Server List = List 1 + List 2.
44
+
45
+ Note: Any DNS server with `FinalQuery` set to true will directly truncate the subsequent parts of the list.
46
+
47
+ When executing a DNS query, the core will query the servers in the Final Server List sequentially. It filters the results using `expectedIPs` and `unexpectedIPs`; if the result is empty after filtering, it attempts the next server in the list. (Behavior differs slightly when `enableParallelQuery` is true; see its field description for details.)
48
+
49
+ ## DnsObject
50
+
51
+ `DnsObject` corresponds to the `dns` field in the configuration file.
52
+
53
+ ```json
54
+ {
55
+ "dns": {
56
+ "hosts": {
57
+ "baidu.com": "127.0.0.1",
58
+ "dns.google": ["8.8.8.8", "8.8.4.4"]
59
+ },
60
+ "servers": [
61
+ "8.8.8.8",
62
+ "8.8.4.4",
63
+ {
64
+ "address": "1.2.3.4",
65
+ "port": 5353,
66
+ "domains": ["domain:xray.com"],
67
+ "expectedIPs": ["geoip:cn"],
68
+ "skipFallback": false,
69
+ "clientIP": "1.2.3.4"
70
+ },
71
+ {
72
+ "address": "https://8.8.8.8/dns-query",
73
+ "domains": ["geosite:netflix"],
74
+ "skipFallback": true,
75
+ "queryStrategy": "UseIPv4"
76
+ },
77
+ {
78
+ "address": "https://1.1.1.1/dns-query",
79
+ "domains": ["geosite:openai"],
80
+ "skipFallback": true,
81
+ "queryStrategy": "UseIPv6"
82
+ },
83
+ "localhost"
84
+ ],
85
+ "clientIp": "1.2.3.4",
86
+ "queryStrategy": "UseIP",
87
+ "disableCache": false,
88
+ "serveStale": false,
89
+ "serveExpiredTTL": 0,
90
+ "disableFallback": false,
91
+ "disableFallbackIfMatch": false,
92
+ "enableParallelQuery": false,
93
+ "useSystemHosts": false,
94
+ "tag": "dns_inbound"
95
+ }
96
+ }
97
+ ```
98
+
99
+ > `hosts`: map{string: address} | map{string: [address]}
100
+
101
+ A static IP mapping. The value consists of entries in the form `"domain": "address"` or `"domain": ["address 1", "address 2"]`. Each address may be an IP or a domain name. When resolving a domain, the core will check all mapping entries and return all matched IP addresses. If nothing matches, the DNS query phase is entered.
102
+
103
+ 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:
104
+
105
+ - If the mapping contains both IP addresses and domain names, the domain names are removed and only the IP addresses are returned.
106
+ - 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.
107
+ - 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.
108
+ - 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.
109
+
110
+ 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).
111
+
112
+ > `servers`: \[string | [DnsServerObject](#dnsserverobject) \]
113
+
114
+ A list of DNS servers. Two types are supported: DNS address (string format) and [DnsServerObject](#dnsserverobject).
115
+
116
+ When the value is `"localhost"`, it indicates using the local machine's preset DNS configuration.
117
+
118
+ When the value is a DNS `"IP:Port"` address, such as `"8.8.8.8:53"`, Xray will use the specified UDP port of this address for DNS queries. The query follows routing rules. If no port is specified, port 53 is used by default.
119
+
120
+ When the value is in the form of `"tcp://host:port"`, such as `"tcp://8.8.8.8:53"`, Xray will use `DNS over TCP` for queries. The query follows routing rules. If no port is specified, port 53 is used by default.
121
+
122
+ When the value is in the form of `"tcp+local://host:port"`, such as `"tcp+local://8.8.8.8:53"`, Xray will use `TCP Local Mode (TCPL)` for queries. This means the DNS request will **not** pass through the routing component but will request directly via the Freedom outbound to reduce latency. If no port is specified, port 53 is used by default.
123
+
124
+ When the value is in the form of `"https://host:port/dns-query"`, such as `"https://dns.google/dns-query"`, Xray will use `DNS over HTTPS` (RFC8484, abbreviated as DOH) for queries. Some providers have certificates for IP aliases, so you can write the IP directly, such as `https://1.1.1.1/dns-query`. Non-standard ports and paths can also be used, such as `"https://a.b.c.d:8443/my-dns-query"`.
125
+
126
+ When the value is in the form of `"h2c://host:port/dns-query"`, such as `"h2c://dns.google/dns-query"`, Xray will use the `DNS over HTTPS` request format but will send the request in cleartext h2c. This cannot be used directly; in this case, you need to configure a Freedom outbound + streamSettings with TLS to wrap it into a normal DOH request. This is used for special purposes, such as customizing the SNI of DOH requests or using utls fingerprints.
127
+
128
+ When the value is in the form of `"https+local://host:port/dns-query"`, such as `"https+local://dns.google/dns-query"`, Xray will use `DOH Local Mode (DOHL)` for queries. This means the DOH request will **not** pass through the routing component but will request directly via the Freedom outbound to reduce latency. Generally suitable for server-side use. Non-standard ports and paths can also be used.
129
+
130
+ When the value is in the form of `"quic+local://host"`, such as `"quic+local://dns.adguard.com"`, Xray will use `DNS over QUIC Local Mode (DOQL)` for queries. This means the DNS request will **not** pass through the routing component but will request directly via the Freedom outbound. This method requires the DNS server to support DNS over QUIC. By default, port 853 is used for queries, and non-standard ports can be used.
131
+
132
+ When the value is `fakedns`, the FakeDNS feature will be used for queries.
133
+
134
+ ::: tip TIP 1
135
+ When using `localhost`, the local machine's DNS requests are not controlled by Xray. Additional configuration is required to forward DNS requests through Xray.
136
+ :::
137
+
138
+ ::: tip TIP 2
139
+ The DNS clients initialized by different rules will be shown in the Xray startup logs at the `info` level, such as `local DOH`, `remote DOH`, and `udp` modes.
140
+ :::
141
+
142
+ ::: tip TIP 3
143
+ (v1.4.0+) You can enable DNS query logging in [Log](./log.md).
144
+ :::
145
+
146
+ > `clientIp`: string
147
+
148
+ The IP address used in the EDNS Client Subnet extension.
149
+
150
+ Must be a valid IPv4 or IPv6 address. When actually sent, the last few bits will be automatically masked; IPv4 and IPv6 are sent with /24 and /96 subnets respectively.
151
+
152
+ > `queryStrategy`: "UseIP" | "UseIPv4" | "UseIPv6" | "UseSystem"
153
+
154
+ Limits the capabilities of all servers in the DNS module and sets the default value for IP query types initiated by Xray itself.
155
+
156
+ The default value `UseIP` allows querying both A + AAAA records. When a query initiated by Xray itself does not specify an IP type, both A and AAAA records are queried from the upstream DNS server. `UseIPv4` only queries and allows querying A records; `UseIPv6` only queries and allows querying AAAA records.
157
+
158
+ `UseSystem` adapts to the operating system's network environment. Before querying, it checks whether there are IPv4 and IPv6 default gateways, thereby limiting the capabilities of all servers and setting the default query type. It checks in real-time on graphical OS environments and only once on command-line environments.
159
+
160
+ ```json
161
+ "dns": {
162
+ "servers": [
163
+ "https://1.1.1.1/dns-query",
164
+ {
165
+ "address": "https://8.8.8.8/dns-query",
166
+ "domains": [
167
+ "geosite:netflix"
168
+ ],
169
+ "skipFallback": true,
170
+ "queryStrategy": "UseIPv4" // netflix domain queries A record
171
+ },
172
+ {
173
+ "address": "https://1.1.1.1/dns-query",
174
+ "domains": [
175
+ "geosite:openai"
176
+ ],
177
+ "skipFallback": true,
178
+ "queryStrategy": "UseIPv6" // openai domain queries AAAA record
179
+ }
180
+ ],
181
+ "queryStrategy": "UseIP" // Globally query both A and AAAA records
182
+ }
183
+ ```
184
+
185
+ ::: tip TIP 1
186
+ The global `"queryStrategy"` value takes precedence. When the `"queryStrategy"` value in a sub-item conflicts with the global `"queryStrategy"` value, the query for that sub-item will return an empty response.
187
+ :::
188
+
189
+ ::: tip TIP 2
190
+ When the `"queryStrategy"` parameter is not written in a sub-item, the global `"queryStrategy"` parameter value is used. This behavior is the same as versions prior to Xray-core v1.8.6.
191
+ :::
192
+
193
+ For example:<br>
194
+ Global `"queryStrategy": "UseIPv6"` conflicts with sub-item `"queryStrategy": "UseIPv4"`.<br>
195
+ Global `"queryStrategy": "UseIPv4"` conflicts with sub-item `"queryStrategy": "UseIPv6"`.<br>
196
+ Global `"queryStrategy": "UseIP"` does not conflict with sub-item `"queryStrategy": "UseIPv6"`.<br>
197
+ Global `"queryStrategy": "UseIP"` does not conflict with sub-item `"queryStrategy": "UseIPv4"`.
198
+
199
+ ```json
200
+ "dns": {
201
+ "servers": [
202
+ "https://1.1.1.1/dns-query",
203
+ {
204
+ "address": "https://8.8.8.8/dns-query",
205
+ "domains": [
206
+ "geosite:netflix"
207
+ ],
208
+ "skipFallback": true,
209
+ "queryStrategy": "UseIPv6" // Global "UseIPv4" conflicts with sub-item "UseIPv6"
210
+ }
211
+ ],
212
+ "queryStrategy": "UseIPv4"
213
+ }
214
+ ```
215
+
216
+ The sub-item query for the Netflix domain returns an empty response due to the conflicting `"queryStrategy"` value. The Netflix domain is then queried by `https://1.1.1.1/dns-query`, returning an A record.
217
+
218
+ > `disableCache`: true | false
219
+
220
+ `true` disables DNS caching. Defaults to `false` (not disabled).
221
+
222
+ This does not affect `localhost` DNS (system DNS), which always follows Golang's DNS caching behavior (cgo and pure go may differ slightly).
223
+
224
+ > `serveStale`: true | false
225
+
226
+ `true` enables DNS optimistic caching. Defaults to `false` (not enabled).
227
+
228
+ Only effective when the server has DNS caching enabled (i.e., this option is constrained by `disableCache`).
229
+
230
+ > `serveExpiredTTL`: number
231
+
232
+ Validity period for optimistic caching in seconds. Defaults to 0, meaning it never expires.
233
+
234
+ If the server has caching enabled and optimistic caching is turned on: when the cache has expired but the optimistic cache has not, the stale DNS record in the cache is returned immediately, and the cache is refreshed in the background. This can reduce latency.
235
+
236
+ > `disableFallback`: true | false
237
+
238
+ `true` disables DNS fallback queries. Defaults to `false` (not disabled).
239
+
240
+ > `disableFallbackIfMatch`: true | false
241
+
242
+ `true` disables fallback queries when the DNS server's priority domain list is matched. Defaults to `false` (not disabled).
243
+
244
+ > `enableParallelQuery`: true | false
245
+
246
+ `true` enables parallel queries. Defaults to `false` (not enabled).
247
+
248
+ DNS failover is serial by default, meaning a query is sent to the next server only after the selected DNS server fails or `expectedIPs` and `unexpectedIPs` do not match.
249
+
250
+ When parallel query is enabled, queries are initiated asynchronously to all selected DNS servers in advance, executing a strategy of "dynamic grouping, intra-group racing, and inter-group fallback".
251
+
252
+ **Dynamic Grouping**: Adjacent servers in the selected server list are considered the same group if their `clientIP`, `skipFallback`, `queryStrategy`, `tag`, `domains`, `expectedIPs`, and `unexpectedIPs` are **exactly** the same.
253
+
254
+ **Intra-group Racing**: If any DNS server in the same group queries successfully and the IP matches `expectedIPs` and `unexpectedIPs`, the group is considered successful, and results from other servers in the group are ignored.
255
+
256
+ **Inter-group Fallback**: If the first group is still querying, wait. If the first group succeeds, return the IP. If all servers in the first group fail or IPs do not match, fallback to the next group. Finally, if all groups fail, return an empty resolution.
257
+
258
+ > `useSystemHosts`: true | false
259
+
260
+ If true, appends the system hosts file to the built-in DNS hosts.
261
+
262
+ > `tag`: string
263
+
264
+ For query traffic generated by the built-in DNS, except for `localhost`, `fakedns`, `TCPL`, `DOHL`, and `DOQL` modes, this tag can be used in routing for matching via `inboundTag`.
265
+
266
+ ### DnsServerObject
267
+
268
+ ```json
269
+ {
270
+ "address": "1.2.3.4",
271
+ "port": 5353,
272
+ "domains": ["domain:xray.com"],
273
+ "expectedIPs": ["geoip:cn"],
274
+ "unexpectedIPs": ["geoip:cloudflare"],
275
+ "skipFallback": false,
276
+ "finalQuery": false,
277
+ "tag": "dns-tag",
278
+ "clientIP": "1.2.3.4",
279
+ "queryStrategy": "UseIPv4",
280
+ "disableCache": false
281
+ }
282
+ ```
283
+
284
+ > `address`: address
285
+
286
+ A list of DNS servers. Two types are supported: DNS address (string format) and DnsServerObject.
287
+
288
+ When the value is `"localhost"`, it indicates using the local machine's preset DNS configuration.
289
+
290
+ When the value is a DNS `"IP"` address, such as `"8.8.8.8"`, Xray will use the specified UDP port of this address for DNS queries. The query follows routing rules. Defaults to port 53.
291
+
292
+ When the value is in the form of `"tcp://host"`, such as `"tcp://8.8.8.8"`, Xray will use `DNS over TCP` for queries. The query follows routing rules. Defaults to port 53.
293
+
294
+ When the value is in the form of `"tcp+local://host"`, such as `"tcp+local://8.8.8.8"`, Xray will use `TCP Local Mode (TCPL)` for queries. This means the DNS request will **not** pass through the routing component but will request directly via the Freedom outbound to reduce latency. If no port is specified, port 53 is used by default.
295
+
296
+ When the value is in the form of `"https://host:port/dns-query"`, such as `"https://dns.google/dns-query"`, Xray will use `DNS over HTTPS` (RFC8484, abbreviated as DOH) for queries. Some providers have certificates for IP aliases, so you can write the IP directly, such as `https://1.1.1.1/dns-query`. Non-standard ports and paths can also be used, such as `"https://a.b.c.d:8443/my-dns-query"`.
297
+
298
+ When the value is in the form of `"https+local://host:port/dns-query"`, such as `"https+local://dns.google/dns-query"`, Xray will use `DOH Local Mode (DOHL)` for queries. This means the DOH request will **not** pass through the routing component but will request directly via the Freedom outbound to reduce latency. Generally suitable for server-side use. Non-standard ports and paths can also be used.
299
+
300
+ When the value is in the form of `"quic+local://host:port"`, such as `"quic+local://dns.adguard.com"`, Xray will use `DOQ Local Mode (DOQL)` for queries. This means the DNS request will **not** pass through the routing component but will request directly via the Freedom outbound. This method requires the DNS server to support DNS over QUIC. By default, port 853 is used for queries, and non-standard ports can be used.
301
+
302
+ When the value is `fakedns`, the FakeDNS feature will be used for queries.
303
+
304
+ ::: tip About Local Mode and the Domain of the DNS Server Itself
305
+ There are two scenarios for DNS requests sent by the DNS module:
306
+
307
+ **Local Mode** connections are made directly outwards by the core. In this case, if the address is a domain name, it will be resolved by the system itself. The logic is relatively simple.
308
+
309
+ **Non-Local** modes will essentially be treated as requests coming from an inbound with the tag `dns.tag` (Don't know where it is? Ctrl+F in your browser to search for `inboundTag`). They will go through the normal core processing flow and may be assigned by the routing module to a local freedom or other remote outbounds. They will be resolved by the freedom's `domainStrategy` (beware of potential loops) or sent directly as domains to the remote end to be resolved according to the server's own resolution method.
310
+
311
+ Since it might be difficult for average users to clarify the logic involved, it is recommended (especially in a transparent proxy environment) to **directly set the corresponding IPs for servers with domain names in the host option of the DNS module** to prevent loops.
312
+
313
+ Incidentally, DNS requests sent by the DNS module in non-local modes will automatically skip the `IPIfNonMatch` and `IPOnDemand` resolution processes in the routing module. This prevents their resolution from being sent back to the DNS module, causing a loop.
314
+ :::
315
+
316
+ > `port`: number
317
+
318
+ DNS server port, e.g., `53`. Defaults to `53` if omitted. This item is invalid when using DOH, DOHL, or DOQL modes; non-standard ports should be specified in the URL.
319
+
320
+ > `domains`: \[string\]
321
+
322
+ A list of domains. Domains included in this list will prioritize using this server for queries. The domain format is the same as in [Routing Configuration](./routing.md#ruleobject).
323
+
324
+ > `expectedIPs`:\[string\]
325
+
326
+ A list of IP ranges. The format is the same as in [Routing Configuration](./routing.md#ruleobject).
327
+
328
+ When configured, Xray DNS will verify the returned IP and only return addresses included in the `expectedIPs` list.
329
+
330
+ If `*` exists in the list, and if no IP exists after filtering, the original IP is still returned so that the request does not fail.
331
+
332
+ > `unexpectedIPs`: [string]
333
+
334
+ The reverse version of `expectedIPs`. IPs included in this list are removed. The asterisk works the same way.
335
+
336
+ > `skipFallback`: true | false
337
+
338
+ `true`: Skip this server during DNS fallback queries. Defaults to `false` (not skipped).
339
+
340
+ > `timeoutMs`: number
341
+
342
+ DNS server timeout in milliseconds. Default is 4000 ms.
343
+
344
+ This does not affect `localhost` DNS (system DNS), which always follows Golang's DNS timeout behavior (cgo and pure go may differ slightly).
345
+
346
+ > `finalQuery`: true | false
347
+
348
+ If set to true, the request to this DNS server will be the final attempt and will not trigger fallback behavior.
349
+
350
+ > `queryStrategy`: "UseIP" | "UseIPv4" | "UseIPv6" | "UseSystem"
351
+
352
+ If not specified, it inherits from the global configuration; if specified, it allows further limiting the capabilities of this server and setting the default value for IP query types initiated by Xray itself.
353
+
354
+ Note: It is always constrained by the global `queryStrategy`.
355
+
356
+ ### The following configuration items, if not specified, will inherit from the global configuration, or can override the global configuration here
357
+
358
+ > `tag`: string
359
+
360
+ > `clientIP`: [string]
361
+
362
+ > `disableCache`: true | false
363
+
364
+ > `serveStale`: true | false
365
+
366
+ > `serveExpiredTTL`: number