CoreDNS
We saw why we need a DNS server and how it can help manage name resolution in large environments with many hosts and how you can configure your hosts to point to a DNS server. Now we'll see how to configure a host as a DNS server.
There are many DNS server solutions out there, but we'll focus on CoreDNS which is used in Kubernetes.
The CoreDNS binaries can be downloaded from the Github page or as a Docker image. Let's go the traditional way. Download the binary using curl or wget and extract it. You'll get the coredns executable.
wget https://github.com/coredns/coredns/releases/download/v1.11.2/coredns_1.11.2_linux_amd64.tgz
tar -xzvf coredns_1.11.2_linux_amd64.tgz
chmod +x coredns
To start CoreDNS just running the binary should work, but if another DNS server is using port 53 you'll get this error.
./coredns
Listen: listen tcp :53: bind: permission denied
# Change the port and it will work
./coredns -dns.port=1053
.:1053
CoreDNS-1.11.2
linux/amd64, go1.20.14, 8868454
Now we haven't specified the IP for hostname mappings. For that you need to provide some configurations. There are several ways to do this, we'll see one. First, we put all entries in the DNS server's /etc/hosts file.
Then we configure CoreDNS to use that file. CoreDNS loads its configuration from a file called Corefile. Here's a simple configuration that instructs CoreDNS to fetch the IP for hostname mappings from the /etc/hosts file. When the DNS server runs, it now picks up the IPs and names from the /etc/hosts file on the server.
CoreDNS also supports other ways to configure DNS entries through plugins. We'll see the plugin it uses for Kubernetes in a later section.