Installing CoreDNS on Debian Latest
CoreDNS is a flexible DNS server that can be used as an alternative to traditional DNS servers such as BIND or NSD. In this tutorial, we will guide you through the installation of CoreDNS on Debian Latest.
Prerequisites
Before starting with the installation, make sure you have the following prerequisites:
- Access to a Debian Latest server with root privileges
- A user account with administrative privileges
- Access to the internet
Step 1: Update the System
Before installing CoreDNS, it's a good practice to update the system with the latest patches and security updates. You can do this by running the following command:
sudo apt-get update && sudo apt-get upgrade -y
Step 2: Install CoreDNS
You can install CoreDNS using the Debian package manager (apt). To do this, follow these steps:
First, add the CoreDNS repository to your Debian system. To do this, create a new file named
coredns.listin the/etc/apt/sources.list.d/directory:sudo nano /etc/apt/sources.list.d/coredns.listAdd the following line to the file:
deb https://packagecloud.io/coredns/coredns/debian/ stretch mainSave and exit the file.
Download and add the GPG key for the CoreDNS repository:
curl -L https://packagecloud.io/coredns/coredns/gpgkey | sudo apt-key add -Update the package list:
sudo apt-get updateInstall CoreDNS:
sudo apt-get install coredns -y
Wait for the installation to complete.
Step 3: Configure CoreDNS
After installing CoreDNS, you need to configure it to work properly. By default, CoreDNS listens on the port 53. You can change this by editing the CoreDNS configuration file.
Open the
Corefileconfiguration file in a text editor:sudo nano /etc/coredns/CorefileEdit the file to define the DNS zones that CoreDNS will manage. For example, to define a zone for
example.com, add the following lines:example.com { file /etc/coredns/example.com.db }Save and exit the file.
Create a forward zone file for the
example.comdomain:sudo nano /etc/coredns/example.com.dbAdd the following example contents to the file:
$ORIGIN example.com. $TTL 86400 example.com. IN SOA ns1.example.com. hostmaster.example.com. ( 2022010100 ; Serial 3600 ; Refresh 1800 ; Retry 604800 ; Expire 86400 ; Minimum TTL ) example.com. IN NS ns1.example.com. ns1 IN A 192.168.1.1 www IN A 192.168.1.2Save and exit the file.
Restart CoreDNS to apply the changes:
sudo systemctl restart coredns
Conclusion
You have successfully installed and configured CoreDNS on Debian Latest. You can now use CoreDNS as an alternative to traditional DNS servers. Remember to update the DNS records when necessary and make backups of the configuration files.