Overview
editDnsClient sends DNS queries to one server, over the transport you choose, and returns the parsed response. It is a client for a resolver or an authoritative server you name: it does not read the DNS configuration of the machine and does not resolve names recursively by itself.
using var client = new DnsClient(serverAddress, DnsClientProtocol.Udp);
var response = await client.QueryAsync("www.example.com", DnsQueryType.A);
Assert.Equal(DnsResponseCode.NoError, response.Header.ResponseCode);
var addresses = response.Answers.OfType<DnsARecord>().Select(record => record.Address).ToList();
Assert.Equal([IPAddress.Parse("192.0.2.10")], addresses);Pages
- Protocols: UDP, TCP, DNS over TLS, DNS over HTTPS and DNS over QUIC, the format of the server address, and the HTTP options.
- Querying: record types, typed records, response codes, reverse lookups, internationalized names, and custom query messages.
- DNSSEC: request the signatures, read the resolver's AD flag, or validate the chain of trust locally.
- Errors and timeouts: the exceptions, the timeout, how responses are checked, and tracing.
Options
DnsClientOptions is the third argument of the constructor:
| Option | Default | Use |
|---|---|---|
| Timeout | 5 seconds | How long to wait for a response. Timeout.InfiniteTimeSpan disables it. See Errors and timeouts. |
| EnableEdns | true | Adds an EDNS(0) OPT record to the queries. |
| EdnsUdpPayloadSize | 1232 | The largest UDP response the client accepts, advertised in the OPT record. |
| RetryTruncatedOverTcp | true | Sends the query again over TCP when a UDP response is truncated. See Truncated responses. |
| DnssecOk | false | Asks for the DNSSEC records. See DNSSEC. |
| DnssecValidationMode | None | Local validates the DNSSEC chain of trust. See DNSSEC. |
| DnssecTrustAnchors | DnssecTrustAnchors.Root | The trust anchors of local validation. |
| TimeProvider | TimeProvider.System | The clock used to check the validity period of DNSSEC signatures. |
| HttpHandler, HttpVersion, HttpVersionPolicy | a pooled handler, HTTP/2, RequestVersionOrLower | DNS over HTTPS only. See DNS over HTTPS. |
| ServerAddressResolver | the system resolver | Resolves the host name of the server. See Server address. |