mirror of
https://github.com/XTLS/Xray-docs-next.git
synced 2026-10-12 09:18:19 +03:00
Xray-core: Add Lua script for dns and routing
https://github.com/XTLS/Xray-core/pull/6823
This commit is contained in:
@@ -7,6 +7,7 @@ The built-in DNS module in Xray has three main purposes:
|
||||
- **Routing Phase:** Resolves domain names to IPs and matches rules based on the resolved IPs for traffic splitting.
|
||||
::: details Detailed explanation
|
||||
Whether a domain name is resolved for IP-based routing depends on `routing.domainStrategy`. The built-in DNS server may be used for DNS queries only with the following values:
|
||||
|
||||
- `"IPIfNonMatch"`: If no rule matches during the first routing pass, resolution occurs whenever the target includes a domain name and at least one rule contains an `ip` condition.
|
||||
- `"IPOnDemand"`: Resolution occurs when the target includes a domain name and a rule containing an `ip` condition is encountered.
|
||||
|
||||
@@ -14,6 +15,7 @@ The built-in DNS module in Xray has three main purposes:
|
||||
|
||||
- **Outbound Phase:** Resolves target domain names for connections or for sending to a remote proxy server.
|
||||
::: details Detailed explanation
|
||||
|
||||
- For example, setting `targetStrategy` to `UseIP` in a VLESS outbound resolves the target domain of the proxied request through the local built-in DNS module, then sends the resolved IP to the remote proxy server.
|
||||
- Setting `sockopt.domainStrategy` to `UseIP` in a VLESS outbound resolves the VLESS server's domain through the built-in DNS module, then connects to the resolved IP.
|
||||
- Setting `sockopt.domainStrategy` to `UseIP` in a Freedom outbound resolves the request's target domain through the built-in DNS module, then connects to the resolved IP.
|
||||
@@ -23,6 +25,7 @@ The built-in DNS module in Xray has three main purposes:
|
||||
|
||||
- **TUN/Transparent Proxy DNS Traffic Hijacking:** Combines routing with the DNS outbound to hijack DNS traffic into this module; or uses [Tunnel](./inbounds/tunnel.md) to expose port 53 and act as a recursive DNS server.
|
||||
::: details Detailed explanation
|
||||
|
||||
- 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,6 +34,8 @@ The built-in DNS module in Xray has three main purposes:
|
||||
|
||||
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.
|
||||
|
||||
If `script` is configured, subsequent DNS queries are handled by a [Lua script](../development/lua/guide/dns.md), and the built-in processing flow below is skipped.
|
||||
|
||||
The core then begins to build a list of servers, sorting them according to the requested domain based on the following rules.
|
||||
|
||||
- Build List 1: Contains servers where the `domains` field successfully matches the requested domain, in the order they appear in the configuration file.
|
||||
@@ -54,6 +59,7 @@ When executing a DNS query, the core will query the servers in the Final Server
|
||||
"baidu.com": "127.0.0.1",
|
||||
"dns.google": ["8.8.8.8", "8.8.4.4"]
|
||||
},
|
||||
"script": "",
|
||||
"servers": [
|
||||
"8.8.8.8",
|
||||
"8.8.4.4",
|
||||
@@ -107,6 +113,10 @@ The mapping target may be a domain name. When the core finishes matching and the
|
||||
|
||||
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).
|
||||
|
||||
> `script`: string
|
||||
|
||||
Path to a Lua script file; defaults to an empty string. When set, the Lua script takes over the built-in DNS processing flow. See the [DNS Scripts guide](../development/lua/guide/dns.md) for usage.
|
||||
|
||||
> `servers`: \[string | [DnsServerObject](#dnsserverobject) \]
|
||||
|
||||
A list of DNS servers. Two types are supported: DNS address (string format) and [DnsServerObject](#dnsserverobject).
|
||||
@@ -267,6 +277,7 @@ For query traffic generated by the built-in DNS, except for `localhost`, `fakedn
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "primary",
|
||||
"address": "1.2.3.4",
|
||||
"port": 5353,
|
||||
"domains": ["domain:xray.com"],
|
||||
@@ -281,6 +292,10 @@ For query traffic generated by the built-in DNS, except for `localhost`, `fakedn
|
||||
}
|
||||
```
|
||||
|
||||
> `id`: string
|
||||
|
||||
Server identifier; an empty string if omitted. Lua scripts use [`serverObj.ID`](../development/lua/reference/module-dns.md#id) to identify the upstream.
|
||||
|
||||
> `address`: address
|
||||
|
||||
A list of DNS servers. Two types are supported: DNS address (string format) and DnsServerObject.
|
||||
|
||||
@@ -15,6 +15,7 @@ For a more detailed analysis of the routing function: [Analysis of Routing (Part
|
||||
"routing": {
|
||||
"domainStrategy": "AsIs",
|
||||
"rules": [],
|
||||
"script": "",
|
||||
"balancers": []
|
||||
}
|
||||
}
|
||||
@@ -44,6 +45,10 @@ For each connection, routing will judge these rules from top to bottom. When the
|
||||
When no rule is matched, traffic is sent via the first outbound by default.
|
||||
:::
|
||||
|
||||
> `script`: string
|
||||
|
||||
Path to a Lua script file; defaults to an empty string. When set, the Lua script takes over outbound selection. See the [Routing Scripts guide](../development/lua/guide/routing.md) for usage.
|
||||
|
||||
> `balancers`: \[ [BalancerObject](#balancerobject) \]
|
||||
|
||||
An array, where each item is a load balancer configuration.
|
||||
|
||||
Reference in New Issue
Block a user