dnsproxy Documentation

repository·master·Indexed 25 days ago

https://github.com/adguardteam/dnsproxy

A versatile DNS proxy server supporting multiple protocols including DNS-over-TLS (DoT), DNS-over-HTTPS (DoH), DNSCrypt, and DNS-over-QUIC (DoQ). It can operate as both a client proxying to encrypted upstreams and a server providing encrypted DNS services. Key features include DNS64 synthesis, EDNS Client Subnet (ECS) support, domain-specific routing, caching, and rate limiting. Configuration is available via command-line flags or YAML files.

Tokens
5.7K
Snippets
9
Records
37
Agent score
76%

What's inside dnsproxy

  1. Run dnsproxy as an encrypted DNS server

    master

    To act as an encrypted server (e.g., providing DoH or DoT to clients), you must provide TLS certificates and specify the appropriate port using flags like --tls-port, --https-port, or --quic-port. Use -p 0 to disable plain DNS handling.

    Note for DNSCrypt: You must first obtain a configuration file (e.g., using the dnscrypt tool) and provide it via --dnscrypt-config.

  2. Specify upstreams for specific domains

    master

    Use dnsmasq-like syntax to route queries for specific domains to specific upstreams using the -u flag.

    Syntax: [/domain/]<upstreamString>

    • [/domain/]upstream: Routes queries for domain and its subdomains to upstream.
    • [/ *.domain/]upstream: The wildcard * matches any sub-domain, but not the domain itself.
    • [/]upstream: The empty domain // matches unqualified names (single label) or DS requests.
    • #: The special address # tells dnsproxy to use the common (default) servers.
    • Precedence: More specific domains take precedence over less specific ones.
  3. Run dnsproxy via CLI

    master
    The dnsproxy CLI is the primary entry point for the application. When executed, it parses configuration options, initializes logging, and starts the DNS proxy server. The application handles SIGINT and SIGTERM signals to perform a graceful shutdown of the proxy service.
  4. Run dnsproxy with command-line arguments

    master

    You can pass command-line arguments directly to the container to configure upstreams. In this example, the -u flag is used to specify Google DNS (8.8.8.8:53).

    docker run \
        --name dnsproxy_google_dns \
        -p 53:53/tcp \
        -p 53:53/udp \
        adguard/dnsproxy \
        -u 8.8.8.8:53
  5. Run dnsproxy with a configuration file

    master

    To use a custom configuration file, mount your local config.yaml into the container at /opt/dnsproxy/config.yaml using a volume mount.

    docker run \
        --name dnsproxy_google_dns \
        -p 53:53/tcp \
        -p 53:53/udp \
        -v $PWD/config.yaml:/opt/dnsproxy/config.yaml \
        adguard/dnsproxy
  6. Configure dnsproxy via YAML configuration file

    master
    dnsproxy can be configured using a YAML file. The configuration file allows you to define server settings, upstreams, caching behavior, and security options. When both a configuration file and command-line arguments are provided, command-line arguments take priority.
  7. Configure dnsproxy logging

    master

    The CLI supports basic logging configuration via the following options:

    • Log Output: You can specify a file path for logs. If provided, the application will create or append to the file with 0644 permissions. If not provided, logs are sent to os.Stdout.
    • Verbosity: Enabling the Verbose flag sets the log level to Debug. By default, the log level is Info.
  8. Configure DNS over HTTPS (DoH) and TLS

    master

    The proxy supports encrypted DNS via TLS and DoH.

    TLS Configuration:

    • Provide TLSCertPath and TLSKeyPath to enable TLS.
    • Specify TLSListenPorts to define which ports the TLS server should listen on.

    DoH Configuration:

    • HTTP3 enables HTTP/3 support.
    • DoHInsecureEnabled allows insecure DoH.
    • HTTPSUserinfo can be used to provide credentials in user:password format.
    • HTTPSListenPorts defines the ports for the DoH server.
    • QUICListenPorts defines the ports for QUIC-based DoH.
  9. Configure Cache Settings

    master

    The proxy supports DNS caching with the following configurable options:

    • Cache: Enables or disables the cache.
    • CacheSizeBytes: The maximum size of the cache in bytes.
    • CacheMinTTL: Minimum Time To Live for cached records.
    • CacheMaxTTL: Maximum Time To Live for cached records.
    • CacheOptimistic: Enables optimistic cache responses.
    • CacheOptimisticAnswerTTL: TTL for optimistic answers.
    • CacheOptimisticMaxAge: Maximum age for optimistic cache entries.