A fast and secure DoH (DNS-over-HTTPS) server written in Rust.
This requires the rust compiler to be installed.
Without built-in support for HTTPS:
sh
cargo install doh-proxy
With built-in support for HTTPS (requires openssl-dev):
sh
cargo install doh-proxy
```text USAGE: doh-proxy [FLAGS] [OPTIONS]
FLAGS: -K, --disable-keepalive Disable keepalive -P, --disable-post Disable POST queries -h, --help Prints help information -V, --version Prints version information
OPTIONS:
-E, --err-ttl
-i, --tls-cert-path <tls_cert_path> Path to a PEM-encoded identity (only required for built-in TLS)
```
The recommended way to use doh-proxy is to use a TLS termination proxy (such as hitch or relayd), a CDN or a web server with proxying abilities as a front-end.
That way, the DoH service can be exposed as a virtual host, sharing the same IP addresses as existing websites.
If doh-proxy and the HTTP/2 front-end run on the same host, using the HTTP protocol to communicate between both is fine.
If both are on distinct networks, such as when using a CDN, doh-proxy can handle HTTPS requests, provided that it was compiled with the tls feature.
The certificates and private keys must be encoded in PEM format. They can be stored in the same file.
In order to enable built-in HTTPS support, add the --tls-cert-path option to specify the location of the certificates file, as well as the private keys file using --tls-cert-key-path.
Once HTTPS is enabled, HTTP connections will not be accepted.
A sample self-signed certificate localhost.pem can be used for testing.
The file also includes the private key.
DNSCrypt is an alternative encrypted DNS protocol that is faster and more lightweight than DoH.
Both DNSCrypt and DoH connections can be accepted on the same TCP port using Encrypted DNS Server.
Encrypted DNS Server forwards DoH queries to Nginx or rust-doh when a TLS connection is detected, or directly responds to DNSCrypt queries.
It also provides DNS caching, server-side filtering, metrics, and TCP connection reuse in order to mitigate exhaustion attacks.
Unless the front-end is a CDN, an ideal setup is to use rust-doh behind Encrypted DNS Server.
encrypted-dns-serverAdd the following section to the configuration file:
toml
[tls]
upstream_addr = "127.0.0.1:3000"
nginxIn an existing server, a /doh endpoint can be exposed that way:
text
location /doh {
proxy_pass http://127.0.0.1:3000;
}
This example assumes that the DoH proxy is listening locally to port 3000.
HTTP caching can be added (see the proxy_cache_path and proxy_cache directives in the Nginx documentation), but be aware that a DoH server will quickly create a gigantic amount of files.
Use the online DNS stamp calculator to compute the stamp for your server, and the dnscrypt-proxy -show-certs command to print the TLS certificate signatures to be added it.
doh-proxy can be used with dnscrypt-proxy
as a client.
doh-proxy is currently being used by the doh.crypto.sx public DNS resolver.
An extensive list of public DoH servers can be found here: public encrypted DNS servers.