How to Configure DNS over HTTPS on Linux
This guide will help you set up and configure DNS over HTTPS (DoH) on your Linux system, covering multiple configuration methods and best practices.
Prerequisites
- Linux operating system
- Administrator (root) privileges
- Basic command-line knowledge
- Stable network connection
Using systemd-resolved
Step 1: Check systemd-resolved Version
systemctl --version
systemd-resolve --version
Ensure the version is 247 or higher, as these versions support DoH.
Step 2: Configure resolved.conf
Edit /etc/systemd/resolved.conf
:
[Resolve]
DNS=1.1.1.1 1.0.0.1
DNSOverTLS=yes
DNSSEC=yes
Cache=yes
DNSStubListener=yes
For DoH, add the following configuration:
[Resolve]
DNS=https://cloudflare-dns.com/dns-query
https://dns.google/dns-query
DNSOverTLS=no
DNSSEC=yes
Cache=yes
DNSStubListener=yes
Step 3: Restart Service
sudo systemctl restart systemd-resolved
sudo systemctl status systemd-resolved
Using NetworkManager
Step 1: Check NetworkManager Version
nmcli --version
Ensure the version supports DoH functionality.
Step 2: Configure Connection
Configure DoH using nmcli:
# List current connections
nmcli connection show
# Modify specified connection
sudo nmcli connection modify "Connection Name" ipv4.dns "1.1.1.1,1.0.0.1" ipv4.dns-over-tls yes
sudo nmcli connection modify "Connection Name" ipv6.dns "2606:4700:4700::1111,2606:4700:4700::1001" ipv6.dns-over-tls yes
Step 3: Apply Changes
sudo nmcli connection up "Connection Name"
Using Standalone Clients
dnscrypt-proxy
- Installation
# Debian/Ubuntu
sudo apt install dnscrypt-proxy
# Fedora
sudo dnf install dnscrypt-proxy
# Arch Linux
sudo pacman -S dnscrypt-proxy
- Configuration
Edit /etc/dnscrypt-proxy/dnscrypt-proxy.toml
:
server_names = ['cloudflare', 'google']
listen_addresses = ['127.0.0.1:53']
max_clients = 250
ipv4_servers = true
ipv6_servers = true
dnscrypt_servers = true
doh_servers = true
require_dnssec = true
require_nolog = true
require_nofilter = true
force_tcp = false
timeout = 2500
keepalive = 30
- Start Service
sudo systemctl enable dnscrypt-proxy
sudo systemctl start dnscrypt-proxy
sudo systemctl status dnscrypt-proxy
Stubby
- Installation
# Debian/Ubuntu
sudo apt install stubby
# Fedora
sudo dnf install stubby
# Arch Linux
sudo pacman -S stubby
- Configuration
Edit /etc/stubby/stubby.yml
:
resolution_type: GETDNS_RESOLUTION_STUB
dns_transport_list:
- GETDNS_TRANSPORT_TLS
tls_authentication: GETDNS_AUTHENTICATION_REQUIRED
tls_query_padding_blocksize: 128
edns_client_subnet_private: 1
round_robin_upstreams: 1
idle_timeout: 10000
listen_addresses:
- 127.0.0.1@53
- 0::1@53
upstream_recursive_servers:
- address_data: 1.1.1.1
tls_auth_name: "cloudflare-dns.com"
- address_data: 1.0.0.1
tls_auth_name: "cloudflare-dns.com"
- Start Service
sudo systemctl enable stubby
sudo systemctl start stubby
sudo systemctl status stubby
Verify Configuration
Method 1: Using dig
# Test DNS resolution
dig @127.0.0.1 example.com
# Check DNSSEC
dig @127.0.0.1 example.com +dnssec
# Verify DoH server
dig @127.0.0.1 whoami.cloudflare CH TXT
Method 2: Using resolvectl
# View current DNS settings
resolvectl status
# Test DNS resolution
resolvectl query example.com
# Check DNSSEC
resolvectl query --dnssec example.com
Method 3: Online Testing
- Visit DNS leak test website
- Run comprehensive test
- Verify DNS request routing
Troubleshooting
Common Issues
-
Resolution Failure
- Check network connection
- Verify configuration files
- Check service status
- Review system logs
-
Performance Issues
- Choose nearest server
- Optimize cache settings
- Monitor response time
- Check system resources
-
Compatibility Issues
- Update packages
- Check dependencies
- Verify system requirements
- Test alternative configurations
Log Analysis
- System Logs
# View systemd-resolved logs
journalctl -u systemd-resolved
# Check NetworkManager logs
journalctl -u NetworkManager
# View dnscrypt-proxy logs
journalctl -u dnscrypt-proxy
- Network Diagnostics
# Test network connectivity
ping 1.1.1.1
# Check DNS resolution
nslookup example.com
# Verify DNSSEC
dig example.com +dnssec
Best Practices
-
Provider Selection
- Evaluate privacy policies
- Check service availability
- Consider geographical location
- Test connection speed
-
Security Recommendations
- Use trusted providers
- Enable DNSSEC
- Regular system updates
- Monitor network activity
-
Performance Optimization
- Choose nearest servers
- Optimize cache settings
- Monitor performance metrics
- Regular maintenance
Enterprise Deployment
System-wide Configuration
-
Create Configuration Files
- Set up systemd-resolved
- Configure NetworkManager
- Deploy client software
-
Deployment Strategy
- Use configuration management
- Implement monitoring
- Plan maintenance windows
-
Maintenance Management
- Regular updates
- Performance monitoring
- Issue tracking
- Backup procedures
Next Steps
- Server List - Browse available DoH providers
- Security Guide - Learn more about security configuration
- Performance Optimization - Improve DNS performance
- FAQ - Get more help