Solved

CentOS:  Setup DNS and create records

Posted on 2011-03-11
38
1,142 Views
Last Modified: 2012-05-11
Hi All,

I'm very new to CentOS, being a Windows Admin for the last 10 years I fancied a change.

Can someone walk me through installing DNS and show me how to create a record, ideally from a command line rather than editing a file, as i want to automate the process.

I have root SSH access and yum is installed.


D
0
Comment
Question by:detox1978
  • 21
  • 16
38 Comments
 
LVL 2

Expert Comment

by:Saikapian_4739
Comment Utility
Install the bind package by the following command if you have yum repository set up

yum -y install bind

Once the package is installed a sample directory containing all the configuration files will be created under . /usr/shares/docs/bind-*.*.*/Sample/
This directory will have two directories under it, ie. etc and var. Copy all the files from the two directoris to their exact locations i.e. files from etc to /etc and from var to /var mainataing the directory structure exactly as it is here.

Then you need to work with these files
/etc/named.conf ---> Primary config file containing enteries for local resolution, internal and external resolution, you have to define your zones here only.

/var/named :

This directory will contain the different zone files for all zones like localhost, localdomain etc.

Actually there is no need to create a fresh zone file with the entire records. These files in the /var/named directory contains the sample files , you can simply have a look at them and then create your own file.

Anyways here is how you have to create teh file if you don't want to edit.

$TTL      86400 ; 24 hours could have been written as 24h or 1d
$ORIGIN example.com.
@  1D  IN       SOA ns1.example.com.      hostmaster.example.com. (
                        2002022401 ; serial
                        3H ; refresh
                        15 ; retry
                        1w ; expire
                        3h ; minimum
                       )
       IN  NS     ns1.example.com. ; in the domain
       IN  NS     ns2.smokeyjoe.com. ; external to domain
       IN  MX  10 mail.another.com. ; external mail provider


Hope this helps you
                                                             
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
You need some good reading.  I can give you a some totally awesome link.
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch18_:_Configuring_DNS
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
Ok, i've installed bind.9.3.6 and can see /usr/share/doc/bind-9.3.6/sample/

Where do i need to copy the etc and var folder too?
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
This is just the documentation you are talking about.  This is not the path of your configuration files.

The configuration DNS files are located in:
/var/named/var/named

The above documentation tells you what to install.  You should have installed named and bind
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I have a /var/named/ folder but it does not contain a folder called var
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
I think you have not installed named

Try this:
rpm -qa | grep named

Open in new window


And if you see something, show it to me.  If you don't, you have to install named

 
yum install named

Open in new window

0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
named wasn't installed
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
-bash-3.2# yum install named
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror.netrino.co.uk
 * base: mirror.sov.uk.goscomb.net
 * extras: mirror.netrino.co.uk
 * updates: mirror.netrino.co.uk
addons                                                   |  951 B     00:00
base                                                     | 2.1 kB     00:00
c5-testing                                               | 1.9 kB     00:00
dag                                                      | 1.1 kB     00:00
extras                                                   | 2.1 kB     00:00
updates                                                  | 1.9 kB     00:00
Reducing CentOS-5 Testing to included packages only
Finished
Setting up Install Process
No package named available.
Nothing to do
-bash-3.2#
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Ok these are the package you need

bind (includes DNS server, named)
bind-utils (utilities for querying DNS servers about host information)
bind-libs (libraries used by the bind server and utils package)
bind-chroot (tree of files which can be used as a chroot jail for bind)
caching-nameserver (config files for a simple caching nameserver)


First check whether you have these installed or not:
 
rpms="bind bind-utils bind-libs bind-chroot caching-nameserver"
for p in $rpms
do
  echo "Checking package $p ..."
  rpm -qa | grep $p
done

Open in new window



If some of these packages is missing, install it:
 
yum install <package>

Open in new window

0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
You have new mail in /var/spool/mail/root
-bash-3.2# rpms="bind bind-utils bind-libs bind-chroot caching-nameserver"
-bash-3.2# for p in $rpms
> do
>   echo "Checking package $p ..."
>   rpm -qa | grep $p
> done
Checking package bind ...
bind-chroot-9.3.6-4.P1.el5_5.3
bind-libs-9.3.6-4.P1.el5_5.3
bind-9.3.6-4.P1.el5_5.3
Checking package bind-utils ...
Checking package bind-libs ...
bind-libs-9.3.6-4.P1.el5_5.3
Checking package bind-chroot ...
bind-chroot-9.3.6-4.P1.el5_5.3
Checking package caching-nameserver ...
-bash-3.2#
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility

yum install bind-utils caching-nameserver

Open in new window

0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
ok, I've installed them.

/var/named/ now contains the following folders;

chroot
localdomain.zone
named.broadcast  
named.ip6.local  
named.zero
data    
localhost.zone    
named.ca        
named.local      
slaves


What's next?
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Ok.  So try this

cd /var/named/chroot/var/named
ls
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
data              
localhost.zone  
named.ca        
named.local  
slaves
localdomain.zone  
named.broadcast  
named.ip6.local  
named.zero
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Here you go.
This is where you have the zone files.  Now you can follow the directions of the tutorial I sent you earlier and it is a little bit of reading but it is detailed and you should not have any problems in configuring your DNS.
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
That link is far too generic.

How do i create records.
0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
Comment Utility
First you need to tell the name of files where your records (forward and reverse) would reside.  This is done as follows:

Open /var/named/chroot/etc/named.conf and add the following forward and reverse zone file directives:
The following file is just an example.  For reverse, notice the in-addr.arpa and reversal of IP addresses octets.  This would mean for IP address of 1.2.3.4, you reverse it like 4.3.2.1
 
# Forward Zone for hughes.lan domain
zone "hughes.lan" IN {
        type master;
        file "hughes.lan.zone";
};

# Reverse Zone for hughes.lan domain
zone "15.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.15.zone";            
};

Open in new window


Now you have to create the forward and reverse lookup files.  Use there files as templates.  If you want to understand the details, you will have to read.

The foward zone file would look like
 
$TTL 1D

hughes.lan.             IN      SOA     velma.hughes.lan. foo.bar.tld. (
                                200612060                 ; serial
                                2H                        ; refresh slaves
                                5M                        ; retry
                                1W                        ; expire
                                1M                        ; Negative TTL
                                )

@                       IN      NS      velma.hughes.lan.

velma.hughes.lan.       IN      A       192.168.15.10     ; RHEL server
fred.hughes.lan.        IN      A       192.168.15.1      ; router
scooby.hughes.lan.      IN      A       192.168.15.2      ; upstairs WAP
shaggy.hughes.lan.      IN      A       192.168.15.3      ; downstairs WAP
scooby-dum.hughes.lan.  IN      A       192.168.15.4      ; Fedora desktop
daphne.hughes.lan.      IN      A       192.168.15.5      ; network printer
mysterymachine          IN      A       192.168.15.6      ; mail server
scrappy			IN	A	192.168.15.7      ; Windows box
							  ; aliases
www			IN	CNAME	velma.hughes.lan. ; WWW server	
virtual			IN	CNAME	velma             ; virtual WWW tests
mail                    IN      CNAME   mysterymachine    ; sendmail host

							  ; DHCP Clients
dhcp01.hughes.lan.      IN      A       192.168.15.100
dhcp02.hughes.lan.      IN      A       192.168.15.101
dhcp03.hughes.lan.      IN      A       192.168.15.102
dhcp04.hughes.lan.      IN      A       192.168.15.103
dhcp05.hughes.lan.      IN      A       192.168.15.104

@                       IN      MX  10  mail.hughes.lan.

Open in new window



And the reverse zone file would look like

 
$TTL 1D

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

        IN      NS      velma.hughes.lan.
10      IN      PTR     velma.hughes.lan.
1       IN      PTR     fred.hughes.lan.
2       IN      PTR     scooby.hughes.lan.
3       IN      PTR     shaggy.hughes.lan.
4       IN      PTR     scooby-dum.hughes.lan.
5       IN      PTR     daphne.hughes.lan.
6       IN      PTR     mysterymachine.hughes.lan.
7       IN      PTR     scrappy.hughes.lan.

100     IN      PTR     dhcp01.hughes.lan.
101     IN      PTR     dhcp02.hughes.lan.
102     IN      PTR     dhcp03.hughes.lan.
103     IN      PTR     dhcp04.hughes.lan.
104     IN      PTR     dhcp05.hughes.lan.

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
By the way, this is where I found all this information.  If you don't like to read too much, you may want to read only this little document
http://www.redhat.com/magazine/026dec06/features/dns/
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I want to use this as a name server, so how would i set a .co.uk and .com zone?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Supposing you have company.co.uk and company.com

First you would open /var/named/chroot/etc/named.conf and name your zone files.  So you need one zone file each for forward lookup and the same number for the reverse lookup.

Then in those files, just follow the forward and reverse lookup template and create files.  Test them.
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
Is there no way to setup a zone for .com and .co.uk

Then i can just create the records?
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Are you the ISP for these HUGE zones??

The idea is exactly the same.  It is just that I don't think you are modifying .com (which is millions of records) tree and likewise .co.uk also has millions of records.  If you are the SOA (source of authority) for these, why not.  You can only be the SOA for the zones that you own.  For the rest you need to get the record included by a higher authority.

For example if I have a company littleguy.  I would request a bigger authority to add my record.  Lets say, I want littleguy.org.  Then I would directly or indirectly contact .org zone to add my record.  Now, if I have another customer, tinyman with address tinyman.littleguy.org, then I would be the SOA of this and I would enter this record into my DNS.
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I've not used DNS on CentOS before.  on windows you can setup a zone and create the records you want.

This is just a name server, so doesn't need external dns records, only the ones i create.
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I've created a new named.conf file, but nslookup doesn't return the record.

Do i need to restart he dns server?  if so how? :-)
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
worked it out.  But get this response;


-bash-3.2#   /etc/init.d/named restart
Stopping named:                                            [  OK  ]
Starting named:
Error in named configuration:
/etc/named.conf:16: unknown option '$TTL'
/etc/named.conf:19: unknown option 'serial'
/etc/named.conf:20: unknown option 'refresh'
/etc/named.conf:21: unknown option 'retry'
/etc/named.conf:22: unknown option 'expire'
/etc/named.conf:23: unknown option 'Negative'
/etc/named.conf:28: unknown option 'WWW'
/etc/named.conf:29: unknown option 'mail'
/etc/named.conf:30: unknown option 'demo'
/etc/named.conf:31: unknown option 'demo'
/etc/named.conf:41: unknown option 'serial'
/etc/named.conf:42: unknown option 'refresh'
/etc/named.conf:43: unknown option 'retry'
/etc/named.conf:44: unknown option 'expire'
/etc/named.conf:45: unknown option 'Negative'
/etc/named.conf:57: unexpected token near end of file
                                                           [FAILED]
-bash-3.2#
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
I didn't understand what you said.  Is it going to be just a caching only name server?  DNS is name server so I am getting confused.

You are probably not putting comments ';' as in the sample file.

And you can simply write:

 
service named restart

Open in new window

0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
It's going to be used as a names server for my websites to be found on the internet.

Is there not an easier way to do this?
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I'm not having much luck with this;

I tried to create my own file but got errors, so tried using your file and get the following error;



Error in named configuration:
/etc/named.conf:13: unknown option '$TTL'
/etc/named.conf:16: unknown option 'serial'
/etc/named.conf:17: unknown option 'refresh'
/etc/named.conf:18: unknown option 'retry'
/etc/named.conf:19: unknown option 'expire'
/etc/named.conf:20: unknown option 'Negative'
/etc/named.conf:25: unknown option 'RHEL'
/etc/named.conf:26: unknown option 'router'
/etc/named.conf:27: unknown option 'upstairs'
/etc/named.conf:28: unknown option 'downstairs'
/etc/named.conf:29: unknown option 'Fedora'
/etc/named.conf:30: unknown option 'network'
/etc/named.conf:31: unknown option 'mail'
/etc/named.conf:32: unknown option 'Windows'
/etc/named.conf:33: unknown option 'aliases'
/etc/named.conf:34: unknown option 'WWW'
/etc/named.conf:35: unknown option 'virtual'
/etc/named.conf:36: unknown option 'sendmail'
/etc/named.conf:38: unknown option 'DHCP'
/etc/named.conf:50: unknown option 'serial'
/etc/named.conf:51: unknown option 'refresh'
/etc/named.conf:52: unknown option 'retry'
/etc/named.conf:53: unknown option 'expire'
/etc/named.conf:54: unknown option 'Negative'
/etc/named.conf:73: unexpected token near end of file
                                                           [FAILED]

# Forward Zone for hughes.lan domain
zone "hughes.lan" IN {
        type master;
        file "hughes.lan.zone";
};

# Reverse Zone for hughes.lan domain
zone "15.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.15.zone";            
};

$TTL 1D

hughes.lan.             IN      SOA     velma.hughes.lan. foo.bar.tld. (
                                200612060                 ; serial
                                2H                        ; refresh slaves
                                5M                        ; retry
                                1W                        ; expire
                                1M                        ; Negative TTL
                                )

@                       IN      NS      velma.hughes.lan.

velma.hughes.lan.       IN      A       192.168.15.10     ; RHEL server
fred.hughes.lan.        IN      A       192.168.15.1      ; router
scooby.hughes.lan.      IN      A       192.168.15.2      ; upstairs WAP
shaggy.hughes.lan.      IN      A       192.168.15.3      ; downstairs WAP
scooby-dum.hughes.lan.  IN      A       192.168.15.4      ; Fedora desktop
daphne.hughes.lan.      IN      A       192.168.15.5      ; network printer
mysterymachine          IN      A       192.168.15.6      ; mail server
scrappy			IN	A	192.168.15.7      ; Windows box
							  ; aliases
www			IN	CNAME	velma.hughes.lan. ; WWW server	
virtual			IN	CNAME	velma             ; virtual WWW tests
mail                    IN      CNAME   mysterymachine    ; sendmail host

							  ; DHCP Clients
dhcp01.hughes.lan.      IN      A       192.168.15.100
dhcp02.hughes.lan.      IN      A       192.168.15.101
dhcp03.hughes.lan.      IN      A       192.168.15.102
dhcp04.hughes.lan.      IN      A       192.168.15.103
dhcp05.hughes.lan.      IN      A       192.168.15.104

@                       IN      MX  10  mail.hughes.lan.

$TTL 1D

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

        IN      NS      velma.hughes.lan.
10      IN      PTR     velma.hughes.lan.
1       IN      PTR     fred.hughes.lan.
2       IN      PTR     scooby.hughes.lan.
3       IN      PTR     shaggy.hughes.lan.
4       IN      PTR     scooby-dum.hughes.lan.
5       IN      PTR     daphne.hughes.lan.
6       IN      PTR     mysterymachine.hughes.lan.
7       IN      PTR     scrappy.hughes.lan.

100     IN      PTR     dhcp01.hughes.lan.
101     IN      PTR     dhcp02.hughes.lan.
102     IN      PTR     dhcp03.hughes.lan.
103     IN      PTR     dhcp04.hughes.lan.
104     IN      PTR     dhcp05.hughes.lan.

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Ok.

This is what is happening here.

You said that forward lookup file is hughes.lan.zone

And reverse lookup file is 192.168.15.zone.

This is what you just said.

Now do as follows:

cp /etc/named.conf /var/named/chroot/var/named/hughes.lan.zone
cp /etc/named.conf /var/named/chroot/var/named/192.168.15.zone

NOW use vi or any editor to edit /etc/named.conf

vi /etc/named.conf

Delete everything in this file below line 13 (Line number as shown in the file above)

Now do this:
cd /var/named/chroot/var/named/
vi hughes.lan.zone

Edit this file
As per the number used above, only keep line 13 to line 45 in this file.  Rest doesn't belong here.
Save and exit

Now vi 192.168.15.zone
Only keep contents of line 47 to the end of the file.  Rest doesn't belong here.

Try your luck again
service named restart

Open in new window

Forward lookup test
 
dig @localhost velma.hughes.lan

Open in new window

Reverse lookup
 
dig @localhost -x 192.168.15.10

Open in new window

0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I've been putting everything into one file named.conf....  should there be more than on file?
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Please follow my instructions above WORD BY WORD

It should be 3 files.  One is named config file.  Second is forward lookup file for one zone.  Third is reverse lookup file for the same zone.  If you remember, I gave you a files count earlier.  Please follow my instructions one line at a time.  I took a lot of time and pain to type it for you.
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
Are you sure named.conf is located;

/etc/named.conf


~ and not


/var/named/chroot/etc/named.conf
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
Here's what i got when i followed the step;


-bash-3.2# service named restart
Stopping named:                                            [  OK  ]
Starting named:
Error in named configuration:
zone hughes.lan/IN: loading master file hughes.lan.zone: file not found
_default/hughes.lan/IN: file not found
zone 15.168.192.in-addr.arpa/IN: loading master file 192.168.15.zone: file not found
_default/15.168.192.in-addr.arpa/IN: file not found
                                                           [FAILED]
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Ok, I typed right the first time and wrong later.

Issue the following command and test

mv /etc/named.conf /var/named/chroot/etc/
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
mv: `/etc/named.conf' and `/var/named/chroot/etc/named.conf' are the same file
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
It's taken a long time, but i've finally got it to work.

Many thanks for your help and perseverance
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Glad to help.  What was missing?
0
 
LVL 2

Author Comment

by:detox1978
Comment Utility
I installed a PHP script that creates and manages the DNS record and zone files.

The steps you gave me installed DNS, so the files I created must have had a type or the wrong CHMOD.

The files the script creates look very similar, so not sure what i was doing wrong.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally you run into the website or two that will not resolve properly using your own DNS servers.  Some people simply set up global forwarders for their DNS server.  I don’t recommend doing this because it can cause problems resolving addresse…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now