Overview
DNS (Domain Name System) maps hostnames to IP addresses using a client/server model. As a core network service, DNS is fundamental to the global Internet and is also widely used in enterprise networks.
Functions of a DNS Server
- Forward lookup: find the IP address for a given hostname
- Reverse lookup: find the hostname for a given IP address
DNS Distributed Data Structure
DNS data is organized hierarchically and distributed across authoritative servers for different zones. This enables scalable resolution across the global namespace.
DNS Query Methods
Recursive query: method used by most clients when asking a DNS server to resolve a name.
Iterative query: method used by most DNS servers when querying other DNS servers.
Types of DNS Servers
- Caching name server
- Primary (master) name server
- Secondary (slave) name server
BIND Basics
BIND (Berkeley Internet Name Daemon)
Official site: https://www.isc.org/
BIND server programs:
Main daemon: /usr/sbin/named
Service script: /etc/init.d/named
Default port: 53
Main configuration file: /etc/named.conf
Zone data files location (chroot): /var/named/chroot/var/named/
Named Configuration File Example (/etc/named.conf)
options { # options
listen-on port 53 { 127.0.0.1; }; # listen on IPv4 loopback
listen-on-v6 port 53 { ::1; }; # listen on IPv6 loopback
directory "/var/named"; # working directory for zone files
dump-file "/var/named/data/cache_dump.db"; # cache dump
statistics-file "/var/named/data/named_stats.txt"; # statistics file
memstatistics-file "/var/named/data/named_mem_stats.txt"; # memory stats
allow-query { localhost; }; # allowed clients for queries
recursion yes; # enable recursion
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
};
Installing and Starting BIND
# Install bind package
yum install bind
# Start service
systemctl start named.service
# Enable autostart
systemctl enable named.service
Adjusting /etc/named.conf for Access
vim /etc/named.conf
# Example changes:
listen-on-v6 port 53 { any; };
allow-query { any; };
Zone Definitions (zones file)
# Forward zone example
zone "lzy.com." IN {
type master;
file "lzy.com.zone";
allow-update { none; };
};
# Reverse zone example
zone "134.168.192.in-addr.arpa" IN {
type master;
file "134.168.192.zone";
allow-update { none; };
};
Preparing Zone Files
# Copy template files
cp /var/named/named.empty /var/named/lzy.com.zone
cp /var/named/named.empty /var/named/134.192.168.zone
# Set ownership
chown :named lzy.com.zone
Forward Zone File Example
Example forward zone file for the domain. Copy and rename /var/named/named.empty to the desired zone filename and edit its contents.
$TTL 3H
@ IN SOA lzy.com. root.lzy.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns.lzy.com.
dns IN A 192.168.134.139
www IN A 192.168.134.139
Reverse Zone File
Create a reverse zone file (e.g., 137.168.192.zone) by copying the template, updating ownership, and filling in PTR records for IP-to-name mapping.
Network Interface Configuration
vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=static
IPADDR1=192.168.134.139
NETMASK=255.255.255.0
GATEWAY=192.168.134.2
DNS1=192.168.134.139
Starting and Checking the DNS Server
# Start named
systemctl start named.service
# Check named configuration syntax
named-checkconf
Client Configuration
vim /etc/resolv.conf
# Example entries
search excesoft.
nameserver 192.168.137.22
Testing the DNS Server
# On a client machine, use nslookup or dig to test name resolution
nslookup example.domain 192.168.137.22