### Start atomdns with an Example Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/README.md Run atomdns using a more comprehensive example configuration file named 'Conffile-example'. ```bash ./atomdns -c Conffile-example ``` -------------------------------- ### Start atomdns with a Configuration File Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/README.md Execute the compiled atomdns binary, specifying the configuration file to use. The example uses 'Conffile'. ```bash ./atomdns -c Conffile ``` -------------------------------- ### Built-in Conffile Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns.1.md This example demonstrates a built-in configuration file that includes DNS settings and a zone configuration with 'log' and 'whoami' handlers. ```conffile { dns { addr [::]1053 } } example.org { log whoami } ``` -------------------------------- ### atomdns Startup Log Output Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/README.md Example log output upon starting atomdns, showing configured handlers, listening interfaces, and server version. This output provides insights into the server's operational status and configuration. ```txt 2025/12/18 13:30:03 INFO 0.0.10.in-addr.arpa. handlers=log,whoami 2025/12/18 13:30:03 INFO example.org. handlers=id,log,dbfile 2025/12/18 13:30:03 INFO miek.nl. handlers=log,metrics,sign,dbfile 2025/12/18 13:30:03 INFO Startup functions total=14 2025/12/18 13:30:03 INFO Startup handler=global /health=:8080 2025/12/18 13:30:03 INFO Startup handler=global health="overload check" 2025/12/18 13:30:03 INFO Startup handler=global /metrics=localhost:9153 /N=10 2025/12/18 13:30:03 INFO Startup handler=global dns=[::]:1053 tcp=-1 run=24 2025/12/18 13:30:03 INFO Startup handler=global doh=[::]:1443 run=8 inflight=100 path=/dns-query 2025/12/18 13:30:03 INFO Startup handler=global dot=[::]:8053 tcp=1024 run=1 inflight=200 2025/12/18 13:30:03 INFO Startup handler=global tls=manual 2025/12/18 13:30:03 INFO Startup handler=global signal=HUP 2025/12/18 13:30:03 INFO Startup handler=log signal=USR1 2025/12/18 13:30:03 INFO Startup handler=dbfile reload=db.example.org 2025/12/18 13:30:03 INFO Startup handler=sign signing=db.miek.nl 2025/12/18 13:30:03 INFO Days left before expiration handler=sign zone=miek.nl. path=db.miek.nl.signed days=36 2025/12/18 13:30:03 INFO Startup handler=dbfile reload=db.miek.nl.signed 2025/12/18 13:30:03 INFO Build GOOS=linux GOARCH=arm64 go=1.25.5 revision=79e3ca30a4364da296eb74ab67ae04a184166e5a 2025/12/18 13:30:03 INFO Listening roles=DNS:[::]:1053,DOH:[::]:1443,DOT:[::]:8053 2025/12/18 13:30:03 INFO Launched config=Conffile-example PID=3325169 version=v058 dns=0.6.5 zones=3 ┏━┓ ╺┳╸ ┏━┓ ┏┳┓ ┣━┫ ┃ ┃ ┃ ┃┃┃ DNS ╹ ╹ ╹ ┗━┛ ╹ ╹ v058 (0.6.5) High performance and flexible DNS server https://atomdns.miek.nl __________________________________\o/_______ ``` -------------------------------- ### NXDOMAIN Go Template Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/template/README.md An example Go template file used by the template handler to generate an NXDOMAIN response. It includes dynamic fields like query ID and question, and conditionally adds TXT record based on GeoIP ASN data from the context. ```txt ;; QUERY, rcode: NOERROR, id: {{.ID}}, flags: qr rd ra ;; QUESTION SECTION: {{.Question}} ;; AUTHORITY SECTION: {{.Zone}} IN SOA ns.icann.org. noc.dns.icann.org. 2025082229 7200 3600 1209600 3600 {{if Ctx "geoip/asn"}} {{.Zone}} IN TXT "{{Ctx "geoip/asn"}}" {{end}} ``` -------------------------------- ### Compile atomdns from Source Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/README.md Clone the repository, navigate to the atomdns directory, and build the binary. Ensure you have a working Go setup. ```bash $ git clone https://codeberg.org/miekg/dns $ cd dns/cmd/atomdns $ go build ``` -------------------------------- ### Default Log Output Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/log/README.md An example of a typical log line generated by the log handler, showing query details like domain, network, remote address, port, ID, type, class, name, size, buffer size, and opcode. ```txt 2025/10/06 07:25:52 INFO example.org. network=udp remote=::1 port=40689 id=23343 type=MX class=IN name=example.org. size=52 bufsize=1232 opcode=QUERY ``` -------------------------------- ### Minimal DNS Server Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md A basic configuration to start a DNS server authoritative for 'example.org.' with 'log' and 'whoami' handlers. ```dnsconfig example.org log whoami ``` -------------------------------- ### Example GeoIP Handler Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/geoip/README.md An example of how to configure the geoip handler to add location data for use with the template handler. Uses a test database file for city lookups. ```config example.org. { geoip { city testdata/GeoIPCity.dat } template .* { mytemplate.go.tmpl } } ``` -------------------------------- ### Example: Serving a Zone with Specific Transfer Settings Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbfile/README.md Configures the 'example.org' zone to load from 'db.example.org', allowing internet transfers and sending notifications to a specific IP. ```conffile example.org { dbfile db.example.org { transfer { to { notify 10.240.1.1 } } } } ``` -------------------------------- ### Example Hosts File Entries Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbhost/README.md Illustrates common IPv4 and IPv6 entries in a standard hosts file format. ```hosts # The following lines are desirable for IPv4 capable hosts 127.0.0.1 localhost 192.168.1.10 example.com example # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fdfc:a744:27b5:3b0e::1 example.com example ``` -------------------------------- ### Import miekg/dns in Go Project Source: https://github.com/miekg/dns/blob/main/README.md How to add the miekg/dns library to your Go project using go get and import it in your Go files. ```bash go get codeberg.org/miekg/dns@latest ``` -------------------------------- ### Delay Queries Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/drunk/README.md Configures the 'drunk' handler to delay every 3rd query for 50ms. This simulates network latency. ```conffile example.org { drunk { delay /3 50ms } whoami } ``` -------------------------------- ### Import files matching a glob pattern Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/import/README.md This example shows how to import all files within the '../zones/' directory that match the glob pattern '*'. ```conffile import ../zones/* ``` -------------------------------- ### Example: Multiple Zones with Shared File and Source IP Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbfile/README.md Configures multiple zones ('example.org', 'example.net') to use a single signed zone file and specifies the source interface for outgoing transfers. ```conffile example.org example.net { dbfile example.org.signed { transfer { to 10.240.1.1 { source eth0 } } } } ``` -------------------------------- ### RFC 1035 Zone File Format Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbfile/README.md An example of a zone file in the text presentation format as defined in RFC 1035, including SOA and NS records. ```dns $ORIGIN example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600 3600 IN NS a.iana-servers.net. 3600 IN NS b.iana-servers.net. www IN A 127.0.0.1 IN AAAA ::1 ``` -------------------------------- ### Catch-all dbsqlite Configuration (Caution) Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbsqlite/README.md Example of configuring dbsqlite to handle all zones ('.'). This only works if the server is authoritative for the root zone. ```conffile . { dbsqlite root.db } ``` -------------------------------- ### Example whoami DNS response Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/whoami/README.md This is an example of the DNS response generated by the whoami handler when queried for an A record. It includes the client's IP address and port information. ```dns ;; QUESTION SECTION: ;example.org. IN A ;; ADDITIONAL SECTION: example.org. 0 IN A 10.240.0.1 _udp.example.org. 0 IN SRV 0 0 40212 ``` -------------------------------- ### TLS and DOH Configuration with Limits Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md An example configuration that includes settings for DNS, DoH, TLS (Let's Encrypt), and specific handler blocks for zones, including limits on concurrent runs. ```conffile { root /var/lib/atomdns dns { addr [::]:1053 limits { tcp -1 run numcpu()*3 } } doh { addr [::]:10053 limits { run numcpu()*1 } } tls lets-encrypt { source eth0 contact miek@miek.nl directory lets-encrypt } } example.net { log dbfile example.net } ``` -------------------------------- ### Coexisting v1 and v2 Imports Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Demonstrates how to import both v1 and v2 of the dns library simultaneously to allow for incremental conversion. This setup enables differentiating between `dnsv1.RR` and `dns.RR`. ```go import ( dnsv1 "github.com/miekg/dns" "codeberg.org/miekg/dns" ) ``` -------------------------------- ### Default Drop Behavior Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/drunk/README.md Uses the default 'drunk' handler configuration to drop queries. This is a shorter syntax for applying the default drop behavior. ```conffile example.org { drunk whoami } ``` -------------------------------- ### Load Root Zone from URL Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/url/README.md Example of loading the root zone from a URL and saving it to a local file named 'root.transferred'. This demonstrates the practical usage of the url handler. ```conffile . { url root.transferred { https://www.internic.net/domain/root.zone } } ``` -------------------------------- ### Chaos Handler Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Configures the chaos handler for the root zone, providing an optional argument that is returned on CH class queries. ```conffile . { chaos atomdns-001 } ``` -------------------------------- ### Drop Queries Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/drunk/README.md Configures the 'drunk' handler to drop every 3rd query. This is useful for testing how clients handle dropped requests. ```conffile example.org { drunk { drop /3 } whoami } ``` -------------------------------- ### Basic atomdns Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/README.md A minimal Conffile to start atomdns on port 1053 with the 'whoami' handler enabled. The server will look for this file in the current working directory. ```conffile { dns { addr [::]:1053 } } . { whoami } ``` -------------------------------- ### AtomDNS Configuration with GeoIP and Log Handlers Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/log/README.md An example AtomDNS configuration file demonstrating how to enable the geoip handler to add location data to the context, and then use the log handler to log this specific context data. ```conffile example.org. { geoip { city testdata/GeoIPCity.dat } log { geoip/city } whoami } ``` -------------------------------- ### Delay and Truncate Queries Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/drunk/README.md Configures the 'drunk' handler to delay every 3rd query for 5ms and truncate every 5th query. This simulates a combination of network issues. ```conffile example.org { drunk { delay /3 5ms truncate /5 } whoami } ``` -------------------------------- ### Sign Handler Log Output Example Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/sign/README.md This log output illustrates the typical messages generated by the sign handler during the zone signing process, including startup, signing completion, and re-signing events. ```log 2025/09/15 12:00:35 INFO example.org. handlers=log,sign,dbfile 2025/09/15 12:00:35 INFO Start: /metrics handler=global 2025/09/15 12:00:35 INFO Startup: signing: db.example.org handler=sign 2025/09/15 12:00:35 INFO Zone "example.org." in "db.example.org" is signed and is written to db.example.org.signed handler=sign 2025/09/15 12:00:35 INFO Startup: reload: db.example.org.signed handler=dbfile 2025/09/15 12:00:47 INFO Zone "example.org." in "db.example.org" is signed and is written to db.example.org.signed handler=sign 2025/09/15 12:00:47 INFO Resign of zone "example.org." in "db.example.org" successful handler=sign 2025/09/15 12:00:49 INFO Reload of zone "example.org." in "db.example.org.signed" successful handler=dbfile ``` -------------------------------- ### DNS-over-TLS (DoT) Server Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md Configure DNS-over-TLS server options, specifying the listening address and limits for server instances. Requires a separate TLS setup. ```txt dot { addr ADDRESS limits { run EXPR } } ``` -------------------------------- ### Setting EDNS0 UDP Buffer Size (Simplified) Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md A simplified example of setting the EDNS0 UDP buffer size for a new DNS message. ```go m := dns.NewMsg("miek.nl.", dns.TypeDNSKEY") m.UDPSize, m.Security = 4096, true ``` -------------------------------- ### AtomDNS Configuration with Metrics Disabled Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/metrics/README.md Example of an AtomDNS configuration block that disables metrics for a specific zone. ```txt example.org { metrics disable whoami } ``` -------------------------------- ### Inserting Records into SQLite Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbsqlite/README.md Examples of inserting SRV and NS records into the 'rrs' table for the dbsqlite handler. ```sql sqlite> insert into rrs values ( '_ssh._tcp.host1.example.', 'srv', '10 5 43 example', 3600); ``` ```sql sqlite> insert into rrs values ( 'subdel.example', 'ns', 'ns.example.com', 3600); ``` -------------------------------- ### Example 'any' Handler Response Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/any/README.md This demonstrates the expected output when a dig command queries for ANY records on a zone configured with the 'any' handler. The response adheres to RFC 8482. ```txt example.org. 8482 IN HINFO "ANY obsoleted" "See RFC 8482" ``` -------------------------------- ### Enable DNS Cookie Handler Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/cookie/README.md Example of enabling the cookie handler in a configuration file. The SECRET is used for server cookie generation. ```conffile example.org { cookie Use the force whoami } ``` -------------------------------- ### Example Usage of Kill Handler Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/kill/README.md This configuration snippet demonstrates how to use the kill handler to stop the atomdns server after 10 seconds. It's typically used in conjunction with other handlers like 'any' and 'whoami'. ```conffile example.org { kill 10s any whoami } ``` -------------------------------- ### Determine RR Type and Convert to String Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Shows how to get the RR type and its string representation in v2 using dns.RRToType and dns.TypeToString. ```go OLD | NEW | hdr := rr.Header() | rrtype := dns.RRToType(rr) | rrtype := hdr.Rrtype | str := dns.TypeToString[rrtype] | str := dns.TypeToString[rrtype] | // or | | str = dnsutil.TypeToString(rrtype) // gives TYPEXXX for unknown types ``` -------------------------------- ### Configure tsig Handler Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/tsig/README.md Example of configuring the tsig handler in a dns configuration file. Specifies the key name, algorithm, and base64 encoded secret. ```coredns example.org { tsig example.org.key hmac-sha512 NoTCJU+DMqFWywaPyxSijrDEA/eC3nK0xi3AMEZuPVk= dbhost ... { # ... } } ``` -------------------------------- ### Log Output with ECS and ID Context Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/log/README.md An example log line that includes additional context such as the ECS address and the generated request ID, when these handlers are also enabled. ```txt 2025/10/06 07:25:52 INFO example.org. id.id=5FOXMDAG6YAHD6R7QOZ4UTX7VQ network=udp remote=::1 port=40689 ecs.addr=198.51.100.0 id=23343 type=MX class=IN name=example.org. size=52 bufsize=1232 opcode=QUERY ``` -------------------------------- ### Selective Blocking of Opcode with IP Range Exceptions Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/acl/README.md This example blocks all DNS queries with the 'UPDATE' opcode, except for those originating from '192.168.1.0/24'. The 'allow' rule takes precedence for matching IPs. ```conffile . { acl { allow UPDATE 192.168.1.0/24 block UPDATE } } ``` -------------------------------- ### Clone and Build miekg/dns Source: https://github.com/miekg/dns/blob/main/README.md Instructions on how to clone the repository and set up the Go environment for development. Ensure you have Go modules enabled. ```bash git clone git@codeberg.org:miekg/dns # use https if you don't have a codeberg account cd dns # $EDTIOR *.go ``` -------------------------------- ### Implementing a DNS Server Handler (v2) Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Illustrates the updated signature and implementation for a DNS server handler in v2, using `context.Context`, `ResponseWriter`, `Msg`, and `io.Copy`. ```go func HelloServer(ctx contect.Context, w ResponseWriter, req *Msg) { m := req.Copy() dnsutil.SetReply(m, req) m.Extra = []dns.RR{ &TXT{Hdr: dns.Header{Name: m.Question[0].Name, Class: dns.ClassINET}, Txt: []string{"Hello world"}} } m.Pack() io.Copy(w, m) } ``` -------------------------------- ### Getting Canonical Name Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md The `CanonicalName` function has been moved and renamed to `Canonical` within the `dnsutil` package. ```go canon := dnsutil.Canonical(name) ``` -------------------------------- ### Sign Zone with Common Signing Key Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/sign/README.md This snippet demonstrates how to configure the sign handler to sign the 'example.org' zone using specified key files. The signed output is directed to 'db.example.org.signed' for the dbfile handler. ```coredns example.org { sign db.example.org { key Kexample.org.+013+32412 } dbfile db.example.org.signed } ``` -------------------------------- ### DNS-over-QUIC (DoQ) Server Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md Configure DNS-over-QUIC server options by specifying the listening socket address. ```txt dou { addr SOCKET } ``` -------------------------------- ### Configure Log Handler with Context Keys Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/log/README.md Syntax to enable the log handler and specify custom context keys to log. Non-existing keys are ignored, but adding default keys will result in an error. ```txt log { CTX [CTX]... } ``` -------------------------------- ### Setting a DNS Question Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md The `SetQuestion` method has been moved to the `dnsutil` package and now requires the message object as the first argument. ```go dnsutil.SetQuestion(m, "miek.nl.", dns.TypeDNSKEY) ``` -------------------------------- ### Template Handler Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/template/README.md This configuration block sets up the template handler to match any query ('.*') and use the 'nxdomain.go.tmpl' file for generating the response. ```conffile example.org. { template .* { nxdomain.go.tmpl } } ``` -------------------------------- ### Enabling Includes in Zone Parser Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Demonstrates how to enable include directives in the `dns.NewZoneParser`. This is now the default behavior in v2. ```go zp := dns.NewZoneParser(...) zp.SetIncludeAllowed(true) // now the default ``` -------------------------------- ### Prometheus Scrape Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/metrics/README.md Configuration snippet for Prometheus to scrape metrics from an AtomDNS instance. Ensure the target address and port match your AtomDNS setup. ```yaml global: scrape_interval: 1m scrape_configs: - job_name: atomdns static_configs: - targets: ["localhost:9153"] ``` -------------------------------- ### Basic dbfile Handler Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbfile/README.md The simplest form to configure the dbfile handler to load a zone file. ```conffile dbfile FILE ``` -------------------------------- ### Accessing EDNS0 Options Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Demonstrates iterating through EDNS0 options within a DNS message's pseudo-section. ```go for i, options := range m.Pseudo { // ... } ``` ```go for i, options := range opt.Options { // ... } ``` -------------------------------- ### Setting EDNS0 Options Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Illustrates the new method for creating a DNS message and setting EDNS0 options like UDP size and security. ```go m := dns.NewMsg("miek.nl.", dns.TypeDNSKEY) m.UDPSize, m.Security = 4096, true ``` ```go m := new(dns.Msg) dnsutil.SetQuestion(m, "miek.nl.", dns.TypeDNSKEY") m.UDPSize, m.Security = 4096, true ``` -------------------------------- ### Handler Logging with slog Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/README.md Demonstrates how to use the generated log function within a handler for structured logging with the slog package. It shows how to add context like the file path and log different severity levels. ```go alog := log().With(slog.String("path", filepath.Base(d.Path))) alog.Error("Failed to reload", Err(err)) // or alog.Info("Successful reload") ``` -------------------------------- ### Enable Log Handler Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/log/README.md Basic syntax to enable the log handler. This will log default query properties to standard output. ```txt log ``` -------------------------------- ### Simplified Handler Block Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md A shorter syntax for configurations with a single handler, where the zone and handler are listed directly. ```conffile ZONE [ZONE]... [HANDLER]... ``` -------------------------------- ### Importing Zone Files using SQLite Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbsqlite/README.md Demonstrates importing zone data from a file into the 'rrs' table using SQLite's .import command. ```bash ldns-read-zone db.example.org | sed 's/;.*$//' | sed 's/ $//' | \ awk '{print $1 "," $4 "," substr($0, index($0, $5)) "," $2}' > csv.example.org sqlite3 /tmp/db < .mode csv heredoc> BEGIN; heredoc> .import csv.example.org rrs heredoc> COMMIT; heredoc> EOF ``` -------------------------------- ### Filter Specific Record Types from a Network Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/acl/README.md This example shows how to filter all DNS queries of type 'A' originating from the '192.168.0.0/16' network. Queries matching this rule are filtered and return a 'noerror' response with an 'filtered' extended error. ```conffile . { acl { filter A 192.168.0.0/16 } } ``` -------------------------------- ### Handling Fully Qualified Domain Names (FQDN) Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md The `Fqdn` function for ensuring domain names are fully qualified has moved to the `dnsutil` package. ```go s := dnsutil.Fqdn(s) ``` -------------------------------- ### Multiple Zones with Separate Blocks Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Shows how to define handlers for different zones using separate handler blocks. ```conffile example.org { whoami } org { whoami } ``` -------------------------------- ### Load Custom Hosts File for Specific Domain Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbhost/README.md Configures AtomDNS to use a custom hosts file ('example.hosts') for DNS resolution, specifically for the 'example.org' domain. ```conffile example.org { dbhost example.hosts } ``` -------------------------------- ### Create DNS RR (MX Record) Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Illustrates the updated syntax for creating an MX record in v2, including changes to rdata structure. ```go OLD | | r := &MX{ Header{Name:"miek.nl.", Class: dns.ClassINET, TTL: 3600}, | Preference: 10, Mx: "mx.miek.nl."} | | | NEW | r := &MX{ | Header{Name:"miek.nl.", Class: dns.ClassINET, TTL: 3600}, | MX: rdata.MX{Preference: 10, Mx: "mx.miek.nl."}, | } ``` -------------------------------- ### Load Default /etc/hosts File Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbhost/README.md Configures AtomDNS to use the default /etc/hosts file for DNS resolution. ```conffile . { dbhost } ``` -------------------------------- ### dbhost Handler Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbhost/README.md Defines the basic syntax for configuring the dbhost handler, including the optional hosts file path and TTL setting. ```txt dbhost [FILE] { ttl TTL } ``` -------------------------------- ### Basic DNS Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns.1.md This snippet shows a minimal configuration to listen on all addresses on port 53. ```conffile { dns { addr [::]:53 } } ``` -------------------------------- ### Import a shared configuration file Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/import/README.md This snippet demonstrates how to import a shared configuration file named 'config/common.conf'. The contents of the imported file will replace the import line. ```conffile . { import config/common.conf } ``` -------------------------------- ### DNS Server Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md Configure the primary DNS server settings, including the listening address and limits for TCP connections and the number of server instances. ```txt dns { addr ADDRESS limits { tcp EXPR run EXPR } } ``` -------------------------------- ### atomdns Configuration with 'any' Handler Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/any/README.md This snippet shows how to configure the 'any' handler within an atomdns zone. It's used to provide a minimal HINFO response to any query. ```conffile example.org { any whoami } ``` -------------------------------- ### Global Configuration Block Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Specifies server-wide options, including network interfaces for DNS, DoT, DoH, and DoU servers, as well as the root directory and metrics endpoint. ```txt { dns { addr [::]:1053 } root /var/lib/atomdns metrics localhost:9153 } ``` -------------------------------- ### Snippet Definition and Usage Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Demonstrates how to define a reusable snippet and then import it into a handler block for a specific zone. ```conffile (mysnippet) { log whoami } example.org { import mysnippet } ``` -------------------------------- ### Adding EDNS0 Options Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Illustrates how to add EDNS0 options, such as NSID, to a DNS message by assigning to the pseudo section. ```go m.Security = true m.UDPSize = dns.DefaultMsgSize m.Pseudo = append(m.Pseudo, &dns.NSID{}) ``` -------------------------------- ### dbfile Handler with Transfer Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbfile/README.md Extended syntax for configuring zone transfers (incoming and outgoing AXFR) with TSIG keys and notification settings. ```conffile dbfile FILE { transfer { from IP[:PORT] [IP[:PORT]]... { key NAME ALGORITHM SECRET } to [IP[:PORT]]... { notify IP[:PORT] [IP[:PORT]]... source IP|IFACE [IP|IFACE] key NAME ALGORITHM SECRET } } } ``` -------------------------------- ### Testing Chaos Handler with dig Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/chaos/README.md Use the dig command to query for the version.bind TXT record in the CH class against a local server. ```txt % dig @localhost CH TXT version.bind ;; ANSWER SECTION: version.bind. 0 CH TXT "atomdns-001" ``` -------------------------------- ### Unpack Handler Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/unpack/README.md The syntax for the unpack handler is shown for documentation purposes. This handler is automatically set as the first handler to run. ```text unpack ``` -------------------------------- ### Basic Handler Block Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Defines the general structure for handler blocks, specifying zones and the handlers to be executed for queries within those zones. ```txt ZONE [ZONE]... { [HANDLER]... } ``` -------------------------------- ### atomdns Server Banner Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns.1.md This is the startup banner displayed by atomdns when it runs successfully, showing version information and a performance claim. ```text DNS v024 (0.5.15) High performance and flexible DNS server https://atomdns.miek.nl __________________________________\o/_______ ``` -------------------------------- ### Drunk Handler Configuration Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/drunk/README.md Defines the syntax for configuring the 'drunk' handler, including options for dropping, truncating, and delaying queries. ```txt drunk { drop [/N] truncate [/M] delay [/L [DURATION]] } ``` -------------------------------- ### url Handler Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/url/README.md Defines the basic syntax for the url handler, specifying the local file path and the URL(s) to fetch zone data from. ```plaintext url FILE { URL } ``` -------------------------------- ### Disabling Includes in Zone Parser Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Shows how to explicitly disallow include directives in the `dns.NewZoneParser` by setting a custom `IncludeAllowFunc`. ```go zp := dns.NewZoneParser(...) zp.IncludeAllowFunc = func() bool { return false } ``` -------------------------------- ### Reverse Zone using CIDR on Non-Octet Boundary Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Demonstrates configuring a reverse zone using CIDR notation that does not align with octet boundaries. ```conffile 10.0.0.0/27 { whoami } ``` -------------------------------- ### TLS Configuration for DNS-over-TLS Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md Configure TLS settings for DNS-over-TLS, including certificate paths, CA information, network source, contact email, and directory settings. ```txt tls ISSUER { cert CERT KEY ca URL source IP|IFACE [IP|IFACE]... contact EMAIL directory DIRECTORY rootca CA } ``` -------------------------------- ### Profiling Tools Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md Enables the use of profiling tools by specifying the output file for atomdns profiling data. ```dnsconfig { pprof atomdns.prof } ``` -------------------------------- ### DNS-over-HTTPS (DoH) Server Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md Configure DNS-over-HTTPS server options, including the listening address and limits for concurrent requests and server instances. ```txt doh { addr ADDRESS limits { run EXPR inflight EXPR } } ``` -------------------------------- ### Refuse Handler Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/refuse/README.md The syntax for the refuse handler is shown for documentation purposes. ```text refused ``` -------------------------------- ### Context-Based Access Control with GeoIP Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/acl/README.md This snippet demonstrates using context values for access control. It drops queries from 'Cambridge' city but allows queries from any country within the 'EU'. This requires the 'geoip' handler to be configured and populated. ```conffile . { acl { block geoip/city Cambridge allow geoip/country/eu true } } ``` -------------------------------- ### Copying a DNS Message Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md The `Copy` method for DNS messages is now a shallow copy. Use this when you need a quick copy of the message structure. ```go r := m.Copy() // Shallow copy! ``` -------------------------------- ### AtomDNS Global Configuration Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/global/README.md This is the general syntax for the global block in the AtomDNS configuration file. It outlines all available directives for server-wide settings. ```txt { root DIRECTORY log { debug json quiet disable } metrics [/N] [ADDRRES] health [ADDRESS [LAMEDUCK]] pprof [FILE|ADDRESS] dns { addr ADDRESS limits { tcp EXPR run EXPR } } dot { addr ADDRESS limits { run EXPR } } doh { addr ADDRESS limits { run EXPR inflight EXPR } } dou { addr SOCKET } tls ISSUER { cert CERT KEY ca URL source IP|IFACE [IP|IFACE]... contact EMAIL directory DIRECTORY rootca CA } } ``` -------------------------------- ### Import a defined snippet Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/import/README.md This snippet demonstrates how to invoke a previously defined snippet named 'mysnippet' using the 'import' directive. ```conffile import mysnippet ``` -------------------------------- ### Basic dbsqlite Handler Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/dbsqlite/README.md Configures the dbsqlite handler to use a specified SQLite database file. ```conffile dbsqlite DATABASE ``` -------------------------------- ### Load whoami handler in atomdns Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/whoami/README.md Load the whoami handler in your atomdns configuration. This snippet shows the basic configuration to enable the handler for a domain. ```conffile example.org { whoami } ``` -------------------------------- ### Empty Handler Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/empty/README.md The syntax for the empty handler is simply 'empty'. This handler is automatically invoked for unknown configurations. ```text empty ``` -------------------------------- ### Multiple Zones in a Single Block Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/man/atomdns-conffile.5.md Illustrates an alternative syntax where multiple zones can be specified within a single handler block. ```conffile example.org org { whoami } ``` -------------------------------- ### Enable NSID Handler Configuration Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/nsid/README.md Configure the nsid handler in your Caddyfile to add a custom string to the NSID record. This string will be appended to all DNS replies. ```conffile example.org { nsid Use the force whoami } ``` -------------------------------- ### Enable ECS Handler in Caddyfile Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/ecs/README.md This snippet shows how to enable the ECS handler in your Caddyfile configuration. It is typically used in conjunction with other handlers like 'whoami' for testing or demonstration purposes. ```conffile example.org { ecs whoami } ``` -------------------------------- ### Enable Metrics Gathering Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/metrics/README.md Enables metrics gathering for the AtomDNS server. This is the default behavior if not explicitly disabled. ```txt metrics ``` -------------------------------- ### GeoIP Handler Configuration Syntax Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/geoip/README.md Defines the syntax for configuring the geoip handler in Corefile. Specifies database files for city and ASN lookups. ```config geoip { city DBFILE4 [DBFILE6] asn DBFILE4 [DBFILE6] } ``` -------------------------------- ### Convert v1 RR to v2 RR Source: https://github.com/miekg/dns/blob/main/_doc/README-v1-to-v2.md Converts a `github.com/miekg/dns` (v1) `RR` to a `codeberg.org/miekg/dns` (v2) `RR` using string representation. This function is intended for temporary use during migration and panics on error. ```go package dnsrr import ( dnsv2 "codeberg.org/miekg/dns" dnsv1 "github.com/miekg/dns" ) // RRv1tov2 converts github.com/miekg/dns (v1) RR to codeberg.org/miekg/dns (v2) RR. // Typically used in providers that still use v1. // Note: this function is not efficient. It converts via string representation. // Use it until you are able to convert to v2 fully. // Note: Panics on error. func RRv1tov2(rrv1 dnsv1.RR) dnsv2.RR { rrv2, err := dnsv2.New(rrv1.String()) if err != nil { panic("Failed to convert RR to v2: " + err.Error()) } return rrv2 } ``` -------------------------------- ### Define a reusable snippet Source: https://github.com/miekg/dns/blob/main/cmd/atomdns/handlers/import/README.md This shows how to define a reusable snippet named 'mysnippet'. The content within the parentheses and curly braces can be invoked later using 'import mysnippet'. ```conffile (mysnippet) { ... } ```