A Complete DNS Setup Guide on Redhat(CentOS)

Background
When install cloudera cluster recently, I have to setup a private DNS server.
Environment
Private DNS server: 172.19.97.224(bigdatam.localdomain.com)
DNS client:  172.19.101.66(bigdata1.localdomain.com) and 172.19.102.56(bigdata2.localdomain.com.

Install bind and caching-nameserver
yum install bind  bind-utils bind-libs bind-chroot caching-nameserver -y

Run service named restart  to start named server first.

Configure DNS Server
Enable Caching nameserver and Create Zones
Edit /var/named/chroot/etc/named.conf:
1. Use forwarders block to forward DNS requests it can't resolve to upstream DNS server.
2. Add forward and reverse zones block for localdomain.com and 19.172.in-addr.arpa.
3. Add forward and reverse zones block for locahost and 0.0.127.in-addr.arpa.

vi /var/named/chroot/etc/named.conf 

acl localdomain-com { 172.19/16; };
options {
  directory  "/var/named";
  allow-query { localdomain-com; };
 # The block will cause the caching name server to forward DNS requests it can't resolve to upstream DNS server.
  forwarders { upstream-dns-server1; upstream-dns-server2};
  #forward only;
};
zone "localdomain.com" IN {
 type master;
 file "localdomain.com.zone";
};
zone "19.172.in-addr.arpa" IN {
 type master;
 file "172.19.zone";
};

zone "locahost" IN {
        type master;
        file "localhost.zone";
        allow-update{none;};
};

zone "0.0.127.in-addr.arpa" {
        type master;
        file "named.local";
};
zone "." {
 type hint;
 file "named.ca";
};
Add Zone files
Go to /var/named/chroot/var/named directory, create files: localdomain.com.zone and 19.172.in-addr.arpa.
cd /var/named/chroot/var/named
touch localdomain.com.zone && chown named:named localdomain.com.zone && chmod 644 localdomain.com.zone
touch 19.172.in-addr.arpa && chown named:named 19.172.in-addr.arpa && chmod 644 19.172.in-addr.arpa

vi localdomain.com.zone
$TTL 1D
$ORIGIN localdomain.com.
@             IN      SOA     bigdatam.localdomain.com. foo.bar.tld. (
                                200612060                 ; serial
                                2H                        ; refresh slaves
                                5M                        ; retry
                                1W                        ; expire
                                1M                        ; Negative TTL
                                )

@                       IN      NS      bigdatam

bigdatam       IN      A       172.19.97.224
bigdata1       IN      A       172.19.101.66
bigdata2       IN      A       172.19.102.56

vi 172.19.zone
$TTL 1D
$ORIGIN 19.172.IN-ADDR.ARPA.

@       IN      SOA     bigdatam.localdomain.com. foo.bar.tld. (
200612060       ; serial
2H              ; refresh slaves
5M              ; retry
1W              ; expire
1M              ; Negative TTL
)

        IN      NS      bigdatam.localdomain.com.
224.97      IN      PTR     bigdatam.localdomain.com.
66.101       IN      PTR     bigdata1.localdomain.com.
56.102       IN      PTR     bigdata2.localdomain.com.
localhost.zone, named.local and named.ca are already in /var/named/chroot/var/named, they are created automatically, we just need refer them in /var/named/chroot/etc/named.conf.
Restart named server
service named restart 
chkconfig named on
Reload configuration and zones
rndc reload 
Toggle query logging
rndc querylog

Sometimes, we need disable SELinux and firewall
Disable SELinux
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
Disable firewall
/etc/init.d/iptables stop
chkconfig iptables off

Configure DNS Client
Do following steps in all 3 servers.
Prevent /etc/resolv.conf get overwritten
/etc/sysconfig/network-scripts/ifcfg-eth0 (replace eth0 with your network interface if different) and change PEERDNS=yes to PEERDNS=no
Setup DNS Name resolution 
vi /etc/resolv.conf
search localdomain.com
nameserver 172.19.97.224 # the private dns server ip address.
Restart network
/etc/init.d/network restart

Test DNS Setup
Run nslookup to start a session, and run the folloiwng command in all hosts.
# nslookup
> 127.0.0.1
Server:         172.19.97.224
Address:        172.19.97.224#53

1.0.0.127.in-addr.arpa  name = localhost.
> localhost
Server:         172.19.97.224
Address:        172.19.97.224#53

Non-authoritative answer:
Name:   localhost
Address: 127.0.0.1
> bigdatam
Server:         172.19.97.224
Address:        172.19.97.224#53

Name:   bigdatam.localdomain.com
Address: 172.19.97.224
> bigdata1
Server:         172.19.97.224
Address:        172.19.97.224#53

Name:   bigdata1.localdomain.com
Address: 172.19.101.66
dig bigdaam
host -v -t A `hostname

vi /etc/hosts
127.0.0.1       localhost.localdomain localhost
Synchronize System Clock Between Servers
ntpdate pool.ntp.org

Resources
How to set up a home DNS server
How to set up a home DNS server, part II
Post a Comment

Labels

Java (159) Lucene-Solr (110) All (60) Interview (59) J2SE (53) Algorithm (37) Eclipse (35) Soft Skills (35) Code Example (31) Linux (26) JavaScript (23) Spring (22) Windows (22) Web Development (20) Tools (19) Nutch2 (18) Bugs (17) Debug (15) Defects (14) Text Mining (14) J2EE (13) Network (13) PowerShell (11) Chrome (9) Continuous Integration (9) How to (9) Learning code (9) Performance (9) UIMA (9) html (9) Design (8) Dynamic Languages (8) Http Client (8) Maven (8) Security (8) Trouble Shooting (8) bat (8) blogger (8) Big Data (7) Google (7) Guava (7) JSON (7) Problem Solving (7) ANT (6) Coding Skills (6) Database (6) Scala (6) Shell (6) css (6) Algorithm Series (5) Cache (5) IDE (5) Lesson Learned (5) Miscs (5) Programmer Skills (5) System Design (5) Tips (5) adsense (5) xml (5) AIX (4) Code Quality (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Memory Usage (4) OpenNLP (4) Project Managment (4) Python (4) Spark (4) Testing (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Become a Better You (3) Concurrency (3) Eclipse RCP (3) English (3) Firefox (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Distributed (2) Fiddler (2) Google Drive (2) Gson (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Life (2) Logging (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Bit Operation (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Mac (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) Review (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Troubleshooting (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts