6. DNS and hosts#
DNS is central to transparent proxying and TUN. Many cases where "rules do not take effect" are essentially because Link1 did not obtain the domain name.
Minimal DNS Configuration#
dns:
enable: true
listen: 127.0.0.1:1053
ipv6: false
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
nameserver:
- https://223.5.5.5/dns-query
- tls://223.5.5.5:853
Practical impact:
enable=trueenables the Link1 DNS resolver.
listenstarts a local DNS service for the system or router to forward queries to.
enhanced-mode=fake-ipimproves domain-rule hit rates in transparent proxy scenarios.
nameserveris the default upstream DNS.
DNS Server Syntax#
Link1 supports the following DNS upstream formats:
| Format | Protocol | Example | Description |
|---|---|---|---|
1.1.1.1 | UDP | 1.1.1.1 | Treated as UDP DNS when no scheme is specified |
udp://host:53 | UDP | udp://8.8.8.8:53 | Explicit UDP |
tcp://host:53 | TCP | tcp://8.8.8.8:53 | TCP DNS |
tls://host:853 | DoT | tls://1.1.1.1:853 | DNS over TLS |
quic://host:853 | DoQ | quic://dns.adguard-dns.com:853 | DNS over QUIC |
https://host/dns-query | DoH | https://dns.google/dns-query | DNS over HTTPS |
http://host/dns-query | HTTP DNS | http://127.0.0.1:8053/dns-query | Plaintext HTTP DNS |
system:// | System DNS | system:// | Use the system resolver |
dhcp://iface | DHCP DNS | dhcp://eth0 | Obtain DNS from DHCP on the specified interface |
rcode://name | Fixed RCode | rcode://refused | Used for testing or blocking |
openvpn://name | OpenVPN Dynamic DNS | openvpn://ovpn-node | Use DNS provided by the OpenVPN egress |
tailscale://name / ts://name | Tailscale MagicDNS | ts://tailnet | Use MagicDNS / tailnet DNS from the Tailscale egress |
DoH can specify HTTP/3 through a URL fragment:
nameserver:
- https://dns.google/dns-query#h3=true
You can also use a fragment to select a routing egress:
nameserver:
- https://dns.google/dns-query#PROXY
DNS Field Reference#
| Field | Meaning | Practical impact |
|---|---|---|
enable | Enables the DNS module | DNS/Fake-IP does not work when disabled |
prefer-h3 | Prefer HTTP/3 for DoH | Affects transport for https:// DNS upstreams |
listen | DNS service listen address | Used by the system, router, or TUN hijack for queries |
ipv6 | Whether DNS returns IPv6 records | Also limited by the top-level ipv6 setting |
ipv6-timeout | IPv6 query wait time, in milliseconds | Affects wait time during dual-stack resolution |
enhanced-mode | normal or fake-ip | Fake-IP mode improves domain-rule hits |
fake-ip-range | IPv4 Fake-IP pool | Default: 198.18.0.1/16 |
fake-ip-range6 | IPv6 Fake-IP pool | Used for IPv6 Fake-IP |
fake-ip-filter | Domains that do not receive Fake-IP addresses | Commonly used for LAN and connectivity-check domains |
fake-ip-filter-mode | Filter mode | Usually blacklist |
fake-ip-ttl | Fake-IP DNS TTL | Affects client cache duration |
cache-algorithm | DNS cache algorithm | Affects cache eviction strategy |
cache-max-size | DNS cache limit | Too small increases queries; too large uses more memory |
default-nameserver | DNS used to resolve upstream DNS domain names | Solves bootstrap for DoH/DoT upstream domains |
nameserver | Default DNS upstream | Used for normal domain resolution |
fallback | Backup DNS upstream | Used with fallback-filter |
fallback-filter | Conditions for using fallback | Evaluated by GeoIP/GeoSite/domain/ipcidr |
proxy-server-nameserver | DNS used to resolve proxy server domain names | Prevents proxy server domains from being affected by normal routing |
proxy-server-nameserver-policy | DNS routing policy for proxy servers | Specifies DNS separately for proxy server domains |
direct-nameserver | DNS for direct connections | Used for resolution on the direct path |
direct-nameserver-follow-policy | Whether direct DNS follows policy | Affects whether directly connected domains still use policy-based DNS routing |
respect-rules | Whether DNS respects routing rules | Lets DNS queries choose an egress closer to the final route |
use-hosts | Use hosts from the configuration | Enables static domain overrides |
use-system-hosts | Use the system hosts file | Enables /etc/hosts or platform hosts |
nameserver-policy | Specify DNS by domain/ruleset | Implements DNS routing |
Fake-IP#
How Fake-IP works:
The client queries api.example.com
-> Link1 returns 198.18.0.10
Client connection 198.18.0.10:443
-> Link1 reverse-maps 198.18.0.10 to api.example.com
-> Domain rules can match
Suitable for:
- TUN.
- Transparent proxying.
- Router gateway mode.
Not suitable for, or should be filtered for:
- Some LAN device connectivity-check domains.
- Service discovery that depends on real IPs.
- Internal domains.
Example:
dns:
enhanced-mode: fake-ip
fake-ip-filter:
- '*.lan'
- '+.local'
- 'dns.msftnsci.com'
nameserver-policy#
Specify different DNS upstreams by domain:
dns:
nameserver:
- https://dns.google/dns-query
nameserver-policy:
'+.corp.example.com':
- openvpn://corp-vpn
'+.tailnet.ts.net':
- ts://tailnet
'geosite:cn':
- https://223.5.5.5/dns-query
'rule-set:private':
- system://
Practical impact:
- Enterprise domains can use enterprise VPN DNS.
- Tailnet domains can use Tailscale MagicDNS;
tailscale://nameandts://nameare equivalent.
- Domestic domains can use domestic DNS.
- Specific rulesets can use dedicated DNS.
- Policy keys support comma-separated values, for example
geosite:cn,private.
fallback-filter#
dns:
fallback:
- https://1.1.1.1/dns-query
fallback-filter:
geoip: true
geoip-code: CN
geosite:
- geolocation-!cn
domain:
- '+.google.com'
ipcidr:
- 240.0.0.0/4
Meaning: when the default DNS returns an unexpected result, use the fallback result. A common use case is reducing the impact of DNS pollution.
Field impact:
| Field | Meaning |
|---|---|
geoip | Determines whether to use fallback based on GeoIP |
geoip-code | Expected country/region code |
geosite | Triggers fallback based on GeoSite category |
domain | Triggers fallback based on domain pattern |
ipcidr | Triggers fallback based on returned IP CIDR |
hosts#
Static hosts:
hosts:
router.lan: 192.168.9.1
api.local:
- 10.0.0.10
- 10.0.0.11
Practical impact:
- Takes precedence over upstream DNS.
- Suitable for internal services, test domains, and fixed mappings.
- If
dns.use-hosts=false,hostsin the configuration does not take effect.
hosts-providers#
Load hosts from an external file or URL:
hosts-providers:
intranet:
type: file
path: ./hosts/intranet.hosts
remote-hosts:
type: http
url: https://example.com/hosts.txt
path: ./hosts/remote.hosts
interval: 3600
proxy: DIRECT
Field impact:
| Field | Meaning |
|---|---|
type | file or http |
path | Local file or cache path |
url | HTTP download URL |
interval | Refresh interval, in seconds |
dialer-proxy / proxy | Egress used for download |
header | HTTP request headers |
size-limit | Download size limit |
Relationship Between DNS and Rules#
Domain rules depend on domain context, and IP rules depend on IP context. For TUN/transparent proxying, the following is recommended:
dns:
enable: true
enhanced-mode: fake-ip
tun:
enable: true
dns-hijack:
- any:53
sniffer:
enable: true
This lets the rule engine obtain both domain and IP information as much as possible.