Skip to main content
The library supports all common DNS record types. Each record type serves a specific purpose in the DNS system.

Supported record types

The DnsRecordType TypeScript type from /home/daytona/workspace/source/src/index.ts:6 defines all supported types:
type DnsRecordType = 'A' | 'NS' | 'CNAME' | 'SOA' | 'PTR' | 'MX' | 'TXT' | 
                     'SIG' | 'KEY' | 'AAAA' | 'SRV' | 'NAPTR' | 'DS' | 
                     'DNSKEY' | 'CAA'

Record type reference

A (Address Record)

Purpose: Maps a domain name to an IPv4 address. Example:
import { getDnsRecords } from '@layered/dns-records'

const aRecords = await getDnsRecords('example.com', 'A')
// Returns: [{ name: 'example.com', type: 'A', ttl: 3600, data: '93.184.216.34' }]
A records are the most common DNS record type and are used to point domain names to server IP addresses.

AAAA (IPv6 Address Record)

Purpose: Maps a domain name to an IPv6 address. Example:
const aaaaRecords = await getDnsRecords('example.com', 'AAAA')
// Returns: [{ name: 'example.com', type: 'AAAA', ttl: 3600, data: '2606:2800:220:1:248:1893:25c8:1946' }]

CNAME (Canonical Name Record)

Purpose: Creates an alias from one domain name to another. Example:
const cnameRecords = await getDnsRecords('www.example.com', 'CNAME')
// Returns: [{ name: 'www.example.com', type: 'CNAME', ttl: 3600, data: 'example.com' }]
CNAME records are commonly used to point subdomains like www to the main domain or to external services like CDNs.

MX (Mail Exchange Record)

Purpose: Specifies mail servers responsible for accepting email for a domain. Data format: priority hostname Example:
const mxRecords = await getDnsRecords('example.com', 'MX')
// Returns: [
//   { name: 'example.com', type: 'MX', ttl: 3600, data: '10 mail.example.com' },
//   { name: 'example.com', type: 'MX', ttl: 3600, data: '20 backup-mail.example.com' }
// ]
Lower priority numbers indicate higher priority. The mail server with priority 10 will be tried before priority 20.

TXT (Text Record)

Purpose: Stores arbitrary text data, commonly used for domain verification, SPF records, DKIM keys, and other metadata. Example:
const txtRecords = await getDnsRecords('example.com', 'TXT')
// Returns: [
//   { name: 'example.com', type: 'TXT', ttl: 3600, data: 'v=spf1 include:_spf.google.com ~all' },
//   { name: 'example.com', type: 'TXT', ttl: 3600, data: 'google-site-verification=...' }
// ]
TXT records are extensively used for email authentication (SPF, DKIM, DMARC) and domain ownership verification.

NS (Name Server Record)

Purpose: Delegates a DNS zone to use the specified authoritative name servers. Example:
const nsRecords = await getDnsRecords('example.com', 'NS')
// Returns: [
//   { name: 'example.com', type: 'NS', ttl: 3600, data: 'ns1.example.com' },
//   { name: 'example.com', type: 'NS', ttl: 3600, data: 'ns2.example.com' }
// ]

SOA (Start of Authority Record)

Purpose: Stores important information about a DNS zone including the primary name server, zone administrator email, and zone serial number. Data format: Contains multiple fields joined by spaces: primary NS, admin email, serial, refresh, retry, expire, minimum TTL. Example:
const soaRecords = await getDnsRecords('example.com', 'SOA')
// Returns: [{
//   name: 'example.com',
//   type: 'SOA',
//   ttl: 3600,
//   data: 'ns1.example.com admin.example.com 2024010101 7200 3600 1209600 3600'
// }]

CAA (Certification Authority Authorization)

Purpose: Specifies which certificate authorities (CAs) are allowed to issue SSL/TLS certificates for a domain. Data format: critical tag value Example:
const caaRecords = await getDnsRecords('example.com', 'CAA')
// Returns: [
//   { name: 'example.com', type: 'CAA', ttl: 3600, data: '0 issue "letsencrypt.org"' },
//   { name: 'example.com', type: 'CAA', ttl: 3600, data: '0 issuewild ";"' }
// ]
CAA records are important for security. They prevent unauthorized certificate authorities from issuing certificates for your domain.

PTR (Pointer Record)

Purpose: Maps an IP address to a domain name (reverse DNS lookup). Example:
const ptrRecords = await getDnsRecords('34.216.184.93.in-addr.arpa', 'PTR')

SRV (Service Record)

Purpose: Defines the location of servers for specified services. Data format: priority weight port target Example: Used for services like LDAP, XMPP, SIP, etc.

Advanced record types

The library also supports these advanced DNS record types:
  • SIG: Signature record for DNSSEC
  • KEY: Public key record for DNSSEC
  • NAPTR: Name Authority Pointer for URI mapping
  • DS: Delegation Signer for DNSSEC
  • DNSKEY: DNS public key for DNSSEC
These advanced types are primarily used for DNSSEC (DNS Security Extensions) and specialized services.

DNS record object structure

All DNS records returned by the library follow this structure:
interface DnsRecord {
  /** Fully qualified domain name (example.com, mail.google.com, analytics.x.com) */
  name: string
  /** Record type: A, AAAA, CNAME, MX, TXT, etc. */
  type: DnsRecordType
  /** Time to live (in seconds) for this record */
  ttl: number
  /** Record data: IP for A or AAAA, fqdn for CNAME, etc */
  data: string
}

Type number mapping

DNS over HTTPS resolvers return numeric type codes. The library automatically maps these to readable strings:
const dnsTypeNumbers = {
  1: 'A',
  2: 'NS',
  5: 'CNAME',
  6: 'SOA',
  12: 'PTR',
  15: 'MX',
  16: 'TXT',
  24: 'SIG',
  25: 'KEY',
  28: 'AAAA',
  33: 'SRV',
  35: 'NAPTR',
  43: 'DS',
  48: 'DNSKEY',
  257: 'CAA',
}
See /home/daytona/workspace/source/src/dns-resolvers.ts:3 for the implementation.

Build docs developers (and LLMs) love