cnamefollow
Name
cnamefollow - re-resolves CNAME targets through CoreDNS's own server blocks when the target falls within configured authoritative zones.
Description
In split-horizon DNS environments, an external domain may CNAME into an internal zone (e.g., app.example.com CNAME app.internal.corp.). When the upstream resolver chases this CNAME, it resolves the target against the upstream resolver DNS rather than the internal authoritative servers, returning either the wrong answer or NXDOMAIN.
CoreDNS does not natively re-evaluate CNAME targets across server blocks. The cnamefollow plugin solves this by intercepting responses from the upstream resolver, detecting CNAME targets that fall within configured authoritative zones, and re-resolving those targets through CoreDNS's own server.ServeDNS() — which routes to the correct server block for that zone.
The plugin preserves the full CNAME chain in the response. It does not flatten or strip CNAME records.
How It Works
- The upstream resolver (via
forward) returns a response containing a CNAME
- The plugin checks if any CNAME target is a subdomain of the configured zones
- If matched, it calls
upstream.Lookup() which re-enters CoreDNS's server routing, matching the appropriate server block for the target zone
- The re-resolved answer is appended to the original CNAME, producing a complete response
- If no CNAME targets match, or if the re-resolution fails, the original response is returned unmodified
Syntax
cnamefollow ZONE [ZONE...]
ZONE — one or more authoritative zone names to match CNAME targets against
Example
internal.example.com {
forward . 10.0.0.1 10.0.0.2
cache 300
}
corp.example.com {
forward . 10.0.0.1 10.0.0.2
cache 300
}
.:53 {
forward . 169.254.169.253
cnamefollow internal.example.com corp.example.com
cache 300
}
Given the following DNS records:
app.external.net. CNAME app.internal.example.com. (public)
app.internal.example.com. CNAME k8s-elb.amazonaws.com. (internal, AD)
k8s-elb.amazonaws.com. A 10.1.2.3 (internal, AD)
A query for app.external.net will:
- Match the
. server block, forward to 169.254.169.253 (VPC resolver)
- VPC resolver returns:
CNAME app.internal.example.com. + NXDOMAIN (or wrong public answer)
- Plugin detects
app.internal.example.com. is in internal.example.com zone
- Re-resolves through the
internal.example.com server block → internal DNS servers
- Returns the complete chain:
app.external.net. 30 IN CNAME app.internal.example.com.
app.internal.example.com. 30 IN CNAME k8s-elb.amazonaws.com.
k8s-elb.amazonaws.com. 30 IN A 10.1.2.3
Behavior Notes
- Only operates in the server block where it is configured (typically the
. catch-all)
- Only triggers when a CNAME target is a subdomain of a configured zone
- Queries for type
CNAME are passed through without retry (preserves CNAME-only responses for DCV and similar tooling)
- If re-resolution fails or returns no answers, the original upstream response is returned unmodified
- Queries with no CNAME records, or CNAMEs not targeting configured zones, pass through with zero overhead
Building
Add to CoreDNS plugin.cfg before forward:
cnamefollow:github.com/robertlestak/coredns-cnamefollow
forward:forward
Then:
go generate && go build
Why This Exists
See coredns/coredns#1864 — CoreDNS does not chase CNAMEs across server block boundaries. This is a known limitation with no upstream fix as of CoreDNS v1.14.2. In enterprise split-horizon DNS environments where external domains CNAME into internal zones, this causes resolution failures or incorrect answers.