You Can Resolve Domains via curl Using DoH

Did you know you can use curl to get DNS information? Here's how:

$ curl -X GET "https://cloudflare-dns.com/dns-query?name=example.com&type=A" -H "Accept: application/dns-json"
{"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com","type":1}],"Answer":[{"name":"example.com","type":1,"TTL":276,"data":"23.192.228.84"},{"name":"example.com","type":1,"TTL":276,"data":"23.215.0.136"},{"name":"example.com","type":1,"TTL":276,"data":"23.192.228.80"},{"name":"example.com","type":1,"TTL":276,"data":"23.215.0.138"},{"name":"example.com","type":1,"TTL":276,"data":"96.7.128.175"},{"name":"example.com","type":1,"TTL":276,"data":"96.7.128.198"}]}%

It works on Cloudflare's ODOH server too!

$ curl -X GET "https://odoh.cloudflare-dns.com/dns-query?name=example.com&type=A" -H "Accept: application/dns-json"
{"Status":0,"TC":false,"RD":true,"RA":true,"AD":false,"CD":false,"Question":[{"name":"example.com","type":1}],"Answer":[{"name":"example.com","type":1,"TTL":35,"data":"23.192.228.84"},{"name":"example.com","type":1,"TTL":35,"data":"23.215.0.138"},{"name":"example.com","type":1,"TTL":35,"data":"23.215.0.136"},{"name":"example.com","type":1,"TTL":35,"data":"96.7.128.198"},{"name":"example.com","type":1,"TTL":35,"data":"96.7.128.175"},{"name":"example.com","type":1,"TTL":35,"data":"23.192.228.80"}]}%

If you can't bootstrap a DoH server, you can always use https://9.9.9.9/dns-query instead (though not in this format) or https://1.1.1.1/dns-query. If you already know the IP of your target, you can use curl's `–resolve` option too. curl has a `–doh-url` as well which can be used if you want curl to use DoH itself.

Note that although this method works for Cloudlare DoH servers, it is not part of any RFC so you can't really rely on them and should refer to the original RFC instead if you want to send your request to other servers.

Have thoughts or questions? I'd love to hear them:

Delta Chat
hossein@naghdbishi.com (pgp)

Want more articles like this one? Get notified of new posts by subscribing to the RSS feed or the email newsletter. I won't share your email or send spam, only blog posts.

Want more content now? This blog's archive has 50 ready-to-read articles. I also curate a list of cool URLs I find on the internet.

Found a mistake? This blog is open source, you can always open an issue.

Thanks for reading! ♡ All content on this blog is licensed under CC BY-SA 4.0, except where noted otherwise, or for third-party materials.