Public DNS Detector is a lightweight utility designed to identify the DNS servers used by clients visiting a website. It helps distinguish between major DNS providers (such as Cloudflare and Google) and other autonomous servers that directly emit resolution requests.
-
DNS Query: When a client's browser requests the object JSON from the URL
https://uuid.dnsdetector.zone.tld/dnsdetector, the script initiates a DNS query for the subdomainuuid.dnsdetector.zone.tld. -
Server Response:
- On port 53 (DNS), the program responds to A or AAAA queries for
uuid.dnsdetector.zone.tldwith the IPv4 or IPv6 address of the Public DNS Detector server. The Time-to-Live (TTL) for this response is set to 60 seconds. - Simultaneously, the program records the IP address of the DNS client that made the request.
- On port 53 (DNS), the program responds to A or AAAA queries for
-
JSON Object Retrieval:
- With the resolved IP address for
uuid.dnsdetector.zone.tld, the client's browser can retrieve the JSON object fromhttps://uuid.dnsdetector.zone.tld/dnsdetector. - The JSON object contains information about the DNS server used by the client, represented as:
{"server": "client DNS IP address"}.
- With the resolved IP address for
- Detects major DNS providers (e.g., Cloudflare, Google) vs. autonomous servers.
- Lightweight and efficient.
- Easy integration into web applications.
- Deploy the Public DNS Detector server (listening on ports 53 and 80 behind an HTTPS proxy).
- Configure the DNS record for
dnsdetector.zone.tldto point to your server's IP address. - Implement the client-side script to query
uuid.dnsdetector.zone.tldand retrieve the JSON object.
You can configure the Public DNS Detector server using command line arguments or environment variables. If both are provided, the environment variables will take precedence.
Here are the options you can set:
serverAddr: The default address for the DNS server. Set with-serverAddror theSERVER_ADDRenvironment variable.serverAddrIPv6: The default IPv6 address for the DNS server. Set with-serverAddrIPv6or theSERVER_ADDR_IPV6environment variable.ttl: The default TTL for the DNS records. Set with-ttlor theTTLenvironment variable.httpAddr: The default address for the HTTP server. Set with-httpAddror theHTTP_ADDRenvironment variable.httpPort: The default port for the HTTP server. Set with-httpPortor theHTTP_PORTenvironment variable.dnsAddr: The default address for the DNS server. Set with-dnsAddror theDNS_ADDRenvironment variable.dnsPort: The default port for the DNS server. Set with-dnsPortor theDNS_PORTenvironment variable.zone: The default zone for the DNS server. Set with-zoneor theZONEenvironment variable.templateLocation: The default location for the templates. Set with-templateLocationor theTEMPLATE_LOCATIONenvironment variable.maxRequestsPerSecond: The maximum number of requests per second. Set with-maxRequestsPerSecondor theMAX_REQUESTS_PER_SECONDenvironment variable.burstSize: The maximum number of requests in a burst. Set with-burstSizeor theBURST_SIZEenvironment variable. You can display the help message with the-helpcommand line argument.
For example, to start the server with a custom HTTP port and TTL, you could use:
./public-dnsdetector -httpPort 8080 -ttl 300- Clone this repository:
git clone https://github.com/eltorio/public-dnsdetector.git-
Set up your server environment (ensure ports 53 and 80 are accessible).
-
Customize the configuration as needed.
Our application exposes two metrics for monitoring:
publicdns_detector_unique_ips_total is a metric that counts the total number of unique IP addresses that have made requests to our application. This metric can be useful for monitoring the diversity of clients that are using our service.
publicdns_detector_requests_total is a metric that counts the total number of requests received by our application. This metric can be useful for monitoring the volume of traffic that our service is receiving.
These metrics are exposed at the /metrics endpoint of our application and are in a format compatible with Prometheus. Therefore, you can use them with any monitoring tool that supports Prometheus.
For example, to scrape these metrics with Prometheus, you can add the following to your Prometheus configuration:
scrape_configs:
- job_name: 'publicdns_dector'
static_configs:
- targets: ['<publicdns_detector_host>:<publicdns_detector_port>']Our application is available as a Docker image hosted at docker.io with the tag eltorio/publicdns-detector:latest.
To run the Docker image, you need to have Docker installed on your machine. Once Docker is installed, you can use the following command to run the image:
docker run -p 53:53/udp -p 80:80 eltorio/publicdns-detector:latestThis project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.
Feel free to modify and expand upon this template to provide additional details specific to your project. Good luck with your Public DNS Detector! 🚀