| 1 |
[](https://godoc.org/codeberg.org/miekg/dns) |
| 2 |
[](https://codeberg.org/miekg/dns) |
| 3 |
|
| 4 |
# Modern, lightweight DNS library |
| 5 |
|
| 6 |
> Less is more. |
| 7 |
|
| 8 |
This work is partly funded by the [Nominet DNS Fund](https://nominet.uk/our-impact/nominet-dns-fund/). |
| 9 |
|
| 10 |
Complete and usable DNS library. All Resource Records are supported, including the DNSSEC types. It follows a |
| 11 |
lean and mean philosophy. Server side and client side programming is supported, i.e. you can build servers and |
| 12 |
resolvers with it. |
| 13 |
|
| 14 |
We try to keep the _main_ branch as sane as possible and at the bleeding edge of standards, avoiding |
| 15 |
breaking changes wherever reasonable. We rigorously follow upstream Go versions and use bleeding edge Go |
| 16 |
language features. But because this version is young, we allow ourselves some more headroom for |
| 17 |
making backwards incompatible changes. |
| 18 |
|
| 19 |
Many convenience functions are included in _dns_, _dnstest_ or otherwise in _dnsutils_. The RR's resource data |
| 20 |
(RDATA) is split off into its own package: _rdata_. This means accessing the RR's header and rdata is much |
| 21 |
simpler now. [^a] |
| 22 |
|
| 23 |
[^a]: A function is put in _dnsutils_, unless (due to cyclic imports) it is utterly impossible to put it there. Only then it is put in the main _dns_ package. |
| 24 |
|
| 25 |
Example programs are included _and_ benchmarked in |
| 26 |
[`cmd`](https://codeberg.org/miekg/dns/src/branch/main/cmd). And |
| 27 |
[`cmd/atomdns`](https://codeberg.org/miekg/dns/src/branch/main/cmd/atomdns/README.md) is a full blown |
| 28 |
production ready name server. Because of these we are depending on a lot more external packages - at some |
| 29 |
point these servers will be split off. |
| 30 |
|
| 31 |
Also [see the Go documentation](https://pkg.go.dev/codeberg.org/miekg/dns). |
| 32 |
|
| 33 |
This new version will not soon see a v1.0.0 release because I want to be able to still make changes. In a |
| 34 |
year or two (2028?) when things have stabilized it will be blessed with a v1.0.0. |
| 35 |
|
| 36 |
# Porting From v1 |
| 37 |
|
| 38 |
Everything from <https://github.com/miekg/dns> works. See |
| 39 |
[README-v1-to-v2.md](https://codeberg.org/miekg/dns/src/branch/main/_doc/README-v1-to-v2.md) |
| 40 |
for the differences, if you are porting your application, in `cookbook.go` are some common recipes. |
| 41 |
|
| 42 |
Note that a design choice has been made to not supported `\DDD` and `\x` syntax in domain names. This archaic |
| 43 |
way of encoding names was useful way-back-when, nowadays DNS is pretty much a 7-bit protocol and things like |
| 44 |
[Punycode](https://en.wikipedia.org/wiki/Punycode) had to be invented. There is one exception to this and that |
| 45 |
is the SOA's mname can contain a `\.`, for the rest it is ignore and interpreted as `\` and `.`. |
| 46 |
|
| 47 |
## Performance |
| 48 |
|
| 49 |
The performance should be roughly 2x across the board compared to v1 (also see below). |
| 50 |
|
| 51 |
- Serving DNS queries per second is \~2x (maybe more). |
| 52 |
- Parsing zones files in RRs per second is \~1.5x. |
| 53 |
- Memory usage can be \~0.5x due to rdata split off. |
| 54 |
|
| 55 |
For developers please read the |
| 56 |
[developer README](https://codeberg.org/miekg/dns/src/branch/main/_doc/README-dev.md). |
| 57 |
|
| 58 |
# Goals |
| 59 |
|
| 60 |
- KISS. |
| 61 |
- Everything is a resource record, EDNS0 pseudo RRs included. |
| 62 |
- Easy way to access RR's header and resource data (_rdata_ package). |
| 63 |
- Small API. |
| 64 |
- Package _dnsutil_ contains functions that help programmers, but are not necessarily in scope the _dns_ package. |
| 65 |
- Package _dnstest_ contains functions and types that help you test, similar to the _httptest_ package. |
| 66 |
- Package _dnsjson_ contains types for DNS RRs in JSON (RFC 8427). |
| 67 |
- Package _svcb_ holds all details of the SVCB/HTTPS record (RFC 9460). |
| 68 |
- Pacakge _deleg_ holds details for the DELEG record. |
| 69 |
- Many helper/debug functions are moved into _internal_ packages, making the top-level much, much cleaner. |
| 70 |
- Fast. |
| 71 |
- recvmmsg(2) and TCP pipe-lining support. |
| 72 |
- The `cmd/reflect` server does ~420K/340K qps UDP/TCP respectively on the right hardware. |
| 73 |
- Since a46996c I can get ~400K (UDP) qps on my laptop (M2/Asahi Linux), also see 1766e44, 86b53fe and 06e5e0f. |
| 74 |
- On my Dell XPS 17 (Intel) it is similar-ish (~310K/250K qps UDP/TCP). |
| 75 |
- On other Intel/AMD hardware it is lower (~200K (UDP) qps) - yet to understand why. |
| 76 |
- See `cmd/reflect` and do a `go build; make new.txt` to redo the performance test. Requires `dnsperf` to be installed. |
| 77 |
- The SE zone (8M RRs) is parsed in \~11s (\~730K RR/s), the CH zones (15M RRs) is parsed in \~14s (\~1M RR/s). |
| 78 |
The main difference being that SE use algorithm 8, and CH algorithm 13 (shorter RRSIGs). |
| 79 |
See `cmd/parse`, tested with M2/Asahi Linux. |
| 80 |
|
| 81 |
# Users |
| 82 |
|
| 83 |
A not-so-up-to-date-list-that-may-be-actually-current: |
| 84 |
|
| 85 |
- atomdns - included in [`cmd/atomdns`](https://codeberg.org/miekg/dns/src/branch/main/cmd/atomdns/) - a high performance DNS server, based on the principles of CoreDNS, but |
| 86 |
faster and simpler. |
| 87 |
- [dnscrypt-proxy](https://github.com/DNSCrypt/dnscrypt-proxy) - a flexible DNS proxy, with support for |
| 88 |
encrypted DNS protocols such as DNSCrypt v2, DOH, Anonymized DNSCrypt and |
| 89 |
[ODOH](https://developers.cloudflare.com/1.1.1.1/encryption/oblivious-dns-over-https/). |
| 90 |
- [DNSControl](https://dnscontrol.org/) - DNSControl is an opinionated platform for seamlessly managing your DNS configuration across any number of DNS hosts, |
| 91 |
both in the cloud or in your own infrastructure. |
| 92 |
- [Gonemaster](https://codeberg.org/pawal/gonemaster) - Gonemaster is a Go implementation of the DNS test framework Zonemaster engine and CLI. |
| 93 |
- [DNSieve](https://github.com/secu-tools/dnsieve) - a DNS filtering proxy that fans out queries to multiple upstream resolvers concurrently and enforces block-consensus. |
| 94 |
|
| 95 |
Send pull request if you want to be listed here. |
| 96 |
|
| 97 |
## Comments |
| 98 |
|
| 99 |
What users say: |
| 100 |
|
| 101 |
> miekg/dns is probably my favorite Go module in the open source ecosystem. It is very complete (every DNS rtype is defined) |
| 102 |
> and strict (field names match the RFCs, etc). DNSControl has used miekg/dns since the first release. |
| 103 |
|
| 104 |
- <https://codeberg.org/miekg/dns/issues/258#issue-2471506> |
| 105 |
|
| 106 |
> Your library is a blast and I cannot thank you enough 🙏. |
| 107 |
|
| 108 |
- <https://infosec.exchange/@x_cli/115745919220339651> |
| 109 |
|
| 110 |
# Features |
| 111 |
|
| 112 |
- UDP/TCP queries, recvmmsg(2), TCP query-pipelining, IPv4 and IPv6. |
| 113 |
- Fast. |
| 114 |
- RFC 1035 zone file parsing ($INCLUDE, $ORIGIN, $TTL and $GENERATE - for _all_ record types) is supported. |
| 115 |
- Server side programming (mimicking the net/http package), with `dns.Handle` and `dns.HandleFunc` allowing |
| 116 |
for middleware servers. |
| 117 |
- Client side programming. |
| 118 |
- DNSSEC: signing, validating and key generation for DSA, RSA, ECDSA, Ed25519 and ML-DSA-44. |
| 119 |
- EDNS0, NSID, Cookies, etc, as pseudo RRs in the (fake) pseudo section. |
| 120 |
- AXFR/IXFR. |
| 121 |
- TSIG, SIG(0). |
| 122 |
- DNS over TLS (DOT): encrypted connection between client and server over TCP. |
| 123 |
- DNS over HTTP (DOH), see the _dnshttp_ package. |
| 124 |
- Improved naming by embracing sub-packages. |
| 125 |
- Improved RRs, by having the rdata specified in an _rdata_ package. |
| 126 |
- Escapes (\DDD and \x) in domain names is not supported (anymore) - the overhead (50-100%) was too high. |
| 127 |
- Easy way for custom RRs and EDNS0 pseudo RRs. |
| 128 |
|
| 129 |
Have fun! |
| 130 |
|
| 131 |
Miek Gieben - 2026- - <[email protected]> |
| 132 |
|
| 133 |
See [anonymous users asking for support](https://berthub.eu/articles/posts/anonymous-help/) on why these kind |
| 134 |
of requests/issues usually get closed pretty swiftly. |
| 135 |
|
| 136 |
# Building/developing |
| 137 |
|
| 138 |
This library uses Go modules and uses semantic versioning. Getting the code and working with the library is |
| 139 |
done via: |
| 140 |
|
| 141 |
git clone [email protected]:miekg/dns # use https if you don't have a codeberg account |
| 142 |
cd dns |
| 143 |
# $EDTIOR *.go |
| 144 |
|
| 145 |
If you want to use codeberg/miekg/dns in your own project, just do a `go get codeberg.org/miekg/dns@latest` |
| 146 |
and import codeberg.org/miekg/dns in your Go files. |
| 147 |
|
| 148 |
## Examples |
| 149 |
|
| 150 |
A short "how to use the API" is at the beginning of `doc.go`. The cmd/ directory contains a reflect example |
| 151 |
program that is used for benchmarking, and further has atomdns which is full fledged DNS server that is |
| 152 |
developed in tandem with the library. |
| 153 |
|
| 154 |
## Supported RFCs |
| 155 |
|
| 156 |
_all of them_ and _then some_ |
| 157 |
|
| 158 |
- 103{3,4,5} - DNS standard |
| 159 |
- <s>1348 - NSAP record</s> |
| 160 |
- 1982 - Serial Arithmetic |
| 161 |
- 1876 - LOC record |
| 162 |
- 1995 - IXFR |
| 163 |
- 1996 - DNS notify |
| 164 |
- 2136 - DNS Update (dynamic updates) |
| 165 |
- 2181 - RRset definition |
| 166 |
- 2537 - RSAMD5 DNS keys |
| 167 |
- 2065 - DNSSEC (updated in later RFCs) |
| 168 |
- 2671 - EDNS record |
| 169 |
- 2782 - SRV record |
| 170 |
- 2845 - TSIG record |
| 171 |
- 2915 - NAPTR record |
| 172 |
- 2929 - DNS IANA Considerations |
| 173 |
- 3110 - RSASHA1 DNS keys |
| 174 |
- 3123 - APL record |
| 175 |
- 3225 - DO bit (DNSSEC OK) |
| 176 |
- 340{1,2,3} - NAPTR record |
| 177 |
- 3445 - Limiting the scope of (DNS)KEY |
| 178 |
- 3596 - AAAA record |
| 179 |
- 3597 - Unknown RRs |
| 180 |
- 4025 - A Method for Storing IPsec Keying Material in DNS |
| 181 |
- 403{3,4,5} - DNSSEC |
| 182 |
- 4255 - SSHFP record |
| 183 |
- 4343 - Case insensitivity |
| 184 |
- 4408 - SPF record |
| 185 |
- 4509 - SHA256 Hash in DS |
| 186 |
- 4592 - Wildcards in the DNS |
| 187 |
- 4635 - HMAC SHA TSIG |
| 188 |
- 4701 - DHCID |
| 189 |
- 4892 - id.server |
| 190 |
- 5001 - NSID |
| 191 |
- 5155 - NSEC3 record |
| 192 |
- 5205 - HIP record |
| 193 |
- 5702 - SHA2 in the DNS |
| 194 |
- 5936 - AXFR |
| 195 |
- 5966 - TCP implementation recommendations |
| 196 |
- 6605 - ECDSA |
| 197 |
- 6672 - DNAME |
| 198 |
- 6725 - IANA Registry Update |
| 199 |
- 6742 - ILNP DNS |
| 200 |
- 6840 - Clarifications and Implementation Notes for DNS Security |
| 201 |
- 6844 - CAA record |
| 202 |
- 6891 - EDNS0 update |
| 203 |
- 6895 - DNS IANA considerations |
| 204 |
- 6944 - DNSSEC DNSKEY Algorithm Status |
| 205 |
- 6975 - Algorithm Understanding in DNSSEC |
| 206 |
- 7043 - EUI48/EUI64 records |
| 207 |
- 7314 - DNS (EDNS) EXPIRE Option |
| 208 |
- 7477 - CSYNC RR |
| 209 |
- 7828 - TCP-keepalive EDNS0 Option |
| 210 |
- 7553 - URI record |
| 211 |
- 7719 - DNS Terminology |
| 212 |
- 7858 - DNS over TLS: Initiation and Performance Considerations |
| 213 |
- 7871 - EDNS0 Client Subnet |
| 214 |
- 7873 - Domain Name System (DNS) Cookies |
| 215 |
- 8080 - EdDSA for DNSSEC |
| 216 |
- 8145 - EDNS0 key tag |
| 217 |
- 8427 - Representing DNS Messages in JSON |
| 218 |
- 8482 - Minimal Answers for ANY |
| 219 |
- 8484 - DOH |
| 220 |
- 8499 - DNS Terminology |
| 221 |
- 8509 - DNSSEC Trusted Key Sentinel |
| 222 |
- 8659 - DNS Certification Authority Authorization (CAA) Resource Record |
| 223 |
- 8777 - DNS Reverse IP Automatic Multicast Tunneling (AMT) Discovery |
| 224 |
- 8914 - Extended DNS Errors |
| 225 |
- 8976 - Message Digest for DNS Zones (ZONEMD RR) |
| 226 |
- 9250 - DOQ (not implemented, waiting until Go supports QUIC) |
| 227 |
- 9461 - Service Binding Mapping for DNS Servers |
| 228 |
- 9462 - Discovery of Designated Resolvers |
| 229 |
- 9460 - SVCB and HTTPS Records |
| 230 |
- 9499 - DNS Terminology |
| 231 |
- 9558 - GOST 2012 for DNSSEC |
| 232 |
- 9563 - SM2 for DNSSEC |
| 233 |
- 9567 - DNS Error Reporting |
| 234 |
- 9606 - DNS Resolver Information |
| 235 |
- 9660 - Zone version |
| 236 |
- 9715 - IP Fragmentation Avoidance in DNS over UDP |
| 237 |
- 9824 - Compact Denial of Existence in DNSSEC |
| 238 |
- 9859 - DSYNC RR |
| 239 |
- draft-ietf-deleg - DELEG RR |
| 240 |
- draft-westerbaan-dnssec-mldsa-04 - MLDSA for DNSSEC |