I have some things I’d like to use a cloudflare worker for. They do DNS lookups for TXT records. And potentially will do other things like look up NS and MX records. I.e. more than the standard hostname->IP address
I’ve got this working by using DoH to 1.1.1.1 and requesting a JSON response in a fetch… but I feel there ought to be a better way to do it, in part because I see the worker limits as 6 requests simultaneously and 50 in total and while I doubt I’d hit the 50 limit I have hit the 6 simultaneous requests limit
First, am I missing a standard workers DNS library/functrion that can do this? The worker protocol page says I can use TCP sockets but not UDP so UDP DNS seems to be not supported. Is this correct?
Second if I use 1.1.1.1 and DoH is there are way to keep the request open and make multiple queries not just one at a time so that there’s only one request not 1-10
Currently, there isn’t a dedicated DNS library or function within Cloudflare Workers for performing DNS lookups. You are correct that UDP is not supported, so traditional DNS queries over UDP can’t be done within Workers.
For your second question, the DoH (DNS over HTTPS) requests to 1.1.1.1 are stateless, meaning you can’t keep the connection open to make multiple queries over a single request. Each DNS query will be a separate HTTPS request.
However, you can optimize your Worker by managing the concurrency of your fetch requests to stay within the limits. If you’re hitting the limit of 6 simultaneous connections, consider implementing a queue system within your Worker to handle DNS lookups sequentially or with controlled concurrency.
If you’re expecting high volumes of DNS queries, you might want to contact Cloudflare Sales to discuss your use case and any potential solutions they can offer.
Let us know what you think of the solution by logging in and give it a or .
Solutions help the person that asked the question and anyone else that sees the answer later. Login to tell us what you think of the solution with a or .