Cloudflare Zero Trust DNS over HTTPS (DoH) Setup on Ubiquiti:UniFi
Configure Cloudflare Zero Trust DNS over HTTPS (DoH) on your Ubiquiti UniFi network for enhanced privacy and security. This guide walks through setting up encrypted DNS queries to protect your network traffic from eavesdropping.
Why DNS over HTTPS?
Encrypts DNS queries to prevent ISPs and network observers from seeing which websites you visit
Protects against man-in-the-middle attacks and DNS spoofing by encrypting the connection
Leverages Cloudflare's Zero Trust platform for advanced filtering and security policies
Automatically blocks malicious domains and phishing attempts before they reach your network
Prerequisites
- Cloudflare Zero Trust Account: Free tier available
- UniFi Network Application: Version 7.0 or later
- Admin Access: To your UniFi Controller
Setup Guide
- Log in to your Cloudflare Zero Trust dashboard
- Navigate to Gateway → DNS Locations
- Create a new DNS location or use the default
- Note down your DoH endpoint URL (format:
https://<subdomain>.cloudflare-gateway.com/dns-query)
Before configuring UniFi, set up your filtering policies:
- Navigate to Gateway → Firewall Policies
- Create DNS policies for content filtering
- Set up security threat categories to block
- Configure allowed/blocked domains
- Download the Cloudflare root certificate
- SSH into your UniFi device (UDM/UDM-Pro/USG)
- Upload and install the certificate to system trust store
- Verify certificate installation
- Open UniFi Network Application
- Navigate to Settings → Internet → WAN Networks
- Select your WAN connection
- Under DNS Server, choose "Manual"
- Enter Cloudflare Gateway IP addresses:
- Primary: Your Gateway DNS IPv4 address
- Secondary: Backup Gateway DNS IPv4 address
Configure the UniFi device to use DoH:
# SSH into UniFi device
ssh [email protected]
# Configure DNS over HTTPS
set service dns forwarding name-server <gateway-ip>
set service dns forwarding options server=/*/<gateway-ip>
commit
save- Test DNS resolution from a client device
- Check Cloudflare Zero Trust dashboard for query logs
- Verify encrypted DNS queries are appearing
- Test blocked domains to ensure filtering works
Testing Your Configuration
Visit dnsleaktest.com to verify your DNS queries are routing through Cloudflare
Run DNS Leak TestCheck your Cloudflare Zero Trust dashboard under Gateway → Analytics to see DNS queries in real-time
Troubleshooting
- Verify Cloudflare Gateway DNS IPs are correct
- Check certificate installation on UniFi device
- Ensure firewall rules allow outbound port 443
- Try flushing DNS cache on client devices
- Confirm DNS location is properly configured
- Check that source IP matches your network
- Allow up to 5 minutes for initial queries to appear
- Enable DNS caching on UniFi device
- Use Cloudflare's anycast network for lowest latency
- Consider setting up secondary DNS for redundancy