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.
const a = await Deno.resolveDns("", "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.
const mx = await Deno.resolveDns("", "MX");
We are also optionally able to specify a nameserver via an ip address and (optionally) a port number. To override the system configuration.
const aaaa = await Deno.resolveDns("", "AAAA", {
  nameServer: { ipAddr: "", port: 53 },

Run this example locally using the Deno CLI:

deno run --allow-net

Additional resources: