BIND is the DNS server that powers the internet, and it’s notorious for its arcane configuration syntax.
Let’s see it in action. Imagine we have a domain, example.com, and we want to:
- Serve a website from
www.example.com. - Have an IPv6 address for
example.comitself. - Point
mail.example.comto our mail server. - Designate
example.comas the primary mail handling domain.
Here’s a snippet from a BIND zone file for example.com:
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023102701 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ; minimum TTL
)
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
@ IN A 192.0.2.1
@ IN AAAA 2001:db8::1
www IN CNAME @
mail IN MX 10 mail.example.com.
IN A 192.0.2.2
This file tells BIND how to respond when asked about example.com.
The $TTL directive sets the default Time To Live for records in this zone. A SOA (Start of Authority) record is mandatory, providing administrative information about the zone. NS records declare the authoritative name servers for the domain.
Now, let’s break down the other records:
@ IN A 192.0.2.1: The@symbol is a shorthand for the zone’s origin, which isexample.comin this case. This is anArecord, mapping the hostnameexample.comto an IPv4 address. When someone looks upexample.com, BIND will tell them to go to192.0.2.1.@ IN AAAA 2001:db8::1: Similarly, thisAAAArecord mapsexample.comto an IPv6 address,2001:db8::1. This is crucial for modern internet connectivity.www IN CNAME @: ThisCNAME(Canonical Name) record means thatwww.example.comis an alias forexample.com. If you try to accesswww.example.com, BIND will first resolveexample.com(to192.0.2.1and2001:db8::1) and return those addresses. This is useful for pointing multiple hostnames to the same IP without duplicating records.mail IN MX 10 mail.example.com.: This is anMX(Mail Exchanger) record. It specifies which server handles email for the domain. The10is the preference value; lower numbers mean higher preference. So,mail.example.comis the preferred mail server.mail IN A 192.0.2.2: ThisArecord provides the IPv4 address for themail.example.comserver itself, allowing other mail servers to connect to it.
The most surprising thing about DNS records is how much flexibility there is in their definition, and how simple names can hide complex relationships. For instance, a CNAME record can point to any other hostname, not just the zone origin, and MX records can point to hostnames that don’t have A or AAAA records themselves, as long as another server (often the one handling the MX record’s hostname) is configured to accept mail for that domain.
BIND’s configuration is all about defining these relationships. The IN part signifies the Internet class, which is standard. The key is understanding the record types (A, AAAA, CNAME, MX, NS, SOA) and how they map hostnames to IP addresses, other hostnames, or specific services like mail. The serial number in the SOA record is critical; it must be incremented every time you change the zone file, otherwise, secondary DNS servers won’t pick up the changes.
The next concept you’ll grapple with is DNSSEC, securing your zones against spoofing and ensuring data integrity.