Root-Server Tutorial

ROOT-SERVER TUTORIAL

Setting up a DNS Server on Your netcup vServer or Root Server

Learn how to configure the DNS servers or install your own DNS server

Author:

cbhp

Last updated:

05/11/2021

Introduction

When setting up a new vServer or root server, you will get in touch with IP addresses (e.g. 127.0.0.1 or ::1), domain names (e.g. www.example.org) and the Domain Name System (DNS). A DNS server can tell you the Resource Records (RR) of a domain name. Typical RRs are A (for an IPv4 address), AAAA (for an IPv6 address), CNAME (for another domain name), TXT (for text records) and MX (for mail exchange). You can use public DNS servers (e.g. from Google or Cloudflare), or the DNS servers from netcup or set up your own DNS server. An own DNS server will be required if you want to filter traffic with whitelists/blacklists, if you want to control the DNS cache, want to keep your DNS traffic private, or want to manage an own DNS zone. This tutorial shows you how to use existing DNS servers on your netcup server and how to set up an own DNS server.

Requirements

You need a running vServer or root server from netcup where you have Ubuntu Server 20.04 LTS installed and you are logged in via a terminal as root with sudo su.

Step 1 - Apply existing DNS servers

Ubuntu 20.04 LTS is using the application "netplan" to manage the resolver configuration.

Edit the file /etc/netplan/01-netcfg.yaml and add/modify these lines:

### This file describes the network interfaces available on your system
### For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      ### Maybe here are additional entries, please keep them!
      ### ...
      nameservers:
        addresses:
          - 46.38.225.230          # netcup IPv4 DNS Resolver 1
          - 46.38.252.230          # netcup IPv4 DNS Resolver 2
          - "2a03:4000:0:1::e1e6"  # netcup IPv6 DNS Resolver 1
          - "2a03:4000:8000::fce6" # netcup IPv6 DNS Resolver 2

Then execute netplan apply to apply the modified configuration. A reboot may be necessary for some services to apply the changes.

To test if domain names can be resolved, execute dig +short www.netcup.de. The output should be 46.38.224.30.

Step 2 - Set up your own DNS server

This tutorial uses the popular open source DNS server "Bind9".

Step 2.1 - Installing

Run these commands to install the DNS server:

apt update
apt install bind9 bind9-utils bind9-dnsutils bind9-doc bind9-host
named -v

The last output should be BIND 9.16.1-Ubuntu (Stable Release) or similar.

Step 2.2 - Configuring

Edit the file /etc/bind/named.conf.options and add/modify these lines:

options {
        directory "/var/cache/bind";

        // If there is a firewall between you and nameservers you want
        // to talk to, you may need to fix the firewall to allow multiple
        // ports to talk.  See http://www.kb.cert.org/vuls/id/800113

        // If your ISP provided one or more IP addresses for stable
        // nameservers, you probably want to use them as forwarders.
        // Uncomment the following block, and insert the addresses replacing
        // the all-0's placeholder.

        forwarders {
                46.38.225.230;        // netcup IPv4 DNS Resolver 1
                46.38.252.230;        // netcup IPv4 DNS Resolver 2
                2a03:4000:0:1::e1e6;  // netcup IPv6 DNS Resolver 1
                2a03:4000:8000::fce6; // netcup IPv6 DNS Resolver 2
        };

        //========================================================================
        // If BIND logs error messages about the root key being expired,
        // you will need to update your keys.  See https://www.isc.org/bind-keys
        //========================================================================
        dnssec-validation auto;

        // Restrict service to localhost only
        listen-on port 53 { 127.0.0.1; };
        listen-on-v6 port 53 { ::1; };

        // Adjust it to your needs
        max-cache-size 1024m;

        recursion yes;
        allow-recursion { 127.0.0.0/8; };
};

Run the command named-checkconf to ensure the Bind9 configuration file is correct. If there is no output, everything is fine, else please correct the errors in the configuration file.

Restart the Bind9 service: systemctl restart named. To test if domain names can be resolved via your own DNS server, execute dig +short www.netcup.de @127.0.0.1. The last part (@127.0.0.1) uses your local DNS server explicitly instead of the default one. The output should be 46.38.224.30.

Step 2.2 - Set your DNS server as new default

Edit the file /etc/netplan/01-netcfg.yaml and add/modify these lines:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      # Maybe here are additional entries, please keep them!
      # ...
      nameservers:
        addresses:
          - 127.0.0.1 # Own local DNS Resolver

Then execute netplan apply to apply the modified configuration. A reboot may be necessary for some services to apply the changes.

To test if domain names can be resolved, execute dig +short www.netcup.de. The output should be 46.38.224.30.

Conclusion

You either applied existing DNS servers or set up and configured your own local DNS server. For your own local DNS server, you can optimize cache size and cache times if necessary and configure some logging. By default, Bind9 logs to syslog.

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributor's Certificate of Origin

By making a contribution to this project, I certify that:

  1. The contribution was created in whole or in part by me and I have the right to submit it under the license indicated in the file; or

  2. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same license (unless I am permitted to submit under a different license), as indicated in the file; or

  3. The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

  4. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the license(s) involved.

Published 05/11/2021 by cbhp

Submit your tutorial

Get 60€ netcup vouchers for every published tutorial.