COREDNS-FORWARD(7)
π¦ COREDNS-FORWARD(7) π¦
okay bestie, welcome to the coredns-forward glow-up π
this is the manual page for the forward plugin, and it's genuinely one of the most iconic little pieces of CoreDNS. grab a strawberry drink π and let's get into it.
β¨ NAME β¨
forward β literally facilitates proxying DNS messages to upstream resolvers. that's it, that's the whole job, and it does it so well π«Ά
πΈ DESCRIPTION πΈ
so the forward plugin re-uses already opened sockets to the upstreams. no cap β it's not out here opening a fresh socket for every single query like some kind of amateur. it reuses what it's got, which is main character energy π
it supports UDP, TCP, DNS-over-TLS, and DNS-over-HTTPS, and it uses in band health checking. yes bestie, all of those. slay π
π the health check situation π
okay so here's the tea β when forward detects an error, a health check is performed. and this check runs in a loop β performing each check at a 0.5s interval for as long as the upstream reports unhealthy. like it is not going to stop checking on that upstream, it's committed π
once the upstream is healthy again, we stop health checking β until the next error shows up. you know the vibe: it's chill until it's not π
the health checks use a recursive DNS query (. IN NS) to get upstream health. and here's the important bit β any response that is not a network error (REFUSED, NOTIMPL, SERVFAIL, etc) is taken as a healthy upstream. so don't come for it just because the answer was spicy, as long as it's not a network error we're calling that healthy β¨
the health check uses the same protocol as specified in TO. that part matters, bestie, iykyk π₯
and ifmax_failsis set to0, no checking is performed and upstreams will always be considered healthy. literally zero vibes checks. it's just trusting everyone, fr fr π
π when everything is down π
when all upstreams are down, it assumes health checking as a mechanism has failed and will try to connect to a random upstream β which may or may not work. ngl that's the "well, we tried everything, roll the dice" moment π²π
β¨ SYNTAX β¨
Okay so the simplest possible forwarder setup? Literally just this:
forward FROM TO...
FROMis the base domain that gets matched before a request gets forwarded. One tiny catch though: domains using CIDR notation that expand into multiple reverse zones aren't fully supported β only the first expanded zone gets used. πTO...are the destination endpoints you're forwarding to. TheTOsyntax lets you specify a protocol βtls://9.9.9.9,quic://94.140.14.14,https://9.9.9.9(heads up, DoH defaults to the/dns-querypath) ordns://(or literally no protocol at all) for plain DNS. The number of upstreams is capped at 15. Besides IP addresses and files (like/etc/resolv.conf),TOcan also be a hostname (e.g.,my-dns.svc.cluster.local). Hostnames get resolved to IP addresses at startup and are treated as absolute DNS names even without a trailing dot β resolver search domains are not applied. Peep theresolveroption below for that. π«Ά
Multiple upstreams get randomized (see policy) on first use. And when a healthy proxy returns an error during the exchange, the next upstream in the list gets tried. Slay.
π Extra knobs (the expanded syntax) π
There's a whole expanded syntax if you want more control, bestie:
forward FROM TO... {
except IGNORED_NAMES...
force_tcp
prefer_udp
expire DURATION
max_age DURATION
max_idle_conns INTEGER
read_timeout DURATION
max_fails INTEGER
max_connect_attempts INTEGER
doh_method GET|POST
tls CERT KEY CA
tls_servername NAME
policy random|round_robin|sequential
health_check DURATION [no_rec] [domain FQDN]
max_concurrent MAX
next RCODE_1 [RCODE_2] [RCODE_3...]
failfast_all_unhealthy_upstreams
failover RCODE_1 [RCODE_2] [RCODE_3...]
source_address IP
resolver IP[:PORT] [IP[:PORT]...]
}
FROMandTO...β same as above, no notes. πIGNORED_NAMESinexceptis a space-separated list of domains to exclude from forwarding. Anything that doesn't match one of these names just gets passed through.force_tcpβ use TCP even when the request comes in over UDP.prefer_udpβ try UDP first even when the request comes in over TCP. If the response is truncated (TC flag set in the response) then it does another attempt over TCP. And if you somehow specify bothforce_tcpandprefer_udp,force_tcptakes precedence, periodt. Also important: neither of these options changes an explicitly configured DoT, DoQ, or DoH upstream transport. β¨max_failsis the number of subsequent failed health checks needed before an upstream is considered down. If it's0, the upstream will never be marked as down (and won't be health checked at all). Default is2.max_connect_attemptscaps the total number of upstream connect attempts performed for a single incoming DNS request. The default cap is twice the number of configured upstreams, which lets you do two complete passes when all upstreams are healthy. Set it to0to disable the per-request cap.expire DURATIONβ expire (cached) connections after this time. Default is10s.max_age DURATIONβ stop reusing and replace connections after this total lifetime. The default is0, which disables maximum connection age. A non-zero value must not be less thanexpire. π¨doh_method GET|POSTβ whether to use the GET or POST HTTP method for DoH requests (defaults toPOST).max_idle_conns INTEGERβ maximum number of idle connections to cache per upstream for reuse. Default is0, which means unlimited. Also fyi, DoQ multiplexes streams over one cached connection per upstream.read_timeout DURATIONβ the per-query read timeout applied to each upstream while waiting for a response. Default is2s. Bump this up if your upstreams legitimately take longer than 2s to answer (like slow recursive resolutions that would otherwise show up as SERVFAIL/timeouts). Ngl though, this timeout applies to each upstream individually, so big values reduce the time available to retry other upstreams within a single query. πtls CERT KEY CAβ define the TLS properties for the TLS connection. You can provide from 0 to 3 arguments, with these meanings:tlsβ no client authentication is used, and the system CAs are used to verify the server certificate.tls CAβ no client authentication is used, and the fileCAis used to verify the server certificate.tls CERT KEYβ client authentication is used with the specified cert/key pair. The server certificate is verified with the system CAs.tls CERT KEY CAβ client authentication is used with the specified cert/key pair. The server certificate is verified using the specifiedCAfile.
CoreDNS sets the minimum TLS version to TLS 1.2 for DoT and DoH. DoQ uses TLS 1.3 as required by QUIC. The maximum TLS version, TLS 1.2 cipher suites, and key exchange mechanisms all use the Go crypto/tls defaults. π
tls_servername NAMElets you set a server name in the TLS configuration β for instance9.9.9.9needs this set todns.quad9.net. It is strongly recommended when using DoT, DoQ, or DoH with an IP address whose certificate identifies a DNS name instead of that IP address. π
Per destination endpoint TLS server name indication is possible in the form of tls://9.9.9.9%dns.quad9.net or quic://9.9.9.9%dns.quad9.net. tls_servername must not be specified when using per destination endpoint TLS server name indication, because it would introduce a clash between server name indication specifications. If a destination endpoint is to be reached via a port other than 853, then the port must be appended to the end of the destination endpoint specifier. In the case of port 10853, the above string would be: tls://9.9.9.9%dns.quad9.net:10853. π¦
policyspecifies the policy used for selecting upstream servers. Default israndom.randomβ a policy that implements random upstream selection.round_robinβ a policy that selects hosts based on round robin ordering.sequentialβ a policy that selects hosts based on sequential ordering.
health_checkconfigures the behaviour of health checking for the upstream servers:<duration>β use a different duration for health checking. The default duration is0.5s.no_recβ optional argument that sets the RecursionDesired-flag of the dns-query used in health checking tofalse. The flag istrueby default.domain FQDNβ set the domain name used for health checks toFQDN. If not configured, the domain name used for health checks is.. π
max_concurrent MAXwill limit the number of concurrent queries toMAX. Any new query that would push the number of concurrent queries aboveMAXgets a REFUSED response. That response does not count as a health failure. When picking a value forMAX, choose a number at least greater than the expected upstream query rate Γ latency of the upstream servers. And as an upper bound, keep in mind each concurrent query uses about 2kb of memory. π§nextβ if the RCODE (i.e.NXDOMAIN) is returned by the remote, then execute the next plugin. If no next plugin is defined, or the next plugin isn't a forward plugin, this setting is ignored.next_on_nodataβ ifNOERRORis returned by the remote but an empty answer section (NODATA) was provided, execute the next forward plugin, if configured.failfast_all_unhealthy_upstreamsβ determines how requests are handled when all upstream servers are unhealthy and unresponsive to health checks. Enabling this option immediately returns SERVFAIL responses for all requests. By default, requests are sent to a random upstream.failoverβ by default, when a DNS lookup fails to return a DNS response (e.g. timeout), forward will attempt a lookup on the next upstream server. Thefailoveroption makes forward do the same for any response with a response code matching an RCODE (e.g.SERVFAILγREFUSED).NOERRORcannot be used. If all upstreams have been tried, the response from the last attempt is returned. πsource_address IPβ set the address to use for all outgoing requests as the source address (health check query included). This works reliably when upstream servers are reachable from that address. But if upstream servers belong to different networks, be careful β the selected source address may not be valid for all upstreams, and responses may fail if return routing isn't properly configured. In those cases, make sure the upstream servers have a route back to the configured source address. πresolver IP[:PORT] [IP[:PORT]...]β specifies one or more DNS resolver addresses used to resolve hostname-basedTOendpoints at startup. If not specified, the system resolver (/etc/resolv.conf) is used. Each address is either a bare IP (IPv4 or IPv6, port53assumed) orIP:port. You can list multiple addresses for redundancy. β
The client certificate, key, and CA configuration is global for one forward stanza. For DoT and DoQ, use the %servername endpoint form when upstreams in the same stanza require different TLS server names. π
On each endpoint, the timeouts for communication are set like this:
- The DNS and DoT dial timeout defaults to
30sand can decrease automatically down to1sbased on early results. The DoQ handshake timeout is5s. - DoT connection setup (TCP dial plus TLS handshake) is additionally bounded by the remaining 5s forwarding retry window, or an earlier request deadline. When retries are enabled, each setup attempt is limited to half of the window available at the start of forwarding (at most
2.5s), so a stalled handshake leaves time to try a fresh connection. Withmax_connect_attemptsset to1, setup may use the full remaining window. Failed handshakes close the connection; successful connections remain reusable. These setup limits do not change the DNS exchange read timeout. π - The read timeout is static at
2s.
π¦ METADATA π¦
The forward plugin will publish the following metadata, if the metadata plugin is also enabled:
forward/upstreamβ the upstream used to forward the request. π
π METRICS π
Okay so if monitoring is enabled (via the prometheus plugin) then these metrics get exported, and honestly? They're giving observability icon. Let's go through them one by one:
coredns_forward_healthcheck_broken_total{}β counts every time all the upstreams are unhealthy, and we're just randomly (this always uses therandompolicy, no cap) spraying queries at an upstream. Chaos mode, but make it measured.coredns_forward_max_concurrent_rejects_total{}β count of queries that got rejected because the number of concurrent queries was at maximum. Shut down, respectfully.coredns_proxy_request_duration_seconds{proxy_name="forward", to, rcode}β histogram per upstream, RCODE.coredns_proxy_healthcheck_failures_total{proxy_name="forward", to, rcode}β count of failed health checks per upstream.coredns_proxy_conn_cache_hits_total{proxy_name="forward", to, proto}β count of connection cache hits per upstream and protocol.coredns_proxy_conn_cache_misses_total{proxy_name="forward", to, proto}β count of connection cache misses per upstream and protocol.
So real quick, what are those labels? to is one of the upstream servers (that's the TO from the config, bestie), rcode is the returned RCODE from the upstream, and proto is the transport protocol like udp, tcp, tcp-tls, quic, https.
π₯ the deprecated ones (a moment of silence)
The following metrics have recently been deprecated, and here's the glow-up for each:
coredns_forward_healthcheck_failures_total{to, rcode}- Can be replaced with
coredns_proxy_healthcheck_failures_total{proxy_name="forward", to, rcode}
- Can be replaced with
coredns_forward_requests_total{to}- Can be replaced with
sum(coredns_proxy_request_duration_seconds_count{proxy_name="forward", to})
- Can be replaced with
coredns_forward_responses_total{to, rcode}- Can be replaced with
coredns_proxy_request_duration_seconds_count{proxy_name="forward", to, rcode}
- Can be replaced with
coredns_forward_request_duration_seconds{to, rcode}- Can be replaced with
coredns_proxy_request_duration_seconds{proxy_name="forward", to, rcode}
- Can be replaced with
π EXAMPLES π
This is the part where it gets fun. Buckle up.
the classic: proxy everything for a zone to a different port
Proxy all requests within example.org. to a nameserver running on a different port:
example.org {
forward . 127.0.0.1:9005
}
subdomain routing, and the whole "order matters" thing (iykyk)
Send all requests within lab.example.local. to 10.20.0.1, all requests within example.local. (and not in lab.example.local.) to 10.0.0.1, all others requests to the servers defined in /etc/resolv.conf, and caches results. Note that a CoreDNS server configured with multiple forward plugins in a server block will evaluate those forward plugins in the order they are listed when serving a request. Therefore, subdomains should be placed before parent domains β otherwise subdomain requests will be forwarded to the parent domain's upstream. Accordingly, in this example lab.example.local is before example.local, and example.local is before ..
. {
cache
forward lab.example.local 10.20.0.1
forward example.local 10.0.0.1
forward . /etc/resolv.conf
}
The example above is almost equivalent to the following example, except that the example below defines three separate plugin chains (and thus 3 separate instances of cache):
lab.example.local {
cache
forward . 10.20.0.1
}
example.local {
cache
forward . 10.0.0.1
}
. {
cache
forward . /etc/resolv.conf
}
load balancing, but make it multilingual (IPv6 says hi)
Load balance all requests between three resolvers, one of which has a IPv6 address:
. {
forward . 10.0.0.10:53 10.0.0.11:1053 [2003::1]:53
}
everything except that one zone
Forward everything except requests to example.org:
. {
forward . 10.0.0.10:1234 {
except example.org
}
}
Proxy everything except example.org using the host's resolv.conf's nameservers:
. {
forward . /etc/resolv.conf {
except example.org
}
}
DoT girl summer π¦
Proxy all requests to 9.9.9.9 using the DNS-over-TLS (DoT) protocol, and cache every answer for up to 30 seconds. Note the tls_servername is mandatory if you want a working setup, as 9.9.9.9 can't be used in the TLS negotiation. Also set the health check duration to 5s to not completely swamp the service with health checks.
. {
forward . tls://9.9.9.9 {
tls_servername dns.quad9.net
health_check 5s
}
cache 30
}
DoQ era β¨
The following example uses DNS-over-QUIC (DoQ). DoQ uses UDP port 853 by default and multiplexes concurrent queries over separate streams on one QUIC connection. The forward plugin's single-message exchange path does not support AXFR or IXFR over DoQ; those requests return NOTIMP.
. {
forward . quic://94.140.14.14 {
tls_servername dns.adguard-dns.com
health_check 5s
}
cache 30
}
DoH, same energy πΈ
The same configuration but using DNS-over-HTTPS (DoH) protocol. Note that the implementation uses the default /dns-query path (custom paths are not supported).
. {
forward . https://9.9.9.9 {
tls_servername dns.quad9.net
health_check 5s
}
cache 30
}
or configure another domain name for health check requests
. {
forward . tls://9.9.9.9 {
tls_servername dns.quad9.net
health_check 5s domain example.org
}
cache 30
}
multiple upstreams, same provider, one servername
. {
forward . tls://1.1.1.1 tls://1.0.0.1 {
tls_servername cloudflare-dns.com
health_check 5s
}
cache 30
}
multiple DoT upstreams with different tls_servernames
Or when you have multiple DoT upstreams with different tls_servernames, you can do the following:
. {
forward . 127.0.0.1:5301 127.0.0.1:5302
}
.:5301 {
forward . tls://8.8.8.8 tls://8.8.4.4 {
tls_servername dns.google
}
}
.:5302 {
forward . tls://1.1.1.1 tls://1.0.0.1 {
tls_servername cloudflare-dns.com
}
}
chaining with next (the try-again era)
The following would try 1.2.3.4 first. If the response is NXDOMAIN, try 5.6.7.8. If the response from 5.6.7.8 is NXDOMAIN, try 9.0.1.2.
. {
forward . 1.2.3.4 {
next NXDOMAIN
}
forward . 5.6.7.8 {
next NXDOMAIN
}
forward . 9.0.1.2 {
}
}
In the following example, if the response from 1.2.3.4 is SERVFAIL or REFUSED, it will try 5.6.7.8. If the response from 5.6.7.8 is SERVFAIL or REFUSED, it will try 9.0.1.2.
. {
forward . 1.2.3.4 5.6.7.8 9.0.1.2 {
policy sequential
failover SERVFAIL REFUSED
}
}
hostname upstream + a specific resolver to look it up π
Forward to an upstream identified by hostname, using a specific resolver to look it up:
. {
forward . dns.example.local {
resolver 10.0.0.1
}
}
π SEE ALSO π
Go read the RFCs, they're literally the receipts:
RFC 7858β¨https://www.rfc-editor.org/info/rfc7858/β© for DNS over TLS.RFC 8484β¨https://www.rfc-editor.org/info/rfc8484/β© for DNS over HTTPS.RFC 9250β¨https://www.rfc-editor.org/info/rfc9250/β© for DNS over QUIC.
and that's the whole page, bestie π«Ά This one's from CoreDNS, dated October 2026, and the page itself is COREDNS-FORWARD(7) β go forth and forward responsibly, mwah π
π
π¦ where this page comes from
- opensuse-leap 16.0: coredns-extras 1.15.0-bp160.1.1 Β· Apache-2.0 AND MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms