coredns/coredns · error

invalid type %q

Error message

invalid type %q

What it means

CoreDNS's rewrite plugin builds type-rewrite rules by looking both DNS type names up in miekg/dns's dns.StringToType map (after uppercasing the argument). If the first argument of the rule ('from' type) is not a recognized DNS RR type name, the rule cannot be constructed and construction aborts with this error. The check happens at Corefile parse/setup time, so the whole server fails to start rather than failing per-query.

Source

Thrown at plugin/rewrite/type.go:24

	"strings"

	"github.com/coredns/coredns/request"

	"github.com/miekg/dns"
)

// typeRule is a type rewrite rule.
type typeRule struct {
	fromType   uint16
	toType     uint16
	nextAction string
}

func newTypeRule(nextAction string, args ...string) (Rule, error) {
	var from, to uint16
	var ok bool
	if from, ok = dns.StringToType[strings.ToUpper(args[0])]; !ok {
		return nil, fmt.Errorf("invalid type %q", strings.ToUpper(args[0]))
	}
	if to, ok = dns.StringToType[strings.ToUpper(args[1])]; !ok {
		return nil, fmt.Errorf("invalid type %q", strings.ToUpper(args[1]))
	}
	return &typeRule{from, to, nextAction}, nil
}

// Rewrite rewrites the current request.
func (rule *typeRule) Rewrite(_ctx context.Context, state request.Request) (ResponseRules, Result) {
	if rule.fromType > 0 && rule.toType > 0 {
		if state.QType() == rule.fromType {
			state.Req.Question[0].Qtype = rule.toType
			return nil, RewriteDone
		}
	}
	return nil, RewriteIgnored
}

View on GitHub (pinned to 558c9757a9)

Solutions

  1. Fix the first 'type' argument in the rewrite rule to a valid DNS RR type name (A, AAAA, CNAME, MX, TXT, SRV, etc.)
  2. Check spelling/case — lookup uppercases the value, so case is not the issue, only the name itself
  3. Run corefile validation (coredns -conf Corefile) before deploying to catch the error at startup
  4. If the type is genuinely needed but not in StringToType, upgrade CoreDNS/dns library to a version that knows the type

Example fix

// before (Corefile)
rewrite type AA A
// after
rewrite type A AAAA
Defensive patterns

Strategy: validation

Validate before calling

func validDNSType(t string) bool { _, ok := dns.StringToType[strings.ToUpper(t)]; return ok }
// check before writing the rule: if !validDNSType(arg0) { reject }

Prevention

When it happens

Trigger: A Corefile contains a 'rewrite type' rule whose first argument (the type to match) is not a valid DNS type string, e.g. 'rewrite type foo A' or 'rewrite type CNAME' with no second argument (args[1] missing/empty makes args[0] also be checked and args[1] lookup fails on 271, but args[0] lookup fails here for garbage names).

Common situations: Typos in Corefile (e.g. 'rewrite type AA A' intending A), using pseudo-type names not present in StringToType, or truncating the two-argument form so args[1] equals the same invalid token.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of coredns/coredns@558c9757a9 (2026-09-06). Data as JSON: /api/errors/c22ec0e91dca36a8. Report an issue: GitHub.