Prerequisites/Requirements
- VPS installed with CentOS and a web server such as Apache
- Registered domain name
- First, point your domain to a working hosting and create two A records in the Zone Editor, each for your two name servers. Eg ns1.example.com and ns2.example.com. Point each of this A records to your server’s IP. Test to see that when you access the nameservers above, they display the landing page of your VPS. You can also ping them to see if they respond with your server IP.
- In your client area, click on Register Private Nameservers and add the two ns1.example.com and it’s IP and ns2.example.com and it’s IP.
- Great, now you are ready to create the DNS files.
Set up DNS zone on your VPS1. Access the VPS via SSH
ssh user@hostname2. Install bind and dnsutils, which will allow us to use the dig command later on
Centos or Fedora: yum install bind dnsutils
Ubuntu ir Debian: apt-get install bind9 dnsutils3. Create a DNS zone file for the domain that will use the name servers. If the domain is called example.com, here is a sample zone file for the domain. The zone file will be called example.com.db. Save this zone file in /var/named. I will assume your server IP is 10.10.10.10. This file will help map your domain name to the IP.
;
; BIND data file for example.com
;
$TTL 3h
@ IN SOA ns1.example.com. admin.example.com. (
1 ; Serial
3h ; Refresh after 3 hours
1h ; Retry after 1 hour
1w ; Expire after 1 week
1h ) ; Negative caching TTL of 1 day
;
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
example.com. IN MX 10 mail.example.com.
example.com. IN A 10.10.10.10
ns1 IN A 10.10.10.10
ns2 IN A 10.10.10.10
www IN CNAME example.com.
mail IN A 10.10.10.10
ftp IN CNAME example.com.
4. Create similar DNS records as above for your two nameservers, ns1.example.com and ns2.example.com Only replace example.com with ns1.example.com and ns2.example.com in the respective files.
5. Configure reverse DNS records. This zone file teaches our nameservers to resolve a host from an IP address. The file will be called 10.10.10.10.db Also, save this zone file in /var/named
;
; BIND reverse data file for 0.10.10.in-addr.arpa
;
$TTL 604800
0.10.10.in-addr.arpa. IN SOA ns1.example.com.
admin.example.com. (
1 ; Serial
3h ; Refresh after 3 hours
1h ; Retry after 1 hour
1w ; Expire after 1 week
1h ) ; Negative caching TTL of 1 day
;
0.10.10.in-addr.arpa. IN NS ns1.example.com.
0.10.10.in-addr.arpa. IN NS ns2.example.com.
10.10.10.10.in-addr.arpa. IN PTR example.com.
6. Update the BIND configuration file. Note that, at this point, you should have these two files ready. Ie
/var/named/example.com.db
/var/named/10.10.10.10.dbNow, simply open the Bind configuration file using your favourite editor.
vim /etc/named.confThen add the following code. Remeber to change example.com to your domain name
zone "example.com" {
type master;
file "/var/named/example.com.db";
};
zone "0.217.144.in-addr.arpa" {
type master;
file "/var/named/10.10.10.10.db";
};7. Lastly, add an IP address of a stable DNS server in your /etc/resolv.conf file. For example, if you wish to add google’s DNS server, comment our the content of /etc/resolv.conf and add the following line:
nameserver 8.8.4.48. Check binds zone files and configuration
To check the configuration files run the following command:
named-checkconfTo check a DNS zone files we can use named-checkzone command:
named-checkzone example.com /var/named/example.com.db
zone example.com/IN: loaded serial 1
OK
For the reverse zone file check
named-checkzone 0.10.10.in-addr.arpa /var/named/10.10.10.10.db
zone 0.168.192.in-addr.arpa/IN: loaded serial 2
OK9. Restart bind
service named restart10. You can test the bind server configuration using dig command
dig @10.10.10.10 www.example.com
; <<>> DiG 9.6-ESV-R1 <<>> @10.10.10.10 www.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<