lazydns

Domain Validator Plugin

The domain_validator plugin validates DNS query domain names for RFC compliance and filters invalid or malicious queries. It helps protect against DNS abuse, malformed queries, and can block specific domains using a blacklist.

Key features

Validation rules

The plugin validates domain names according to DNS standards:

Basic validation

Strict mode (default)

Lenient mode

Blacklist matching

The blacklist supports three matching modes:

  1. Exact match: "example.com" blocks only example.com
  2. Suffix match: "example.com" blocks example.com, sub.example.com, deep.sub.example.com, etc.
  3. Wildcard match: "*.blocked.org" blocks sub.blocked.org, any.blocked.org, etc., but not blocked.org itself

Behavior details

Configuration options

Example configuration

Basic usage (strict mode)

plugins:
  - tag: validator
    type: domain_validator
    config:
      strict_mode: true
      cache_size: 2000

With blacklist

plugins:
  - tag: validator
    type: domain_validator
    config:
      strict_mode: true
      cache_size: 1000
      blacklist:
        - "malicious.com"          # Blocks malicious.com and *.malicious.com
        - "tracking.example.com"   # Blocks tracking.example.com and sub-domains
        - "*.ads.com"              # Blocks *.ads.com but not ads.com itself
        - "phishing-site.org"

Lenient mode (for IDN support)

plugins:
  - tag: validator
    type: domain_validator
    config:
      strict_mode: false  # Allow consecutive hyphens for punycode domains
      cache_size: 1000

Typical pipeline placement

Place the domain_validator plugin very early in your pipeline (it has priority=2100 by default) to reject invalid queries before they reach expensive plugins like cache or forward:

plugins:
  - type: domain_validator
    tag: validator
    config:
      strict_mode: true
      cache_size: 1000
      blacklist:
        - "malware.example.com"
        - "*.ads.example.org"
  
  - type: cache
    tag: main_cache
    config:
      size: 2048
  
  - type: forward
    tag: upstream
    config:
      upstreams:
        - "8.8.8.8:53"

Metrics (when enabled)

When the metrics feature is enabled, the plugin exposes Prometheus metrics:

Use cases

1. Security filtering

Block known malicious domains and prevent DNS tunneling attacks by rejecting malformed names.

2. Compliance enforcement

Ensure all queries comply with DNS RFC standards before forwarding to upstream resolvers.

3. Ad/tracker blocking

Use the blacklist to block advertising and tracking domains without requiring external zone files.

4. Performance optimization

Cache validation results to reduce CPU overhead for frequently queried domains.

Troubleshooting

Legitimate domains are being rejected

Symptom: Valid domains like xn--example-something are rejected.

Solution: Set strict_mode: false to allow consecutive hyphens required for punycode/IDN domains.

config:
  strict_mode: false  # Allow IDN domains

High CPU usage

Symptom: CPU usage is high even with domain validation enabled.

Solution: Increase cache_size to cache more validation results:

config:
  cache_size: 5000  # Increase from default 1000

Blacklist not working

Symptom: Blacklisted domains are still being resolved.

Solution:

  1. Check that domain names are lowercase in the blacklist
  2. Verify the validator plugin runs before forward plugins
  3. Check logs for WARN messages about rejected domains
  4. Remember that *.example.com doesn’t block example.com itself (use both if needed)
config:
  blacklist:
    - "ads.example.com"   # Blocks ads.example.com and subdomains
    - "*.ads.example.com" # Redundant with suffix match above

Best practices

  1. Place early in pipeline: The validator should run before cache and forward plugins to reject queries as early as possible
  2. Use appropriate mode: Enable strict_mode: true for security-focused deployments, false for international domain support
  3. Size cache appropriately: Set cache_size based on your query volume (1000-5000 is typical)
  4. Monitor metrics: Track validation rejections to identify potential issues or attacks
  5. Keep blacklist manageable: Large blacklists can impact memory; consider using dedicated blocklist plugins for extensive filtering

Performance notes

Security considerations

Differences from similar plugins

Unlike ACL or domain set plugins, domain_validator focuses on structural validation rather than policy-based filtering. It ensures queries are well-formed before they reach other plugins.

Use domain_validator for RFC compliance and basic security, and acl/domain_set for policy-based allow/deny rules.