Assumed that you already buy two Virtual Private Server (VPS) but you dont want to point your nameservers on your hosting provider. To look more professional and stylish, you can run and have two private nameservers such as ns1.ehowstuff.local and ns2.ehowstuff.local. This post will show you the steps on how to setup and run your own Bind9 Chroot private nameservers on CentOS 6.2 VPS or dedicated server with atleast 2 IP addresses. To fit you requirement, please replace domain (ehowstuff.local) and ip addresses to your own domain and IPs.
ns1.ehowstuff.local : 192.168.1.44 (Master Private DNS server)
ns2.ehowstuff.local : 192.168.1.54 (Slave Private DNS server)
1. Install Bind Chroot DNS Server on both Primary and Slave server :
Master DNS Server
[root@ns1 ~]# yum install bind-chroot -y
Slave DNS server
[root@ns2 ~]# yum install bind-chroot -y
Master DNS Server
2. Login to Primary DNS server (ns1), and create a file /var/named/chroot/var/named/ehowstuff.local with the following configuration:
[root@ns1 ~]# vim /var/named/chroot/var/named/ehowstuff.local
; ; Addresses and other host information. ; $TTL 14400 ehowstuff.local. IN SOA ns1.ehowstuff.local. admin.ehowstuff.local. ( 2012060201 ; Serial 86400 ; Refresh 7200 ; Retry 3600000 ; Expire 86400 ) ; Minimum ;A record for domain mapping domain to IP ehowstuff.local. IN A 192.168.1.44 ;Define the atleast 2 private nameservers ehowstuff.local. IN NS ns1.ehowstuff.local. ehowstuff.local. IN NS ns2.ehowstuff.local. ; Map 2 private nameservers to IP addressess using A record ns1 IN A 192.168.1.44 ns2 IN A 192.168.1.54 ; Specify subdomains if any using CNAME or alias. www IN CNAME ehowstuff.local. ftp IN CNAME ehowstuff.local. ; Mail exhanger and map it IP using A record. ehowstuff.local. IN MX 10 mail.ehowstuff.local.
3. Still on ns1, please generate an RNDC key :
The rndc tool is used to managed the named daemon. We need to generate a keyfile called /etc/rndc.key which is referenced both by /etc/rndc.conf and /etc/named.conf To do this we use the following command;
[root@ns1 ~]# rndc-confgen -a -c /etc/rndc.key wrote key file "/etc/rndc.key"
View the content of the RNDC key :
[root@ns1 ~]# cat /etc/rndc.key key "rndc-key" { algorithm hmac-md5; secret "T6tduqyMQ/YbIDXOmE0Fzg=="; };
4. on ns1, edit the /var/named/chroot/etc/named.conf file for ehowstuff.local
[root@ns1 ~]# vi /var/named/chroot/etc/named.conf
options { directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; forwarders { 8.8.8.8; }; }; include "/etc/rndc.key"; // We are the master server for ehowstuff.local zone "ehowstuff.local" { type master; file "/var/named/ehowstuff.local"; allow-transfer {192.168.1.54;}; allow-update {none;}; };
5. Start the DNS service using the following command :
[root@ns1 ~]# /etc/init.d/named start Starting named: [ OK ]
6. Make named daemon auto start during boot :
[root@ns1 ~]# chkconfig named on
Slave DNS Server
7. Making slave DNS server can be so easy. Login to the other DNS server(ns2) and open the named.conf file. You need not create any file as the slave will automatically download the master zone information through zone transfer. After sometime, you can view the zone file. :
[root@ns2 ~]# vi /var/named/chroot/etc/named.conf
zone "ehowstuff.local" { type slave; file "/var/named/slaves/ehowstuff.local"; masters {192.168.1.44;}; };
Note: Bind will not allow you to run master and slave on same server, even-though you have 2 IP addresses
8. Start the DNS service using the following command :
[root@ns2 ~]# /etc/init.d/named start Starting named: [ OK ]
9. Make named daemon auto start during boot :
[root@ns2 ~]# chkconfig named on
10. Before testing, make sure your pc or server using the Bind Chroot DNS Server that has been set up :
[root@ns1 ~]# cat /etc/resolv.conf nameserver 192.168.1.44 nameserver 192.168.1.54
[root@ns2 ~]# cat /etc/resolv.conf nameserver 192.168.1.44 nameserver 192.168.1.54
11. Test your DNS service :
Test from Master DNS server (ns1)
[root@ns1 ~]# dig ehowstuff.local ; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.2 <<>> ehowstuff.local ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25783 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 ;; QUESTION SECTION: ;ehowstuff.local. IN A ;; ANSWER SECTION: ehowstuff.local. 14400 IN A 192.168.1.44 ;; AUTHORITY SECTION: ehowstuff.local. 14400 IN NS ns1.ehowstuff.local. ehowstuff.local. 14400 IN NS ns2.ehowstuff.local. ;; ADDITIONAL SECTION: ns1.ehowstuff.local. 14400 IN A 192.168.1.44 ns2.ehowstuff.local. 14400 IN A 192.168.1.54 ;; Query time: 0 msec ;; SERVER: 192.168.1.44#53(192.168.1.44) ;; WHEN: Sat Jun 2 14:46:46 2012 ;; MSG SIZE rcvd: 117
[root@ns1 ~]# host -t mx ehowstuff.local
ehowstuff.local mail is handled by 10 mail.ehowstuff.local.
[root@ns1 ~]# host -t ns ehowstuff.local
ehowstuff.local name server ns2.ehowstuff.local. ehowstuff.local name server ns1.ehowstuff.local.
Test from Slave DNS server (ns2)
[root@ns2 ~]# dig ehowstuff.local ; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.2 <<>> ehowstuff.local ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11526 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 ;; QUESTION SECTION: ;ehowstuff.local. IN A ;; ANSWER SECTION: ehowstuff.local. 14400 IN A 192.168.1.44 ;; AUTHORITY SECTION: ehowstuff.local. 14400 IN NS ns2.ehowstuff.local. ehowstuff.local. 14400 IN NS ns1.ehowstuff.local. ;; ADDITIONAL SECTION: ns1.ehowstuff.local. 14400 IN A 192.168.1.44 ns2.ehowstuff.local. 14400 IN A 192.168.1.54 ;; Query time: 3 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Sat Jun 2 15:26:19 2012 ;; MSG SIZE rcvd: 117
[root@ns2 ~]# host -t mx ehowstuff.local
ehowstuff.local mail is handled by 10 mail.ehowstuff.local.
[root@ns2 ~]# host -t ns ehowstuff.local
ehowstuff.local name server ns2.ehowstuff.local. ehowstuff.local name server ns1.ehowstuff.local.
1 Comment
Hi, I’m new in the VPS world, so I have a lot of questions but don’t know how to ask them!
This tutorial is perfect for hosting a website on own vps, but now I wanted to know
How can I register domains with my VPS? I think that it’s possible, but I don’t know how, so can you help me in this mission? 😉
By “register domain” I mean register the domain and use it with any hosting provider (changing the NS records) is it possible?
Waiting for help!