1. Introduction
CoreDNS is a flexible, extensible open-source DNS server. It supports a variety of protocols and storage backends, making it an ideal choice for building modern, customizable DNS infrastructure. This article explains how to install and configure CoreDNS so you can quickly set up a powerful and stable DNS service.
2. Steps
-
Download CoreDNS and put the binary in the bin folder. We'll use version 1.11.1 as an example. Download link: Github
wget https://github.com/coredns/coredns/releases/download/v1.11.1/coredns_1.11.1_linux_amd64.tgz tar -xvf coredns_1.11.1_linux_amd64.tgz cd coredns_1.11.1_linux_amd64 cp coredns /usr/bin/coredns -
Create the service file
vi /etc/systemd/system/coredns.serviceEnter the following content:
[Unit] Description=CoreDNS DNS server Documentation=https://coredns.io After=network.target [Service] PermissionsStartOnly=true LimitNOFILE=1048576 LimitNPROC=512 CapabilityBoundingSet=CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_BIND_SERVICE NoNewPrivileges=true User=root WorkingDirectory=~ ExecStart=/usr/bin/coredns -conf=/etc/coredns/Corefile ExecReload=/bin/kill -SIGUSR1 Restart=on-failure [Install] WantedBy=multi-user.targetAfter saving, reload the systemd configuration:
systemctl daemon-reload -
Create the Corefile configuration file
First, create a folder to hold the configuration file
mkdir /etc/corednsCreate the configuration file
vi /etc/coredns/CorefileThis is a simple configuration that uses the 114 public DNS server for name resolution and enables a few basic plugins.
. { errors log health ready forward . 114.114.114.114 cache }Save the file
-
Make sure port 53 is not in use
lsof -i:53dnsmasq occupying port 53 (common on CentOS 7) First check whether it is enabled with systemctl status dnsmasq.service. If it is, first kill -9 the process, stop it with
systemctl stop dnsmasq.service, and then disable it at boot withsystemctl disable dnsmasq.service. After disabling it, reboot the server to test and make sure the service doesn't come back up.systemd-resolved occupying port 53 (common on Ubuntu Server) First edit /etc/systemd/resolved.conf as follows:
[Resolve] DNS=114.114.114.114 DNSStubListener=noDNS sets the DNS server this machine points to; your ISP's DNS or a public DNS is recommended. DNSStubListener=no means it won't listen on port 53. Once configured, run these commands to restart the system service:
sudo systemctl daemon-reloadsudo systemctl restart systemd-resolvedCheck where the /etc/resolv.conf symlink points by runningll /etc/resolv.conf. If the symlink shows the following, no change is needed:/etc/resolv.conf -> /run/systemd/resolve/resolv.conf. Otherwise, set the symlink withsudo ln -s -f /run/systemd/resolve/resolv.conf /etc/resolv.conf. -
Enable CoreDNS at boot and start it
systemctl enable coredns systemctl start coredns
3. FAQ
Question 1: What if I still can't connect after configuring it? Answer 1: Check whether CoreDNS is listening on port 53. If it is, check whether the firewall allows access to port 53.