Skip to content

CoreDNS

homepage-banner

Introduction

CoreDNS is a DNS server. It is written in Go.

CoreDNS is different from other DNS servers, such as (all excellent) BIND, Knot, PowerDNS and Unbound (technically a resolver, but still worth a mention), because it is very flexible, and almost all functionality is outsourced into plugins.

Plugins can be stand-alone or work together to perform a “DNS function”. https://coredns.io/manual/toc/

Configuring CoreDNS

CoreDNS is configured using a Corefile, which is a text file that defines the DNS zones and how they are resolved. The Corefile consists of a series of blocks, each of which is enclosed in curly braces. Each block defines a DNS zone and how it is resolved. Here is an example of a simple Corefile:

. {
    forward . 8.8.8.8
}

In this example, the . block defines the root DNS zone and the forward plugin is used to forward requests to the Google DNS server at 8.8.8.8.

Using CoreDNS Plugins

CoreDNS provides a wide variety of plugins that can be used to customize its behavior. Here are some examples of common plugins:

Hosts Plugin

The hosts plugin allows you to define DNS records using a hosts file format. Here’s an example Corefile that uses the hosts plugin:

. {
    hosts {
        10.0.0.1 example.com
    }
}

In this example, any request for example.com will be resolved to 10.0.0.1.

Proxy Plugin

The proxy plugin allows you to serve DNS requests by proxying them to another DNS server. Here’s an example Corefile that uses the proxy plugin:

. {
    proxy . 8.8.8.8
}

In this example, any request for a DNS record that is not defined in the Corefile will be forwarded to the Google DNS server at 8.8.8.8.

Rewrite Plugin

The rewrite plugin allows you to rewrite DNS requests based on regular expressions. Here’s an example Corefile that uses the rewrite plugin:

. {
    rewrite name example.com www.example.com
    forward . 8.8.8.8
}

In this example, any request for example.com will be rewritten to www.example.com before being forwarded to the Google DNS server at 8.8.8.8.

CoreDNS on Kubernetes

coredns-on-k8s

Conclusion

CoreDNS is a powerful and flexible DNS server that can be used for a wide variety of use cases. In this blog post, we have explored how to configure CoreDNS using a Corefile and provided some examples of common plugins that can be used to customize its behavior. With CoreDNS, you can easily create a DNS server that meets your specific needs.

Reference

  • Learning CoreDNS by John Belamaric and Cricket Liu
  • https://coredns.io/
  • https://coredns.io/2017/06/08/how-queries-are-processed-in-coredns/
  • https://sysdig.com/blog/how-to-monitor-coredns/
Feedback