Best practice to resolve DNS
Hey, i was wondering if there is a better way to resolve DNS to get an IP without using DNS over HTTP. Can anyone help?
4 Replies
Why not DNS over HTTPS? It's the easiest way to resolve DNS in a Worker
Yeah I know that it is simple, but just wanted to know if there are even more simpler methods
But thank you :)
Understandable, unfortunately there isn't. Besides the fetch api (which can do HTTPS) the best you have is TCP sockets but you would have to manually craft and send DNS over TCP packets which is not as widely supported as DNS over UDP is, and would be quite complex to do
You could do DNS over TLS with that support I suppose, but its still way more complex than DoH
It's not that hard to do DNS over TCP (https://github.com/Tyler-OBrien/Cloudflare-Worker-Dns-Over-Tcp/blob/50f745857cb3fa4d726a6b89d36c1c8a09fb5dc2/src/index.ts#L181C1-L181C39), thanks to generic libraries for parsing dns, and most Resolvers do support it. But TCP Connect Bans Cloudflare IPs including 1.1.1.1, so you'd have to use 8.8.8.8 or something else. I would wager CF's DoH would be faster and more reliable