dae/docs/dns.md

110 lines
3.8 KiB
Markdown
Raw Normal View History

2023-02-25 01:38:21 +07:00
# DNS
2023-03-15 11:55:33 +07:00
dae will intercept all UDP traffic to port 53 and sniff DNS. Here gives some examples and templates for DNS configuration.
## Examples
2023-02-25 01:38:21 +07:00
```shell
dns {
upstream {
# Value can be scheme://host:port.
# Scheme list: tcp, udp, tcp+udp. Ongoing: https, tls, quic.
# If host is a domain and has both IPv4 and IPv6 record, dae will automatically choose
# IPv4 or IPv6 to use according to group policy (such as min latency policy).
# Please make sure DNS traffic will go through and be forwarded by dae, which is REQUIRED for domain routing.
# If dial_mode is "ip", the upstream DNS answer SHOULD NOT be polluted, so domestic public DNS is not recommended.
alidns: 'udp://dns.alidns.com:53'
googledns: 'tcp+udp://dns.google:53'
}
# The routing format of 'request' and 'response' is similar with section 'routing'.
2023-03-14 14:01:55 +07:00
# See https://github.com/daeuniverse/dae/blob/main/docs/routing.md
2023-03-17 03:41:46 +07:00
routing {
2023-03-27 11:45:10 +07:00
# According to the request of dns query, decide to use which DNS upstream.
# Match rules from top to bottom.
2023-03-17 03:41:46 +07:00
request {
# Built-in outbounds in 'request': asis, reject.
2023-03-17 03:41:46 +07:00
# You can also use user-defined upstreams.
2023-02-25 01:38:21 +07:00
2023-03-17 03:41:46 +07:00
# Available functions: qname, qtype.
2023-02-25 01:38:21 +07:00
2023-03-17 03:41:46 +07:00
# DNS request name (omit suffix dot '.').
qname(geosite:category-ads-all) -> reject
2023-03-17 03:41:46 +07:00
qname(suffix: abc.com, keyword: google) -> googledns
qname(full: ok.com, regex: '^yes') -> googledns
# DNS request type
qtype(a, aaaa) -> alidns
qtype(cname) -> googledns
2023-02-25 01:38:21 +07:00
2023-03-17 03:41:46 +07:00
# If no match, fallback to this upstream.
fallback: asis
}
2023-03-27 11:45:10 +07:00
# According to the response of dns query, decide to accept or re-lookup using another DNS upstream.
# Match rules from top to bottom.
2023-03-17 03:41:46 +07:00
response {
# Built-in outbounds in 'response': accept, reject.
2023-03-17 03:41:46 +07:00
# You can use user-defined upstreams.
2023-02-25 01:38:21 +07:00
2023-03-17 03:41:46 +07:00
# Available functions: qname, qtype, upstream, ip.
# Accept the response if the request is sent to upstream 'googledns'. This is useful to avoid loop.
upstream(googledns) -> accept
# If DNS request name is not in CN and response answers include private IP, which is most likely polluted
# in China mainland. Therefore, resend DNS request to 'googledns' to get correct result.
!qname(geosite:cn) && ip(geoip:private) -> googledns
fallback: accept
}
2023-02-25 01:38:21 +07:00
}
2023-03-17 03:41:46 +07:00
2023-02-25 01:38:21 +07:00
}
```
2023-03-15 11:55:33 +07:00
## Templates
```shell
# Use alidns for China mainland domains and googledns for others.
2023-03-15 11:55:33 +07:00
dns {
upstream {
googledns: 'tcp+udp://dns.google:53'
alidns: 'udp://dns.alidns.com:53'
}
2023-03-16 23:43:24 +07:00
routing {
2023-03-27 11:45:10 +07:00
# According to the request of dns query, decide to use which DNS upstream.
# Match rules from top to bottom.
2023-03-16 23:43:24 +07:00
request {
2023-03-27 11:45:10 +07:00
# Lookup China mainland domains using alidns, otherwise googledns.
2023-03-16 23:43:24 +07:00
qname(geosite:cn) -> alidns
2023-03-27 11:45:10 +07:00
# fallback is also called default.
2023-03-16 23:43:24 +07:00
fallback: googledns
}
2023-03-15 11:55:33 +07:00
}
}
```
```shell
# Use alidns for all DNS queries and fallback to googledns if pollution result detected.
2023-03-15 11:55:33 +07:00
dns {
upstream {
googledns: 'tcp+udp://dns.google:53'
alidns: 'udp://dns.alidns.com:53'
}
2023-03-16 23:43:24 +07:00
routing {
2023-03-27 11:45:10 +07:00
# According to the request of dns query, decide to use which DNS upstream.
# Match rules from top to bottom.
2023-03-16 23:43:24 +07:00
request {
2023-03-27 11:45:10 +07:00
# fallback is also called default.
2023-03-16 23:43:24 +07:00
fallback: alidns
}
2023-03-27 11:45:10 +07:00
# According to the response of dns query, decide to accept or re-lookup using another DNS upstream.
# Match rules from top to bottom.
2023-03-16 23:43:24 +07:00
response {
2023-03-27 11:45:10 +07:00
# Trusted upstream. Always accept its result.
2023-03-16 23:43:24 +07:00
upstream(googledns) -> accept
2023-03-27 11:45:10 +07:00
# Possibly polluted, re-lookup using googledns.
2023-03-16 23:43:24 +07:00
!qname(geosite:cn) && ip(geoip:private) -> googledns
2023-03-27 11:45:10 +07:00
# fallback is also called default.
2023-03-16 23:43:24 +07:00
fallback: accept
}
2023-03-15 11:55:33 +07:00
}
}
```