Skip to content


Repository files navigation


Client and server software to query DNS over HTTPS, using Google DNS-over-HTTPS protocol and IETF DNS-over-HTTPS (RFC 8484).



From Source

  • Install Go, at least version 1.20. The newer, the better.

Note for Debian/Ubuntu users: You need to set $GOROOT if you could not get your new version of Go selected by the Makefile.

  • First create an empty directory, used for $GOPATH:
mkdir ~/gopath
export GOPATH=~/gopath
  • To build the program, type:
  • To install DNS-over-HTTPS as Systemd services, type:
sudo make install
  • By default, Google DNS over HTTPS is used. It should work for most users (except for People's Republic of China). If you need to modify the default settings, type:
sudoedit /etc/dns-over-https/doh-client.conf
  • To automatically start DNS-over-HTTPS client as a system service, type:
sudo systemctl start doh-client.service
sudo systemctl enable doh-client.service
  • Then, modify your DNS settings (usually with NetworkManager) to

  • To test your configuration, type:



  • To uninstall, type:
sudo make uninstall

Note: The configuration files are kept at /etc/dns-over-https. Remove them manually if you want.

Using docker image

docker run -d --name doh-server \
  -p 8053:8053 \
  -e DOH_HTTP_PREFIX="/dns-query" \
  -e DOH_SERVER_LISTEN=":8053" \
  -e DOH_SERVER_VERBOSE="false" \

Feeling adventurous? Try the latest build:

  • m13253/dns-over-https-server:latest
  • m13253/dns-over-https-client:latest


All log lines (by either doh-client or doh-server) are written into stderr; you can view them using your OS tool of choice (journalctl when using systemd).

Server Configuration

The following is a typical DNS-over-HTTPS architecture:

+--------------+                                +------------------------+
| Application  |                                |  Recursive DNS Server  |
+-------+------+                                +-----------+------------+
        |                                                   |
+-------+------+                                +-----------+------------+
| Client side  |                                |      doh-server        |
| cache (nscd) |                                +-----------+------------+
+-------+------+                                            |
        |         +--------------------------+  +-----------+------------+
+-------+------+  |    HTTP cache server /   |  |   HTTP service muxer   |
|  doh-client  +--+ Content Delivery Network +--+ (Apache, Nginx, Caddy) |
+--------------+  +--------------------------+  +------------------------+

Although DNS-over-HTTPS can work alone, an HTTP service muxer would be useful as you can host DNS-over-HTTPS along with other HTTPS services.

HTTP/2 with at least TLS v1.3 is recommended. OCSP stapling must be enabled, otherwise DNS recursion may happen.

Configuration file

The main configuration file is doh-client.conf.

Server selectors. If several upstream servers are set, one is selected according to upstream_selector for each request. With upstream_selector = "random", a random upstream server will be chosen for each request.

# available selector: random (default) or weighted_round_robin or lvs_weighted_round_robin
upstream_selector = "random"

Example configuration: Apache

SSLProtocol TLSv1.2
SSLHonorCipherOrder On
SSLUseStapling on
SSLStaplingCache shmcb:/var/lib/apache2/stapling_cache(512000)

<VirtualHost *:443>
    ServerName MY_SERVER_NAME
    Protocols h2 http/1.1
    ProxyPass /dns-query http://[::1]:8053/dns-query
    ProxyPassReverse /dns-query http://[::1]:8053/dns-query

(Credit: Joan Moreau)

Example configuration: Nginx

server {
  listen       443 ssl http2 default_server;
  listen       [::]:443 ssl http2 default_server;
  server_name  MY_SERVER_NAME;

  server_tokens off;

  ssl_protocols TLSv1.2 TLSv1.3;          # TLS 1.3 requires nginx >= 1.20.0
  ssl_prefer_server_ciphers on;
  ssl_dhparam /etc/nginx/dhparam.pem;     # openssl dhparam -dsaparam -out /etc/nginx/dhparam.pem 4096
  ssl_ecdh_curve secp384r1;               # Requires nginx >= 1.1.0
  ssl_session_timeout  10m;
  ssl_session_cache shared:SSL:10m;
  ssl_session_tickets off;                # Requires nginx >= 1.5.9
  ssl_stapling on;                        # Requires nginx >= 1.3.7
  ssl_stapling_verify on;                 # Requires nginx => 1.3.7
  ssl_early_data off;                     # 0-RTT, enable if desired - Requires nginx >= 1.15.4
  resolver valid=300s;            # Replace with your local resolver
  resolver_timeout 5s;
  # HTTP Security Headers
  add_header X-Frame-Options DENY;
  add_header X-Content-Type-Options nosniff;
  add_header X-XSS-Protection "1; mode=block";
  add_header Strict-Transport-Security "max-age=63072000";
  ssl_certificate /path/to/your/server/certificates/fullchain.pem;
  ssl_certificate_key /path/to/your/server/certificates/privkey.pem;
  location /dns-query {
    proxy_pass       http://localhost:8053/dns-query;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;


Example configuration: Caddy (v2) {
        reverse_proxy * localhost:8053
        tls your@email.address
        try_files {path} {path}/index.php /index.php?{query}

Example configuration: Docker Compose + Traefik + Unbound (Raspberry Pi/Linux/Mac) [linux/amd64,linux/arm64,linux/arm/v7]

version: '2.2'

    # The official v2 Traefik docker image
    image: traefik:v2.3
    hostname: proxy
      - default
      TRAEFIK_API: "true"
      # DNS provider specific environment variables for DNS Challenge using route53 (AWS)
      # The HTTP port
      - "80:80"
      # The HTTPS port
      - "443:443"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
      #- "--log.level=DEBUG"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.letsencrypt.acme.dnschallenge=true"
      # Providers list:
      - "--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=route53"
      # Enable below line to use staging letsencrypt server.
      #- "--certificatesresolvers.letsencrypt.acme.caserver="
      - "${EMAIL}"
      - ""
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
      - ./data/proxy/certs:/certs
    image: satishweb/doh-server:latest
    hostname: doh-server
      - default
      # Enable below line to see more logs
      # DEBUG: "1"
      UPSTREAM_DNS_SERVER: "udp:unbound:53"
      DOH_SERVER_VERBOSE: "false"
      # - ./doh-server.conf:/server/doh-server.conf
      # - ./app-config:/app-config
      - unbound
      - "traefik.enable=true"
      - "traefik.http.routers.doh-server.rule=Host(`${SUBDOMAIN}.${DOMAIN}`) && Path(`${DOH_HTTP_PREFIX}`)"
      - "${DOH_SERVER_LISTEN}"
      - ""
      - "traefik.http.routers.doh-server.tls=true"
      - ""
      - ""
      - "traefik.http.routers.doh-server.tls.certresolver=letsencrypt"
      - "[0].main=${DOMAIN}"
      - "[0].sans=${SUBDOMAIN}.${DOMAIN}"
      # Protection from requests flood
      - ""
      - ""
      - ""
    image: satishweb/unbound:latest
    hostname: unbound
      - default
      # Disable these ports if DOH server is the only client
      - 53:53/tcp
      - 53:53/udp
      - ./unbound.sample.conf:/templates/unbound.sample.conf
      - ./data/unbound/custom:/etc/unbound/custom
      # Keep your custom.hosts file inside custom folder
    #  DEBUG: "1"

Complete Guide available at:

IPV6 Support for Docker Compose based configuration TBA

Example configuration: DNS-over-TLS

There is no native DNS-over-TLS support, but you can easily add it via nginx:

stream {
    server {
        listen                  *:853 ssl;
        proxy_pass              ipofyourdnsresolver:port  #

    ssl_certificate /etc/letsencrypt/live/site.yourdomain/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.yourdomain/privkey.pem;

The DoT service can also be provided by running a STunnel instance to wrap dnsmasq (or any other resolver of your choice, listening on a TCP port); this approach does not need a stand-alone daemon to provide the DoT service.


DNS-over-HTTPS is compatible with DNSSEC, and requests DNSSEC signatures by default. However, signature validation is not built-in. It is highly recommended that you install unbound or bind and pass results for them to validate DNS records. An instance of Pi Hole could also be used to validate DNS signatures as well as provide other capabilities.

EDNS0-Client-Subnet (GeoDNS)

DNS-over-HTTPS supports EDNS0-Client-Subnet protocol, which submits part of the client's IP address (/24 for IPv4, /56 for IPv6 by default) to the upstream server. This is useful for GeoDNS and CDNs to work, and is exactly the same configuration as most public DNS servers.

Keep in mind that /24 is not enough to track a single user, although it is precise enough to know the city where the user is located. If you think EDNS0-Client-Subnet is affecting your privacy, you can set no_ecs = true in /etc/dns-over-https/doh-client.conf, with the cost of slower video streaming or software downloading speed.

To ultilize ECS, X-Forwarded-For or X-Real-IP should be enabled on your HTTP service muxer. If your server is backed by unbound or bind, you probably want to configure it to enable the EDNS0-Client-Subnet feature as well.

Protocol compatibility

Google DNS-over-HTTPS Protocol

DNS-over-HTTPS uses a protocol compatible to Google DNS-over-HTTPS, except for absolute expire time is preferred to relative TTL value. Refer to json-dns/response.go for a complete description of the API.

IETF DNS-over-HTTPS Protocol

DNS-over-HTTPS uses a protocol compatible to IETF DNS-over-HTTPS (RFC 8484).

Supported features

Currently supported features are:

  • IPv4 / IPv6
  • EDNS0 large UDP packet (4 KiB by default)
  • EDNS0-Client-Subnet (/24 for IPv4, /56 for IPv6 by default)

Known issues

  • it does not work well with dnscrypt-proxy, you might want to use either (or fix the compatibility bugs by submitting PRs)

The name of the project

This project is named "DNS-over-HTTPS" because it was written before the IETF DoH project. Although this project is compatible with IETF DoH, the project is not affiliated with IETF.

To avoid confusion, you may also call this project "m13253/DNS-over-HTTPS" or anything you like.


DNS-over-HTTPS is licensed under the MIT License. You are encouraged to embed DNS-over-HTTPS into your other projects, as long as the license permits.

You are also encouraged to disclose your improvements to the public, so that others may benefit from your modification, in the same way you receive benefits from this project.