Beginner
clideploy
Running DNS Queries
There are some cases when running DNS queries is useful. This is usually the case when one would like to use a DNS server not configured on the machine.
In the most basic basic case, we can query a domain's A record. This will give us a list of ipv4 addresses.
!--frsh-copybutton:1-->
const a = await Deno.resolveDns("example.com", "A");
console.log(a);
We can also query other record types. In this case we are querying an MX record which is related to email protocols. Deno supports querying A, AAAA, ANAME, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, and TXT records.
!--frsh-copybutton:2-->
const mx = await Deno.resolveDns("example.com", "MX");
console.log(mx);
We are also optionally able to specify a nameserver via an ip address and (optionally) a port number. To override the system configuration.
!--frsh-copybutton:3-->
const aaaa = await Deno.resolveDns("example.com", "AAAA", {
nameServer: { ipAddr: "8.8.8.8", port: 53 },
});
console.log(aaaa);
Run this example locally using the Deno CLI:
deno run --allow-net https://byexample-wwv03xf36j0g.deno.dev/dns-queries.ts
Additional resources: