MCPcopy
hub / github.com/AdguardTeam/dnsproxy

github.com/AdguardTeam/dnsproxy @v0.82.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.82.1 ↗
748 symbols 2,959 edges 116 files 618 documented · 83%
README

DNS Proxy

Go Reference Go Report Card

A simple DNS proxy server that supports all existing DNS protocols including DNS-over-TLS, DNS-over-HTTPS, DNSCrypt, and DNS-over-QUIC. Moreover, it can work as a DNS-over-HTTPS, DNS-over-TLS or DNS-over-QUIC server.

How to install

There are several options how to install dnsproxy.

  1. Grab the binary for your device/OS from the Releases page.
  2. Use the official Docker image.
  3. Build it yourself (see the instruction below).

How to build

You will need Go 1.26 or later.

make build

Usage

Usage of ./dnsproxy:
  --bogus-nxdomain=subnet
        Transform the responses containing at least a single IP that matches specified addresses and CIDRs into NXDOMAIN.  Can be specified multiple times.
  --bootstrap/-b
        Bootstrap DNS for DoH and DoT, can be specified multiple times (default: use system-provided).
  --cache
        If specified, DNS cache is enabled.
  --cache-max-ttl=uint32
        Maximum TTL value for DNS entries, in seconds.
  --cache-min-ttl=uint32
        Minimum TTL value for DNS entries, in seconds. Capped at 3600. Artificially extending TTLs should only be done with careful consideration.
  --cache-optimistic
        If specified, optimistic DNS cache is enabled.
  --cache-size=int
        Cache size (in bytes). Default: 64k.
  --config-path=path
        YAML configuration file. Minimal working configuration in config.yaml.dist. Options passed through command line will override the ones from this file.
  --dnssec
        Defines whether the proxy should set the DO bits in the upstream requests.  Default: true.
  --doh-insecure-enabled
        If specified, the DoH server will skip TLS certificate verification.
  --doh-routes
        Routes for DNS-over-HTTPS.  If not specified, the default routes are registered:
        - "GET /", deprecated and will soon be removed,
        - "POST /", deprecated and will soon be removed.
        - "GET /dns-query",
        - "POST /dns-query".
  --dns64
        If specified, dnsproxy will act as a DNS64 server.
  --dns64-prefix=subnet
        Prefix used to handle DNS64. If not specified, dnsproxy uses the 'Well-Known Prefix' 64:ff9b::.  Can be specified multiple times.
  --dnscrypt-config=path/-g path
        Path to a file with DNSCrypt configuration. You can generate one using https://github.com/AdguardTeam/dnscrypt.
  --dnscrypt-port=port/-y port
        Listening ports for DNSCrypt.
  --edns
        Use EDNS Client Subnet extension.
  --edns-addr=address
        Send EDNS Client Address.
  --fallback/-f
        Fallback resolvers to use when regular ones are unavailable, can be specified multiple times. You can also specify path to a file with the list of servers.
  --help/-h
        Print this help message and quit.
  --hosts-file-enabled
        If specified, use hosts files for resolving.
  --hosts-files=path
        List of paths to the hosts files, can be specified multiple times.
  --http3
        Enable HTTP/3 support.
  --https-port=port/-s port
        Listening ports for DNS-over-HTTPS.
  --https-server-name=name
        Set the Server header for the responses from the HTTPS server.
  --https-userinfo=name
        If set, all DoH queries are required to have this basic authentication information.
  --insecure
        Disable secure TLS certificate validation.
  --ipv6-disabled
        If specified, all AAAA requests will be replied with NoError RCode and empty answer.
  --listen=address/-l address
        Listening addresses.
  --max-go-routines=uint
        Set the maximum number of go routines. A zero value will not not set a maximum.
  --optimistic-answer-ttl
        Default TTL value for expired DNS entries in optimistic cache.  Default: 30s
  --optimistic-max-age
        Period of time after which entries are removed from optimistic cache in human-readable form. Default: 12h.
  --output=path/-o path
        Path to the log file.
  --pending-requests-enabled
        If specified, the server will track duplicate queries and only send the first of them to the upstream server, propagating its result to others. Disabling it introduces a vulnerability to cache poisoning attacks.
  --port=port/-p port
        Listening ports. Zero value disables TCP and UDP listeners.
  --pprof
        If present, exposes pprof information on localhost:6060.
  --private-rdns-upstream
        Private DNS upstreams to use for reverse DNS lookups of private addresses, can be specified multiple times.
  --private-subnets=subnet
        Private subnets to use for reverse DNS lookups of private addresses.
  --quic-port=port/-q port
        Listening ports for DNS-over-QUIC.
  --ratelimit=int/-r int
        Ratelimit (requests per second).
  --ratelimit-subnet-len-ipv4=int
        Ratelimit subnet length for IPv4.
  --ratelimit-subnet-len-ipv6=int
        Ratelimit subnet length for IPv6.
  --refuse-any
        If specified, refuses ANY requests.
  --timeout=duration
        Timeout for outbound DNS queries to remote upstream servers in a human-readable form
  --tls-crt=path/-c path
        Path to a file with the certificate chain.
  --tls-key=path/-k path
        Path to a file with the private key.
  --tls-max-version=version
        Maximum TLS version, for example 1.3.
  --tls-min-version=version
        Minimum TLS version, for example 1.0.
  --tls-port=port/-t port
        Listening ports for DNS-over-TLS.
  --udp-buf-size=int
        Set the size of the UDP buffer in bytes. A value <= 0 will use the system default.
  --upstream/-u
        An upstream to be used (can be specified multiple times). You can also specify path to a file with the list of servers.
  --upstream-mode=mode
        Defines the upstreams logic mode, possible values: load_balance, parallel, fastest_addr (default: load_balance).
  --use-private-rdns
        If specified, use private upstreams for reverse DNS lookups of private addresses.
  --verbose/-v
        Verbose output.
  --version
        Prints the program version.

Examples

Simple options

Runs a DNS proxy on 0.0.0.0:53 with a single upstream - Google DNS.

./dnsproxy -u 8.8.8.8:53

The same proxy with verbose logging enabled writing it to the file log.txt.

./dnsproxy -u 8.8.8.8:53 -v -o log.txt

Runs a DNS proxy on 127.0.0.1:5353 with multiple upstreams.

./dnsproxy -l 127.0.0.1 -p 5353 -u 8.8.8.8:53 -u 1.1.1.1:53

Listen on multiple interfaces and ports:

./dnsproxy -l 127.0.0.1 -l 192.168.1.10 -p 5353 -p 5354 -u 1.1.1.1

The plain DNS upstream server may be specified in several ways:

  • With a plain IP address:

shell ./dnsproxy -l 127.0.0.1 -u 8.8.8.8:53

  • With a hostname or plain IP address and the udp:// scheme:

shell ./dnsproxy -l 127.0.0.1 -u udp://dns.google -u udp://1.1.1.1

  • With a hostname or plain IP address and the tcp:// scheme to force using TCP:

shell ./dnsproxy -l 127.0.0.1 -u tcp://dns.google -u tcp://1.1.1.1

Encrypted upstreams

DNS-over-TLS upstream:

./dnsproxy -u tls://dns.adguard.com

DNS-over-HTTPS upstream with specified bootstrap DNS:

./dnsproxy -u https://dns.adguard.com/dns-query -b 1.1.1.1:53

DNS-over-QUIC upstream:

./dnsproxy -u quic://dns.adguard.com

DNS-over-HTTPS upstream with enabled HTTP/3 support (chooses it if it's faster):

./dnsproxy -u https://dns.google/dns-query --http3

DNS-over-HTTPS upstream with forced HTTP/3 (no fallback to other protocol):

./dnsproxy -u h3://dns.google/dns-query

DNSCrypt upstream (DNS Stamp of AdGuard DNS):

./dnsproxy -u sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20

DNS-over-HTTPS upstream (DNS Stamp of Cloudflare DNS):

./dnsproxy -u sdns://AgcAAAAAAAAABzEuMC4wLjGgENk8mGSlIfMGXMOlIlCcKvq7AVgcrZxtjon911-ep0cg63Ul-I8NlFj4GplQGb_TTLiczclX57DvMV8Q-JdjgRgSZG5zLmNsb3VkZmxhcmUuY29tCi9kbnMtcXVlcnk

DNS-over-TLS upstream with two fallback servers (to be used when the main upstream is not available):

./dnsproxy -u tls://dns.adguard.com -f 8.8.8.8:53 -f 1.1.1.1:53

Encrypted DNS server

Runs a DNS-over-TLS proxy on 127.0.0.1:853.

./dnsproxy -l 127.0.0.1 --tls-port=853 --tls-crt=example.crt --tls-key=example.key -u 8.8.8.8:53 -p 0

Runs a DNS-over-HTTPS proxy on 127.0.0.1:443.

./dnsproxy -l 127.0.0.1 --https-port=443 --tls-crt=example.crt --tls-key=example.key -u 8.8.8.8:53 -p 0

Runs a DNS-over-HTTPS proxy on 127.0.0.1:443 with HTTP/3 support.

./dnsproxy -l 127.0.0.1 --https-port=443 --http3 --tls-crt=example.crt --tls-key=example.key -u 8.8.8.8:53 -p 0

Runs a DNS-over-QUIC proxy on 127.0.0.1:853.

./dnsproxy -l 127.0.0.1 --quic-port=853 --tls-crt=example.crt --tls-key=example.key -u 8.8.8.8:53 -p 0

Runs a DNSCrypt proxy on 127.0.0.1:443.

./dnsproxy -l 127.0.0.1 --dnscrypt-config=./dnscrypt-config.yaml --dnscrypt-port=443 --upstream=8.8.8.8:53 -p 0

[!TIP] In order to run a DNSCrypt proxy, you need to obtain DNSCrypt configuration first. You can use dnscrypt command-line tool to do that with a command like this ./dnscrypt generate --provider-name=2.dnscrypt-cert.example.org --out=dnscrypt-config.yaml.

Additional features

Runs a DNS proxy on 0.0.0.0:53 with rate limit set to 10 rps, enabled DNS cache, and that refuses type=ANY requests.

./dnsproxy -u 8.8.8.8:53 -r 10 --cache --refuse-any

Runs a DNS proxy on 127.0.0.1:5353 with multiple upstreams and enable parallel queries to all configured upstream servers.

./dnsproxy -l 127.0.0.1 -p 5353 -u 8.8.8.8:53 -u 1.1.1.1:53 -u tls://dns.adguard.com --upstream-mode parallel

Loads upstreams list from a file.

./dnsproxy -l 127.0.0.1 -p 5353 -u ./upstreams.txt

DNS64 server

dnsproxy is capable of working as a DNS64 server.

[!NOTE] What is DNS64/NAT64 This is a mechanism of providing IPv6 access to IPv4. Using a NAT64 gateway with IPv4-IPv6 translation capability lets IPv6-only clients connect to IPv4-only services via synthetic IPv6 addresses starting with a prefix that routes them to the NAT64 gateway. DNS64 is a DNS service that returns AAAA records with these synthetic IPv6 addresses for IPv4-only destinations (with A but not AAAA records in the DNS). This lets IPv6-only clients use NAT64 gateways without any other configuration. See also RFC 6147.

Enables DNS64 with the default Well-Known Prefix:

./dnsproxy -l 127.0.0.1 -p 5353 -u 8.8.8.8 --use-private-rdns --private-rdns-upstream=127.0.0.1 --dns64

You can also specify any number of custom DNS64 prefixes:

./dnsproxy -l 127.0.0.1 -p 5353 -u 8.8.8.8 --use-private-rdns --private-rdns-upstream=127.0.0.1 --dns64 --dns64-prefix=64:ffff:: --dns64-prefix=32:ffff::

Note that only the first specified prefix will be used for synthesis.

PTR queries for addresses within the specified ranges or the Well-Known one could only be answered with locally appropriate data, so dnsproxy will route those to the local upstream servers. Those should be specified and enabled if DNS64 is enabled.

Fastest addr + cache-min-ttl

This option would be useful to the users with problematic network connection. In this mode, dnsproxy would detect the fastest IP address among all that were returned, and it will return only it.

Additionally, for those with problematic network connection, it makes sense to override cache-min-ttl. In this case, dnsproxy will make sure that DNS responses are cached for at least the specified amount of time.

It makes sense to run it with multiple upstream servers only.

Run a DNS proxy with two upstreams, min-TTL set to 10 minutes, fastest address detection is enabled:

./dnsproxy -u 8.8.8.8 -u 1.1.1.1 --cache --cache-min-ttl=600 --upstream-mode=fastest_addr

who run dnsproxy with multiple upstreams

Specifying upstreams for domains

You can specify upstreams that will be used for a specific domain(s). We use the dnsmasq-like syntax, decorating domains with brackets (see --server [description][server-description]).

Syntax: [/[domain1][/../domainN]/]upstreamString

Where upstreamString is one or many upstreams separated by space (e.g. 1.1.1.1 or 1.1.1.1 2.2.2.2).

If one or more domains are specified, that upstream (upstreamString) is used only for those domains. Usually, it is used for private nameservers. For instance, if you have a nameser

Extension points exported contracts — how you extend this code

Upstream (Interface)
Upstream is an interface for a DNS resolver. All the methods must be safe for concurrent use. [11 implementers]
upstream/upstream.go
Resolver (Interface)
Resolver resolves the hostnames to IP addresses. Note, that [net.Resolver] from standard library also implements this i [5 …
internal/bootstrap/resolver.go
Handler (Interface)
Handler is an interface for handling DNS requests. [4 implementers]
proxy/requesthandler.go
Middleware (Interface)
Middleware is a common middleware interface. [2 implementers]
proxy/middleware.go
MessageConstructor (Interface)
MessageConstructor creates DNS messages. [2 implementers]
internal/dnsmsg/constructor.go
QUICTracer (Interface)
QUICTracer creates [qlogwriter.Trace] instances for QUIC connection tracing. [1 implementers]
upstream/upstream.go
DialHandler (FuncType)
DialHandler is a dial function for creating unencrypted network connections to the upstream server. It establishes the
internal/bootstrap/bootstrap.go
HandlerFunc (FuncType)
The HandlerFunc type is an adapter to allow the use of ordinary functions as [Handler]. If f is a function with the app
proxy/requesthandler.go

Core symbols most depended-on inside this repo

String
called by 90
internal/cmd/flag.go
Addr
called by 54
proxy/proxy.go
AddressToUpstream
called by 33
upstream/upstream.go
Exchange
called by 32
upstream/upstream.go
Error
called by 31
proxy/upstreams.go
Address
called by 28
upstream/upstream.go
Resolve
called by 26
proxy/proxy.go
Clone
called by 22
upstream/upstream.go

Shape

Function 337
Method 305
Struct 80
Interface 10
TypeAlias 10
FuncType 6

Languages

Go100%

Modules by API surface

proxy/proxy_internal_test.go33 symbols
upstream/upstream_internal_test.go29 symbols
proxy/cache.go28 symbols
upstream/doh.go25 symbols
proxy/proxy.go25 symbols
upstream/doq.go20 symbols
proxy/serverquic.go20 symbols
upstream/upstream.go19 symbols
proxy/upstreams.go19 symbols
proxy/cache_internal_test.go19 symbols
upstream/doq_internal_test.go17 symbols
internal/cmd/proxy.go17 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

cloud.google.com/gov0.123.0 · 1×
cloud.google.com/go/authv0.20.0 · 1×
cloud.google.com/go/compute/metadatav0.9.0 · 1×
github.com/AdguardTeam/dnscryptv0.0.1 · 1×
github.com/AdguardTeam/golibsv0.35.13 · 1×
github.com/BurntSushi/tomlv1.6.0 · 1×
github.com/ameshkov/dnsstampsv1.0.3 · 1×
github.com/anthropics/anthropic-sdk-gov1.50.2 · 1×
github.com/bahlo/generic-list-gov0.2.0 · 1×
github.com/beefsack/go-ratev0.0.0-2022021423340 · 1×
github.com/bluele/gcachev0.0.2 · 1×
github.com/bmatcuk/doublestar/v4v4.10.0 · 1×

For agents

$ claude mcp add dnsproxy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact