Chapter 7. Manipulating Queries and Responses
CoreDNS gives you a great deal of control over what happens to a request as it goes through the plug-in chain, and what response is provided to the client. This allows you to tailor the DNS behavior to your particular environment and use cases. For example, you can easily generate standard names within specific zones using the template
plug-in, and you can transparently redirect traffic using the rewrite
plug-in.
This chapter discusses a few of the most commonly used plug-ins for manipulating requests and responses in this way.
The template Plug-in
The template
plug-in allows you to fabricate answers based solely upon the request. A common use case for this is the creation of answers to PTR queries, without having to actually write them all out in a zone file, as shown in Example 7-1.1
Example 7-1. Answering PTR queries with template
example.com:5300 in-addr.arpa:5300 { # Match host-a-b-c-d.example.com A requests and return a.b.c.d template IN A example.com { match (^|[.])host-(?P<a>[0-9]*)-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*)↵ [.]example[.]com[.]$ answer "{{ .Name }} 60 IN A {{ .Group.a }}.{{ .Group.b }}.{{ .Group.c }}.↵ {{ .Group.d }}" fallthrough } # Match d.c.b.a.in-addr.arpa PTR requests and return host-a-b-c-d.example.com template IN PTR in-addr.arpa { match ^(?P<d>[0-9]*)[.](?P<c>[0-9]*)[.](?P<b>[0-9]*)[.](?P<a>[0-9]*)↵ [.]in-addr[.]arpa[.]$ answer "{{ ...
Get Learning CoreDNS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.