How to set DoH on Linux
This guide uses dnsproxy from AdguardTeam as the DoH client.
dnsproxy is a lightweight DNS proxy server that supports DNS-over-TLS, DNS-over-HTTPS, DNSCrypt, and DNS-over-QUIC protocols.
Install dnsproxy
Download and install the latest version:
VERSION=$(curl -s https://api.github.com/repos/AdguardTeam/dnsproxy/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest dnsproxy version is $VERSION"
wget -O dnsproxy.tar.gz "https://github.com/AdguardTeam/dnsproxy/releases/download/${VERSION}/dnsproxy-linux-amd64-${VERSION}.tar.gz"
tar -xzvf dnsproxy.tar.gz
cd linux-amd64
sudo mv dnsproxy /usr/bin/dnsproxyTest the Connection
Start dnsproxy with DNS.SB as the upstream server:
sudo dnsproxy -l 127.0.0.1 -p 53 -u https://doh.dns.sb/dns-query -b 185.222.222.222:53Open another terminal and test the DNS resolution:
dig example.com @127.0.0.1You should see a response similar to:
;; ANSWER SECTION:
example.com. 1094 IN A 93.184.216.34
;; SERVER: 127.0.0.1#53(127.0.0.1)The SERVER: 127.0.0.1#53 confirms that dnsproxy is working correctly.
Run dnsproxy as a Service
You can use either Supervisor or systemd to keep dnsproxy running in the background.
Option 1: Using Supervisor
Install Supervisor:
sudo apt install supervisor -yCreate the configuration file /etc/supervisor/conf.d/dnsproxy.conf:
[program:dnsproxy]
command = /usr/bin/dnsproxy -l 127.0.0.1 -p 53 -u https://doh.dns.sb/dns-query -b 185.222.222.222:53
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/dnsproxy.log
stderr_logfile = /var/log/supervisor/dnsproxy.error.log
environment = LANG="en_US.UTF-8"Restart Supervisor to apply the configuration:
sudo systemctl restart supervisorOption 2: Using systemd
Create the service file /etc/systemd/system/dnsproxy.service:
[Unit]
Description=DNS Proxy
After=network.target
Requires=network.target
[Service]
Type=simple
ExecStart=/usr/bin/dnsproxy -l 127.0.0.1 -p 53 -u https://doh.dns.sb/dns-query -b 185.222.222.222:53
Restart=on-failure
[Install]
WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now dnsproxyConfigure System DNS
Follow the same method as How to change DNS settings on Linux.
Edit /etc/resolv.conf:
sudo vim /etc/resolv.confReplace the nameserver lines with:
nameserver 127.0.0.1Save the file. Your system is now using DNS over HTTPS.