3 DNS
3 DNS
The DNS translates Internet domain and host names to IP addresses. DNS automatically converts the
names we type in our Web browser address bar to the IP addresses of Web servers hosting those sites.
DNS implements a distributed database to store this name and address information for all public hosts on
the Internet. DNS assumes IP addresses do not change (are statically assigned rather than dynamically
assigned).
In a DNS server such as BIND (Berkeley Internet Name Domain), all information is stored in basic data
elements called resource records (RR). The resource record is usually a fully qualified domain name
(FQDN) of a host, and is broken down into multiple sections organized into a tree-like hierarchy. This
hierarchy consists of a main trunk, primary branches, secondary branches, and so on.
What is an MX record?
An MX record numerically ranks the mail servers you would prefer to receive email for a domain. The
MX record with the lowest number is preferred over the others, but you can set multiple email servers
with the same value for simple load balancing.
When the named service is started, it reads the configuration from files as described in the following table
Path Description
/etc/named.conf The main configuration file.
/etc/named/ An auxiliary directory for configuration files that are included in the main
configuration file
System Information
Domain Name = lab.local
IP address = My local IP address on enp0s3
zone "lab.local" IN {
type master;
file "forward.lab";
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "reverse.lab";
allow-update { none; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
$TTL 86400
@ IN SOA masterdns.lab.local. root.lab.local. (
2011071001 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
@ IN NS masterdns.lab.local.
@ IN A 192.168.1.29
masterdns IN A 192.168.1.29
clienta IN A 192.168.1.240
clientb IN A 192.168.1.241
Step 5: Modify the newly created Zone files – Reverse zone file
Add the following lines:
$TTL 86400
@ IN SOA masterdns.lab.local. root.lab.local. (
2011071001 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
@ IN NS masterdns.lab.local.
@ IN PTR lab.local.
masterdns IN A 192.168.1.29
158 IN PTR masterdns.lab.local.
240 IN PTR clienta.lab.local.
241 IN PTR clientb.lab.local.
Step 9: Test DNS configuration and zone files for any syntax errors
# named-checkconf /etc/named.conf
# named-checkzone lab.local /var/named/forward.lab
# named-checkzone lab.local /var/named/reverse.lab
DNS=192.168.1.29
The rndc configuration is located in /etc/rndc.conf. If the file does not exist, the utility will use the
key located in /etc/rndc.key, which was generated automatically during the installation process
using the rndc-confgen -a command.
To reload both the configuration file and zones, type the following at a shell prompt:
# rndc reload
This will reload the zones while keeping all previously cached responses, so that you can make changes to
the zone files without losing all stored name resolutions.
To reload a single zone, specify its name after the reload command, for example:
# rndc reload localhost
Finally, to reload the configuration file and newly added zones only, type:
# rndc reconfig
$TTL
The $TTL directive allows you to set the default Time to Live (TTL) value for the zone, that is,
how long is a zone record valid. Each resource record can contain its own TTL value, which
overrides this directive.
Increasing this value allows remote nameservers to cache the zone information for a longer
period of time, reducing the number of queries for the zone and lengthening the amount of time
required to propagate resource record changes.
Example: Using the $TTL directive
$TTL 1D
If the hostname value is omitted, the record will point to the last specified hostname.
“Using the A resource record”, the requests for server1.example.com are pointed to 10.0.1.3 or
10.0.1.5.
Using the A resource record
server1 IN A 10.0.1.3 IN A 10.0.1.5
CNAME
The Canonical Name record maps one name to another. Because of this, this type of record is
sometimes referred to as an alias record. It takes the following form:
alias-name IN CNAME real-name
CNAME records are most commonly used to point to services that use a common naming
scheme, such as www for Web servers. However, there are multiple restrictions for their usage:
CNAME records should not point to other CNAME records. This is mainly to avoid possible
infinite loops. CNAME records should not contain other resource record types (such as A, NS,
MX, etc.). The only exception are DNSSEC related records (that is, RRSIG, NSEC, etc.) when the
zone is signed. Other resource record that point to the fully qualified domain name (FQDN) of a
host (that is, NS, MX, PTR) should not point to a CNAME record.
“Using the CNAME resource record”, the A record binds a hostname to an IP address, while the
CNAME record points the commonly used www hostname to it.
www IN CNAME server1
MX
The Mail Exchange record specifies where the mail sent to a particular namespace controlled by
this zone should go. It takes the following form:
IN MX preference-value email-server-name
The email-server-name is a fully qualified domain name (FQDN). The preference-value allows
numerical ranking of the email servers for a namespace, giving preference to some email systems
over others. The MX resource record with the lowest preference-value is preferred over the
others. However, multiple email servers can possess the same value to distribute email traffic
evenly among them.
“Using the MX resource record”, the first mail.example.com email server is preferred to the
mail2.example.com email server when receiving email destined for the example.com domain.
example.com. IN MX 10 mail.example.com. IN MX 20 mail2.example.com
NS
The Nameserver record announces authoritative nameservers for a particular zone. It takes the
following form:
IN NS nameserver-name
The nameserver-name should be a fully qualified domain name (FQDN). Note that when two
nameservers are listed as authoritative for the domain, it is not important whether these
nameservers are secondary nameservers, or if one of them is a primary server. They are both still
considered authoritative.
PTR
The Pointer record points to another part of the namespace. It takes the following form:
last-IP-digit IN PTR FQDN-of-system
The last-IP-digit directive is the last number in an IP address, and the FQDN-of-system is a fully
qualified domain name (FQDN).
PTR records are primarily used for reverse name resolution, as they point IP addresses back to a
particular name. Refer to Section 15.2.2.4.2, “A Reverse Name Resolution Zone File” for more
examples of PTR records in use
SOA
The Start of Authority record announces important authoritative information about a namespace
to the nameserver. Located after the directives, it is the first resource record in a zone file. It takes
the following form:
When configuring BIND, all times are specified in seconds. However, it is possible to use
abbreviations when specifying units of time other than seconds, such as minutes (M), hours (H),
days (D), and weeks (W). Following table, “Seconds compared to other time units” shows an
amount of time in seconds and the equivalent time in another format.
$ORIGIN example.com.
$TTL 86400
@ IN SOA dns1.example.com. hostmaster.example.com. (
2001062501 ; serial
21600 ; refresh after 6 hours
3600 ; retry after 1 hour
604800 ; expire after 1 week
86400 ) ; minimum TTL of 1 day
; Comments
; Comments
IN NS dns1.example.com.
IN NS dns2.example.com.
dns1 IN A 10.0.1.1
dns2 IN A 10.0.1.2
dns1 IN CNAME server1
multiple-a-records
When a resolver queries for these records, BIND will rotate them and respond to the query with
the records in a different order. In the example above, clients will randomly receive records in the
order 1,2, 3; 2, 3, 1; and 3, 1, 2. Most clients will use the first record returned and discard the rest.
# named-checkconf /etc/named.conf
Exmaple :
squid.linuxtechi.com IN NS ns2.linuxtechi.com
ns2.linuxtechi.com IN A 192.168.1.51