What is DNS server? How to configure DNS server in Centos 7?

What is DNS server? How to configure DNS server in Centos 7?

Are we all familiar with the internet and the WEB? Do we know their differences? And how do they work? What is a DNS server? How to configure DNS server in centOS 7? These questions are prevalent from beginners. Keep reading this article. We hope we will make you thoroughly understand these questions.

First, An internet is a connection between two or more computers. Second, the WEB is a connection between two or more internet users.

What is a DNS server?

DNS stands for Domain Name System. There are a few levels of them. The top-level domains are .com, .me, .gov, .edu, etc. There are other levels of the domain from the domain name system, such as .net, .org, .info, .club, etc. On the internet, all the URL has its IP address. We know we can’t remember numbers. And that’s why this domain name comes, just like your phone contact.

DNS server in centOS 7

In easy words, let’s say you typed and enter a web URL—for example, www.infolinux.com. If you didn’t go to this site before your browser then asks for the IP address from the ISP (Internet Service Provider). Suppose any of the users visiting this website from the same provider you have. Then the ISP will save its IP in its cache memory so that you can quickly get into it.

What if your ISP doesn’t know about the website you’re looking for? Well, at this moment, your ISP will ask the IP from the DNS server you provided in your system. This DNS server works in three different steps.  

First, it will ask the root server for the location who knows about the IP of the required web address. And then root server will ask the DNS server to go to the TLD server. Finally, the TLD server will give the right place where your required IP is. Please have a look at the diagram we mentioned here. WE hope you will understand their steps and working principles.

How to configure the DNS server in centOS 7?

DNS server in centOS 7

Before we go to configure our DNS server in centOS 7 terminal, we must check whether we have our static IP or not. To verify a static IP, we can follow these steps:

  1. Find the terminal: Right-click on your centOS home screen. You will find this option to open the terminal.
  2. Go to Root access: once you get into the terminal type “su root” and hit the enter. Now type your password to get into the root access.
  3. Check your IP is Global or Dynamic: After you get into the root access, type “ip a” to have a check if you got any IP or dynamic or global IP.
DNS server in centOS 7

Setting up the Static IP

If you see no IP or dynamic at your IP section, that means you didn’t have a static IP. So to set a static IP, we can follow these steps.

  1. Get a dynamic ip: Type “dhclient” to get a dynamic ip.
  2. Type vi ifcfc-(name of the section, for example, vibr0 or eno 17777…..)
  3. Edit the format. Check the text document and edit the section.
*/ TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
IPV4_FAILURE_FATAL=no
NAME= No need to change    */ your dynamic ip name
VVID= No need to change
DEVICE= No need to change
ONBOOT=yes
IPADDR= Your Dynamic ID
PREFIX=24
GATEWAY= your dynamic ID without the last two digit
[press Enter]   */
  • To save, Type “:wq” to save the configuration file.

Configuation of the DNS server

Now, you have a static ip. We can follow the following steps to configure our DNS server into the centOS 7

  1. Find your Static IP: we can find your static IP from any of these two codes, ip a, ifconfig.
  2. Find your Static hostname: we can find the hostname by typing hostname
  3. To install the BIND, type yum install bind bind-utils
  4. Edit named.conf: Type vim /etc/named.conf in the terminal. And add the following codes.
Listen-on port 53 {127.0.0.1; your static ip;};
…
….
Allow-query {localhost; any;};
:wq   (save it)

Check the fireall-cmd

  • Start the service (DNS server is named): Type systemctl start named. Now we will see the named is enabled.
  • Check if its running: systemctl status named
  • Apply the firewall: firewall-cmd –permanent –add-port=53/tcp
firewall-cmd --permanent --add-port=53/udp
firewall-cmd –reload

We should know that DNS server works both in tcp and udp mode.

  • Check if the ports are enabled or not:     Type firewall-cmd –list-all to check it.
  • Open named.conf: Type vim /etc/named.conf to open the conf file.
  • Create zones: come to the end of the file. Add these following two codes both for forward and reverse ip address.
zone “example.com” IN {
type master; 
file “forward.example.com”
allow-update {none;};
};
zone “reverse static ip (leave last two value)” IN {
type master; 
file “reverse.example.com”  (any)
allow-update {none;};
}; 

Create the two files for forward and reverese

  1. Create forward.example.com & reverese.example.com files: Now we need to create the separate file both for forward and reverse server name. To do that first we need to open the named directory. Type cd /var/named/ to open the directory. Now find named.localhost. We will copy named.localhost (because it will be almost similar) and rename it with forward.example.com. Type cp named.localhost foreward.example.com to copy the required file. Now we have to compile the file. Follow the instruction below.
IN SOA server.example.com.(your hostname) root.example.com.
(
...
@ IN NS server.example.com.
@ IN A Static IP 
Server IN A Static IP
Host IN A Static IP
Desktop IN A client ip Address
Client IN A client ip address
:wq 

After that, we will do the same for reverse.example.com. First, we copy forward.example.com.

cp forward.example.com reverse.example.com
...
....
….
@ IN NS server.example.com.
@ IN PTR server.example.com.
server IN A static IP
host IN A Static IP
desktop IN A client ip Address
client IN A client IP Address
11 IN PTR server.example.com.
10 IN PTR destop.example.com.
:wq
  1. Change the ownership to root name:
chown root:named foreward.example.com
chown root:named reverse.example.com
  1. Start the service to check: Type named-checkconf -z /etc/named.conf. If you find loading serial 0, that means there is no problem. If there is then you will have to change the server name. Similarly, we check for forward and reverse example.
named-checkzone forward /var/named/forward.example.com
named-checkzone reverse /var/named/reverse.example.com
  1. Restart the system: Systemctl restart named

These 14 steps will take you one by one to the configuration of the DNS server. If you are a beginner, we suggest you first to understand the centOS seven first. And then you can start configuring the DNS.

Why do we need to configure a DNS server in centOS 7?

We all know that whenever we insert our expected domain in the URL box, it goes through some procedure to find them out the exact web address. For example, let’s say you bought a laptop from China. The default DNS server in china can be Baidu or any other server in China. What if you come back to your country? You must change the server to get better performance. In an easy word, DNS server keeps you safe and faster. And thus, we need to configure a different DNS server.

After all, we have understood the DNS server and how to configure it in centOS 7. We further explained why we need that. We hope we could emphasise enough to make you understand this specific topic. Stay with us, and we will always be by your side with new programming post. So, we wish you the best of luck in your project.

Leave a Reply