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:

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:

  1. First, add the CoreDNS repository to your Debian system. To do this, create a new file named coredns.list in the /etc/apt/sources.list.d/ directory:

    sudo nano /etc/apt/sources.list.d/coredns.list
    

    Add the following line to the file:

    deb https://packagecloud.io/coredns/coredns/debian/ stretch main
    

    Save and exit the file.

  2. Download and add the GPG key for the CoreDNS repository:

    curl -L https://packagecloud.io/coredns/coredns/gpgkey | sudo apt-key add -
    
  3. Update the package list:

    sudo apt-get update
    
  4. Install 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.

  1. Open the Corefile configuration file in a text editor:

    sudo nano /etc/coredns/Corefile
    
  2. Edit 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.

  3. Create a forward zone file for the example.com domain:

    sudo nano /etc/coredns/example.com.db
    

    Add 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.2
    

    Save and exit the file.

  4. 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.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!