Step 2 - Create Zonefile

A DNS Zone File is a text file that describes the DNS configuration for a domain. The zone file defines a mapping between subdomains and IP addresses. This mapping can be used for defining subdomains such as www or MX records for where mail should be delivered too.

The zone file can also contain additional settings to control aspects such as DNS Caching.

View Zone file

Output the contents of an example zone file for the domain example.com using cat db.example.com

Zone file structure

The first two lines define the domain for the zone and the (Time-To-Live) TTL for a cache of DNS requests. The next block defines the mapping between subdomains and IP addresses.

In this example, the domain has two name servers specified, ns1.example.com and ns2.external-domain.com. Name servers determine which servers can respond with the correct zone information for the particular domain. Domains should list at least two domains for redundancy.

The Zone lists one Mail Exchanger (MX) record for mail, mail.example.com. An MX record specifies a mail server responsible for accepting email messages on behalf of a recipient's domain.

A Records are the most basic type of DNS record and are used to point a domain or subdomain to an IP address. This zone file defines three, ns1 pointing to the IP 192.168.0.1, www to 192.168.0.2 and admin to 192.168.0.3

Finally, it defines one Canonical Name (CNAME) record called demo pointing to the www subdomain. A CNAME is an alias to another record.

Step 3 - Create Configuration

A structure text file defines the CoreDNS configuration. CoreDNS has a series of middleware layers that control it's behaviour and how to handle requests.

The configuration file also defines which Zone Files to load and how to respond. CoreDNS supports multiple backend data sources for zone configuration. Other scenarios will explain the additional backend data sources.

CoreDNS Configuration

By default, a file called Corefile defines the configuration. View the configuration for this scenario using cat Corefile

The configuration has a few fundamental properties. Firstly, it defines that the DNS server should listen to requests on port 2053.

Load configured defines which files to load, in this case, example.com.

All other requests are proxied to 8.8.8.8, Google's free and open DNS server. By using Google's DNS, you can ensure requests for public domains will be responded with the correct IP address.

Help

Katacoda offerings an Interactive Learning Environment for Developers. This course uses a command line and a pre-configured sandboxed environment for you to use. Below are useful commands when working with the environment.

cd <directory>

Change directory

ls

List directory

echo 'contents' > <file>

Write contents to a file

cat <file>

Output contents of file

Vim

In the case of certain exercises you will be required to edit files or text. The best approach is with Vim. Vim has two different modes, one for entering commands (Command Mode) and the other for entering text (Insert Mode). You need to switch between these two modes based on what you want to do. The basic commands are: