DnsClient.NET is a free, open source networking & connectivity project written in C# and released under Apache-2.0. It has 880 GitHub stars, 149 forks and 21 open issues, and was last pushed 7 months ago. On this registry it ranks #47 of 49 tracked projects in Networking & Connectivity, with 5 head-to-head comparisons available.

What is DnsClient.NET?

DnsClient.NET is a high-performance open-source DNS lookup library for .NET developers who need to query DNS records programmatically from C# applications.

What it is

DnsClient.NET is a C# library, published on NuGet as the DnsClient package and licensed under Apache-2.0, that lets applications perform DNS lookups directly rather than shelling out to external tools. It provides both a synchronous and an asynchronous API centered on the LookupClient class, which can be instantiated with no arguments to pick up the local system's configuration, or configured with explicit nameservers, caching behaviour, and error handling. The project lives in the .NET and .NET Core ecosystem and is built from source with the latest .NET SDKs and Visual Studio 2022.

The concrete problem it solves is that .NET provides no convenient, complete way to issue DNS queries and read resource records without resorting to platform-specific calls or parsing the output of a command-line resolver. DnsClient.NET replaces that by speaking the DNS protocols directly, handling UDP lookups with automatic TCP fallback when a response is truncated (enabled by default), configurable EDNS support to adjust the default UDP buffer size and request security-relevant records, and both query-result caching based on record TTL and caching that can be disabled entirely.

Key capabilities

  • Queries over UDP with configurable TCP fallback when the UDP result is truncated, plus EDNS support for adjusting the default UDP buffer size.
  • A TTL-based query result cache with configurable minimum TTL, maximum TTL, and the option to disable caching altogether.
  • Automatic nameserver discovery from local system configuration, including DNS servers set on network interfaces and Windows-specific NRPT policies, alongside explicit multi-endpoint configuration used in random or sequential order with retries.
  • Support for a wide range of resource records: A, AAAA, NS, CNAME, SOA, MX, TXT, CAA, SRV, PTR for reverse lookups, and DNSSEC-related records including RRSIG, NSEC, NSEC3, DNSKEY, and DS.
  • AXFR zone transfer, which requires LookupClient to be set to TCP mode only for that query type.
  • An optional audit trail of each response and exception, optional trace and logging, and configurable error handling where DNS errors such as NotExistentDomain do not throw by default.
  • SRV service-discovery queries with helper extensions on LookupClient.

Who uses it and how

  • .NET application developers embed LookupClient in service code to resolve hostnames, as in the README's example of awaiting QueryAsync("google.com", QueryType.A) and reading result.Answers.ARecords().
  • Operators running applications against multiple configured DNS endpoints rely on the random or sequential endpoint ordering and configurable retries for resilience.
  • Projects that need controlled cache behaviour in high-traffic, low-latency settings set a minimum TTL — even a few milliseconds — so responses are always cached for at least that long.
  • Teams working with Windows environments can depend on nameserver auto discovery that honours NRPT policy configuration rather than hardcoding resolvers.
  • Contributors and evaluators build the project from source and follow the MiniDig sample command-line tool and the separate DnsClient.NET.Samples repository for further usage patterns.

Getting started

Install the library from NuGet with the package name DnsClient, then instantiate new LookupClient() and call QueryAsync with a query name and query type; additional documentation and examples are on the project site at https://dnsclient.michaco.net.

How it compares

DnsClient.NET stands alone in this registry among comparable tools named in its documentation.

When to use it — and when not

Choose it when you are writing .NET code and need direct, cacheable, protocol-level DNS queries with a broad record-type surface; it is a library you embed, not a service, so there is no database, storage, or SMTP to operate, only the DNS servers you point it at. Avoid it if you need a DNS server rather than a client, or if you require a command-line dig-style tool as a dependency, and note that the README itself is brief, deferring to an external site for full documentation, with 21 open issues currently outstanding.

project readme (upstream, from github) — read inline

DnsClient.NET

Build Status Code Coverage NuGet NuGet

DnsClient.NET is a simple yet very powerful and high performance open source library for the .NET Framework to do DNS lookups.

Usage

See the DnsClient site for more details and documentation.

The following example instantiates a new LookupClient to query some IP address.


var lookup = new LookupClient();
var result = await lookup.QueryAsync("google.com", QueryType.A);

var record = result.Answers.ARecords().FirstOrDefault();
var ip = record?.Address;

Features

General

  • Sync & Async API
  • UDP and TCP lookup, configurable if TCP should be used as fallback in case the UDP result is truncated (default=true).
  • Configurable EDNS support to change the default UDP buffer size and request security relevant records
  • Caching
    • Query result cache based on provided TTL
    • Minimum TTL setting to overrule the result's TTL and always cache the responses for at least that time. (Even very low value, like a few milliseconds, do make a huge difference if used in high traffic low latency scenarios)
    • Maximum TTL to limit cache duration
    • Cache can be disabled
  • Nameserver auto discovery. If no servers are explicitly configured, DnsClient will try its best to resolve them based on your local system configuration. This includes DNS servers configured via network interfaces or even via Windows specific NRPT policies.
  • Multiple DNS endpoints can be configured. DnsClient will use them in random or sequential order (configurable), with re-tries.
  • Configurable retry of queries
  • Optional audit trail of each response and exception
  • Configurable error handling. Throwing DNS errors, like NotExistentDomain is turned off by default
  • Optional Trace/Logging

Supported resource records

  • A, AAAA, NS, CNAME, SOA, MB, MG, MR, WKS, HINFO, MINFO, MX, RP, TXT, AFSDB, URI, CAA, NULL, SSHFP, TLSA, RRSIG, NSEC, NSEC3, NSEC3PARAM, DNSKEY, DS, NAPTR, CERT
  • PTR for reverse lookups
  • SRV for service discovery. LookupClient has some extensions to help with that.
  • AXFR zone transfer (as per spec, LookupClient has to be set to TCP mode only for this type. Also, the result depends on if the DNS server trusts your current connection)

Build from Source

To build and contribute to this project, you must have the latest .NET SDKs and Visual Studio 2022 installed.

Examples

Frequently asked questions

Is DnsClient.NET free to use?

DnsClient.NET is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does DnsClient.NET do?

DnsClient.NET is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups

What is DnsClient.NET written in?

DnsClient.NET is primarily written in C#. Its source is publicly available at https://github.com/MichaCo/DnsClient.NET, and it has 880 GitHub stars.