Skip to content

Transport Configuration

The library supports multiple transport protocols with advanced configuration options for different DNS query scenarios.

TCP Transport

TCP transport with custom timeouts and keep-alive settings:

ts
const client = new DnsClient({
  transport: {
    type: 'tcp',
    timeout: 5000,
    keepAlive: true,
    retries: 3
  }
})

TCP Options

OptionTypeDefaultDescription
timeoutnumber5000Connection timeout in milliseconds
keepAlivebooleanfalseEnable TCP keep-alive
retriesnumber3Number of retry attempts
portnumber53TCP port number

DNS-over-TLS (DoT)

Secure DNS queries over TLS with certificate validation:

ts
const tlsClient = new DnsClient({
  transport: {
    type: 'tls',
    serverName: 'dns.example.com',
    verify: true,
    port: 853
  }
})

TLS Options

OptionTypeDefaultDescription
serverNamestringRequiredServer hostname for certificate validation
verifybooleantrueEnable certificate verification
portnumber853TLS port number
timeoutnumber5000Connection timeout in milliseconds

DNS-over-HTTPS (DoH)

Modern HTTPS-based DNS transport with custom headers:

ts
const dohClient = new DnsClient({
  transport: {
    type: 'https',
    url: 'https://dns.example.com/dns-query',
    headers: {
      Accept: 'application/dns-json'
    }
  }
})

HTTPS Options

OptionTypeDefaultDescription
urlstringRequiredDoH endpoint URL
headersRecord<string, string>{}Custom HTTP headers
timeoutnumber5000Request timeout in milliseconds

Advanced Transport Features

Connection Pooling

For high-performance scenarios:

ts
const client = new DnsClient({
  transport: {
    type: 'tcp',
    poolSize: 5,
    poolTimeout: 30000,
    keepAlive: true
  }
})

Load Balancing

Using multiple DNS servers:

ts
const client = new DnsClient({
  transport: {
    type: 'tcp',
    servers: [
      { host: 'dns1.example.com', port: 53 },
      { host: 'dns2.example.com', port: 53 }
    ],
    strategy: 'round-robin' // or 'random', 'failover'
  }
})

Retry Strategy

Custom retry logic:

ts
const client = new DnsClient({
  transport: {
    type: 'tcp',
    retries: 3,
    retryStrategy: (attempt, error) => {
      // Exponential backoff with jitter
      const delay = Math.min(100 * 2 ** attempt, 2000)
      return delay + Math.random() * 100
    }
  }
})

Released under the MIT License.