This site is not affiliated with or endorsed by Cloudflare, Inc. It simply showcases experiments built using Cloudflare services.
Cloudflare Experiments

URL DNS Lookup

Get DNS records for the hostname of any URL using Cloudflare's DNS over HTTPS

Retrieve all DNS record types for any URL's hostname using Cloudflare's DNS over HTTPS (DoH) API.

API Reference

GET /dns

Extracts the hostname from the provided URL and returns all available DNS records.

Prop

Type

Example Request

curl "https://your-worker.workers.dev/dns?url=https://www.cloudflare.com/page"

Success Response

hostname string

The extracted hostname that was looked up

records object

DNS records grouped by type. Only record types that exist for the hostname are included.

A array

IPv4 address records

AAAA array

IPv6 address records

CNAME array

Canonical name records

MX array

Mail exchange records

NS array

Name server records

TXT array

Text records

SOA array

Start of authority records

CAA array

Certification authority authorization records

Each DNS record contains:

name string

The domain name for this record

type string

The DNS record type (A, AAAA, CNAME, etc.)

ttl number

Time to live in seconds

data string

The record data (IP address, hostname, etc.)

{
  "hostname": "example.com",
  "records": {
    "A": [
      {
        "name": "example.com",
        "type": "A",
        "ttl": 1726,
        "data": "93.184.220.34"
      }
    ],
    "AAAA": [
      {
        "name": "example.com",
        "type": "AAAA",
        "ttl": 1726,
        "data": "2606:2800:220:1:248:1893:25c8:1946"
      }
    ],
    "NS": [
      {
        "name": "example.com",
        "type": "NS",
        "ttl": 172800,
        "data": "a.iana-servers.net."
      }
    ]
  }
}

Error Response

{
  "error": "Missing or invalid query parameter: url",
  "code": "INVALID_URL"
}

Error Codes

  • 400 - Missing or invalid url parameter (not http/https)
  • 502 - DNS lookup failed (DoH timeout or error)

Supported Record Types

The API queries for the following DNS record types:

  • A - IPv4 addresses
  • AAAA - IPv6 addresses
  • CNAME - Canonical names
  • MX - Mail exchange servers
  • NS - Name servers
  • TXT - Text records
  • SOA - Start of authority
  • CAA - Certificate authority authorization

Implementation Details

  • Uses Cloudflare's public DNS over HTTPS (DoH) API
  • Queries all record types in parallel for fast responses
  • Stateless - no database or KV storage required
  • Timeout protection on DoH requests

Use Cases

  • Resolve DNS records for the hostname extracted from any URL
  • Debug DNS configuration during deployments or migrations
  • Build diagnostic tools without running dig locally
  • Verify mail (MX), certificate (CAA), or CDN (CNAME) records from the edge

Limitations

  • Uses the hostname only; URL path and query string are ignored
  • Queries a fixed set of record types; no PTR or SRV in this experiment
  • DoH timeout if upstream DNS is slow or unreachable
  • Results reflect public DNS; may differ from resolver-specific or split-horizon views

Deployment

Deploy

Follow the deployment wizard to deploy the Worker to your Cloudflare account. No additional configuration or bindings required.

Test your deployment

curl "https://your-worker.workers.dev/dns?url=https://www.cloudflare.com"

Local Development

cd apps/experiments/url-dns-lookup
npm install
npm run dev

Test locally:

curl "http://localhost:8787/dns?url=https://www.cloudflare.com"

Cloudflare Features Used

On this page