Installing BIND on DNS Server on VPS CentOS

0
25

As per my last Post, for Hosting Website and MySQL on VPS CentOS. Today we are going to Continue on that topic and install DNS Server on that server.

If you haven’t read last Posts for Hosting Website and MySQL you can visit, By Clicking Here .

Now i am continuing with my Current Topic.

Create Private Name Server Of your Domain

Login into Your Gen X Web Hosting Account and fallow the steps

Step1.Log into client area

.

 

Step2. Click on DOMAINS

 

Step3.Locate the domain you wish to modify, then select setting option

 

Step4.In the Managing page, click on Privet Name-server on the left Hand Side.

 

Step5. For Hostname, input Custom NameServers (For example: ns1 and ns2) and IP address Of Hosting Server & save changes

NOTE: Minimum Number of custom name server can be 2.

 

Step6. After adding the Private Name Servers in Domain panel, You need update Private Name Server in your Name Server Panel. Click Here to fallow the step to update Name Server. After updating Name server you need to add them in the hosting end of that domain, Here, we done in Create Forward Zone File step below .

Install BIND on DNS Server

yum install bind bind-utils
Confirm prompt by typing ‘y’ and Enter.
Now Start Bind and check the status of Bind
service named restart
service named status
Bind is installed, now we need to configure it.

Configure Bind DNS Server

Bind configuration file is ‘named.conf’ and process it runs is named .
Open your bind Configuration file with your favorite editor to start the configuration process.
vi /etc/named.conf
In this file, In option section will modify the lines below.
listen-on port 53 { 127.0.0.1;any; };
allow-query { localhost;any; };
above lines tells DNS Server to allow DNS request on Port 53 from localhost(127.0.0.1)  and ‘any’ IP .
Other lines on Option section tells to include file and files present in those location
directory “/var/named”;
dump-file “/var/named/data/cache_dump.db”;
statistics-file “/var/named/data/named_stats.txt”;
memstatistics-file “/var/named/data/named_mem_stats.txt”;
Like directory “/var/named” tells to include all the files present in/var/named/ directory.

Configure Reverse Zone

Assuming my IP is 163.172.180.224, then my Reverse Zone name will be 180.172.163.in-addr.arpa . As per your reverse zone will depend on your VPS IP
Add below lines at the of named.conf file
zone “180.172.163.in-addr.arpa” IN {
type master;
file “180.172.163.in-addr.arpa.zone”; // Zone File Path
};

 

Configure Forward Zone

Forward zone name is the name of your Domain Name. If you host multiple domains on server then you need to create multiple zone and their zone files.
zone “example.com” IN {
type master;
file “example.com.zone”; //Zone File Path
};
Save and exit the file
NOTE: Zone File Path is the name of zone file present in /var/named/ directory. Its not necessary to have “zone” as a extension or domain name(example.com) as a name. We have used here name like “example.com.zone” because by name we can easily differentiate that it’s a zone file for domain name example.com.

Create Reverse Zone File

Reverse zone file are where we define DNS PTR records for reverse DNS lookups.
Let’s move to location given below, which by default includes all files present in it to named.conf
cd /var/named
Create Reverse zone file with name same as the name given in step “Configure Reverse Zone”
touch 180.172.163.in-addr.arpa.zone
Now, edit your forward zone file
vi 180.172.163.in-addr.arpa.zone
Here, firstly we will add SOA record with your Fully Qualified Domain Name. Every time you edit a zone file, you should increment the serial value before you restart the named process
$ORIGIN 180.172.163.in-addr.arpa.
$TTL 86400
@ IN SOA ns1.example.com. server.example.com. (
601 ; serial
21600 ; refresh after 6 hours
3600 ; retry after 1 hour
604800 ; expire after 1 week
86400 ) ; minimum TTL of 1 day
Now add NS Records and there PTR Records. Here NS Record will act as your Primary Name Server for you website.

“@” IN NS ns1.example.com.
224 IN PTR ns1.example.com.
“@” IN NS ns2.example.com.
224 IN PTR ns2.example.com.
224 IN PTR example.com.
224 IN PTR server.example.com.
224 IN PTR www.example.com.
Save and exit the reverse zone file

Create Forward Zone File

Forward zone file is where we define DNS records for forward DNS lookups.
Let’s move to location given below, which by default includes all files present in it to named.conf
cd /var/named
Create Forward zone file with name same as the name given in step “Configure Forward Zone”
touch example.com.zone
Now, edit your forward zone file
vi example.com.zone
Here, firstly we will add SOA record with your Fully Qualified Domain Name. Every time you edit a zone file, you should increment the serial value before you restart the named process
$ORIGIN example.com.
$TTL 86400
@ IN SOA ns1.example.com. server.example.com. (
601 ; serial
21600 ; refresh after 6 hours
3600 ; retry after 1 hour
604800 ; expire after 1 week
86400 ) ; minimum TTL of 1 day
Now add NS Records and there A Records.

example.com. IN NS ns1.example.com.
example.com. IN NS ns2.example.com.
ns1.example.com. IN A 163.172.180.224
ns2.example.com. IN A 163.172.180.224
example.com. IN A 163.172.180.224
www.example.com. IN A 163.172.180.224
server.example.com. IN A 163.172.180.224
Save and exit the forward zone file

Final Setup of Bind DNS Server

Run the following command to check the validity of your configuration files:
named-checkconf

Once that checks out, start BIND:
service named restart
Once Named restarts with out any problem 

Enable BIND to start on boot:
systemctl enable named

Firewall restrictions

In Most cases, Ports are blocked on VPS. So open port 53 for DNS request to complete.
Fallow below steps to do so:
firewall-cmd –zone=public –add-port=53/tcp –permanent
firewall-cmd –zone=public –add-port=53/udp –permanent
firewall-cmd –reload

Finishing

Now, You can open website on your browser or any browser to view your website.
The website content will be the one that you had placed in public_html folder in the 1st Post of this series.

That’s all for this Post.

If you like this Post do like and share. Thanks