Setting Up DNS Server on CentOS 7
Scenario
Primary (Master) DNS Server Details:
Operating System : CentOS 7 minimal server Hostname : ns1.example.com IP Address : 10.0.0.15/24
Client Details:
Operating System : CentOS 7 Hostname : client.example.com IP Address : 10.0.0.14/24
Sequence 1. Setup Primary (Master) DNS Server
- Install bind9 packages on your server.
yum install bind bind-utils -y
- Configure DNS Server by editing
‘/etc/named.conf’
listen-on port 53 { 127.0.0.1; 10.0.0.15;}; # Master DNS IP
directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { localhost; 10.0.0.0/24;}; # IP Range
recursion yes; dnssec-enable yes; dnssec-validation yes; dnssec-lookaside auto; bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; pid-file "/run/named/named.pid"; session-keyfile "/run/named/session.key"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." IN { type hint; file "named.ca"; };
zone "example.com" IN {
type master;
file "forward.example";
allow-update { none; };
};
zone "0.0.10.in-addr.arpa" IN {
type master;
file "reverse.example";
allow-update { none; };
};
include "/etc/named.rfc1912.zones"; include "/etc/named.root.key";
- Create Zone files. Create forward and reverse zone files which we mentioned in the
‘/etc/named.conf’
- Create Forward Zone “
example”
file in‘/var/named’
directory.
- Create Forward Zone “
-
- Create Reverse Zone file “example” in ‘/var/named’ directory.
- Enable and start DNS service:
- Firewall Configuration. We must allow the DNS service default port 53 through firewall.
- Configuring Permissions, Ownership, and SELinux
- Test DNS configuration and zone files for any syntax errors
If it returns nothing, your configuration file is valid.
Check Forward zone:
# named-checkzone example.com /var/named/forward.example Sample output: zone example.com/IN: loaded serial 2011071001 OKCheck reverse zone:
# named-checkzone example.com /var/named/reverse.example Sample Output: zone example.com/IN: loaded serial 2011071001 OK- Add the DNS Server details in your network interface config file.
- Edit file /etc/resolv.conf,
- Restart network service:
Sequence 2. Test DNS Server
[the_ad id="2469"]
dig ns1.example.comSample Output:
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> ns1.example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25179 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;ns1.example.com. IN A ;; ANSWER SECTION: ns1.example.com. 86400 IN A 10.0.0.15 ;; AUTHORITY SECTION: example.com. 86400 IN NS ns1.example.com. ;; ADDITIONAL SECTION: ;; Query time: 0 msec ;; SERVER: 10.0.0.15#53(10.0.0.15) ;; WHEN: Wed Aug 20 16:20:46 IST 2014 ;; MSG SIZE rcvd: 125 nslookup example.com