How to setup private nameservers on a centos machine without cpanel ?

With the help of a control panel it is very easy to setup name-servers on any server. Here,  I am explaining how to setup nameservers on centos/rhel servers without using a control panel.

Step 1 : Setting up nameservers

Checking the version of centOS

[root@server]# cat /etc/redhat-release
CentOS release 6.2 (Final)

[root@server]# uname -a
Linux 2.6.18-308.8.2.el5.028stab101.1 #1 SMP Sun Jun 24 20:25:35 MSD 2012 x86_64 x86_64 x86_64 GNU/Linux

I recently bought two vps and wanted one of them as a hosting server for my website and also setup private nameservers on it.

We can now start installing bind software. Since i have root access to vps server i will try to do everything as root user.

Install bind server with the below command

[root@server]# yum install bind

Checking the installed bind version

[root@server named]# rpm -qa bind

If you may want to consider installing bind-utils to do nslookup,dig,host

[root@server]# yum install bind-utils

Now we can configure named.conf by adding zones.

[root@server]# vi /etc/named.conf

Go ahead and add the server ip to listen on port 53
options {
        listen-on port 53 {;; };
Also change
 allow-query     { localhost; };
 allow-query     { any; };

Now start entering zones at the end of named.conf

zone "" {
type master;
file "/var/named/";
zone "" {
type master;
file "/var/named/";

Here you can see that i have added two zones one for my server hostname and other for the domain itself.

Now we will go to /var/named/ directory and start creating files we pointed in /etc/named.conf file.

[root@server named]# vi

To make thing faster i’m going to redirect contents of named.loopback file found in /var/named/ to the above file. Heres how it is done.

[root@server named]# cat named.loopback >
Confirm it by
[root@server named]# cat
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        AAAA    ::1
        PTR     localhost.

We can use parts of these zone file to add our settings easily. Take a look the zone file and its records below. TTL setting is globally set to 1D and i will be leaving it that way but you can alter the TTL to your need. Source of authority SOA is set to and mail Serial number to ten digit number but you can choose any number.
Added NS records for the hostname of your server and also A record to point the hostname to the server with IP 176.2527.2519.952. Add MX record if you want this server to be the mail server.

[root@server named]# cat
@        IN SOA (
                                        1      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum IN  NS IN  NS IN  A       176.2527.2519.952 IN   MX     0

Now we can add zone recoreds for our domain Cat the conents of our above file to the file /var/named/
[root@server named]# touch
[root@server named]# cat >

We will have a copy of in file. Lets edit it to work

[root@server named]# cat
@        IN SOA (
                                        0      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum IN       NS IN       NS IN       A       176.2527.2519.952 IN   MX        0

www 		IN 	CNAME

Above you will find a CNAME record for www. This setting will load your website even if you call the website with Otherwise only will load the website.

Start the named service

[root@server named]# service named start
Starting named:                                            [  OK  ]

Check the log here 
[root@server named]# cat /var/named/data/
zone loaded serial 0
zone loaded serial 0
zone loaded serial 0
zone loaded serial 0
zone loaded serial 1
zone localhost.localdomain/IN: loaded serial 0
zone localhost/IN: loaded serial 0
managed-keys-zone ./IN: loaded serial 0
zone sending notifies (serial 0)
zone sending notifies (serial 1)

You are almost done now.

Lets check the changes from within our server.

[root@server named]# dig @localhost

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> @localhost
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<

All perfect.

2. Registering name servers you just created

The world won’t know anything about the nameservers you created just now. So how are we supposed to publish it to other dns servers on the planet ?
Simple, register them on domain registrar portal. is registred with, so i will go there and register my newly created nameservers. Godaddy will update our private nameservers to the root servers and so on and so forth. Soon within 24-48 hrs the dns will propogate and your website will show up for everyone.
What are our name servers again ?

How to register them at your registrar ?
Set them with ip we added in zone files. 176.2527.2519.952 5.176.2527.952

Adding the above nameservers with ip to register private nameservers will vary on the registrar, but the concept is the same.

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

Leave a Reply

Your email address will not be published. Required fields are marked *