Dino DNS

March 5, 2022 ยท View on GitHub

Icon

Dino DNS

A fast and efficient DNS server and client

Build NuGet

Overview

Dino DNS provides fast and flexible DNS client and server implementations for:

๐Ÿค Licensing and Support

Dino DNS is licensed under the MIT license. It is free to use in personal and commercial projects.

There are support plans available that cover all active Turner Software OSS projects. Support plans provide private email support, expert usage advice for our projects, priority bug fixes and more. These support plans help fund our OSS commitments to provide better software for everyone.

๐Ÿฅ‡ Performance

These performance comparisons show the performance overhead of the DNS library itself and associated allocations. They do not represent the network overhead to a remote DNS servers.

The server implementation that each benchmark is performing against is Dino DNS.

DNS-over-UDP

This is your typical DNS query. While fast and efficient, it is limited by the lack of transport-layer encryption, reliable delivery and message length.

MethodMeanErrorStdDevOp/sRatioRatioSDGen 0Gen 1Allocated
DinoDNS90.28 us1.066 us0.945 us11,077.11.000.000.4883-1,704 B
Kapetan_DNS325.99 us10.447 us30.803 us3,067.63.580.1923.43750.976673,996 B
MichaCo_DnsClient257.72 us5.141 us10.384 us3,880.12.840.1122.4609-71,640 B

DNS-over-TCP

With TCP DNS queries, there is a small overhead from negotiating the connection but otherwise is very fast. It addresses the reliable delivery and message length limitations that occur with UDP queries.

A good DNS client implementation will pool TCP sockets to avoid needing to negotiate the connection per request.

MethodMeanErrorStdDevOp/sRatioRatioSDGen 0Allocated
DinoDNS94.99 us1.018 us0.902 us10,527.11.000.000.48831,892 B
MichaCo_DnsClient112.52 us2.246 us3.562 us8,887.11.210.051.46485,064 B
โš  Note: While Kapetan's DNS client does support TCP, it can't be benchmarked due to port exhaustion issues it has.

DNS-over-TLS

With DNS-over-TLS, you get the benefits of DNS-over-TCP with transport-layer encryption between the client and the server.

MethodMeanErrorStdDevOp/sRatioGen 0Allocated
DinoDNS126.5 us2.09 us1.95 us7,908.11.000.48832,274 B

๐Ÿ‘‹ Know of a .NET DNS-over-TLS client? Raise a PR to add it as a comparison!

DNS-over-HTTPS

An alternative to DNS-over-TLS is DNS-over-HTTPS, providing the same core functionality through a different method. This can disguise DNS traffic when performed over port 443 (the default port for HTTPS).

MethodMeanErrorStdDevOp/sRatioGen 0Allocated
DinoDNS207.2 us3.77 us3.52 us4,827.11.001.46485,625 B

๐Ÿ‘‹ Know of a .NET DNS-over-HTTPS client? Raise a PR to add it as a comparison!

โญ Getting Started

Perform a DNS query

This is a basic query against a DNS server, retrieving "A" records to further process.

var client = new DnsClient(new NameServer[]
{
	new NameServer(IPAddress.Parse("192.168.0.1"), ConnectionType.Udp)
	NameServers.Cloudflare.IPv4.GetPrimary(ConnectionType.DoH),
}, DnsMessageOptions.Default);

var dnsMessage = await client.QueryAsync("example.org", DnsQueryType.A);
var aRecords = dnsMessage.Answers.WithARecords();

Implement a basic DNS server

This is a basic forwarding DNS server where you can, for example, have use a UDP server endpoint but forward over TLS to another name server.

public class DnsForwardingServer : DnsServerBase
{
	private readonly DnsClient Client;

	public DnsForwardingServer(
		NameServer[] nameServers,
		ServerEndPoint[] endPoints,
		DnsMessageOptions options
	) : base(endPoints, options)
	{
		Client = new DnsClient(nameServers, options);
	}

	protected override async ValueTask<int> OnReceiveAsync(ReadOnlyMemory<byte> requestBuffer, Memory<byte> responseBuffer, CancellationToken cancellationToken)
	{
		return await Client.SendAsync(requestBuffer, responseBuffer, cancellationToken).ConfigureAwait(false);
	}
}

var server = new DnsForwardingServer(
	new[] { NameServers.Cloudflare.IPv4.GetPrimary(ConnectionType.DoT) },
	new[] { new ServerEndpoint(ConnectionType.Udp) },
	DnsMessageOptions.Default
);
server.Start();