What is Domain Name System? | How to Configure DNS in Linux

The DNS is a database of domain name and IP address records that helps browsers to find the correct IP address for a hostname URL entered into it. When we want to access a website, we usually type its domain name into the web browser, such as www.google.com, www.wikipedia.com, or www.techarticles.in. Web browsers, on the other hand, require the specific IP addresses in order to load content for the website. The DNS is responsible for converting domain names to IP addresses so that resources can be loaded from the website's server.

Websites may have many IP addresses linked to a single domain name. Large sites, such as Google, will have users requesting a server from all over the world.

{getToc} $title={Table of Contents}

1. Introduction


This article primarily covers how to set the DNS server address correctly under Linux, covering three approaches. 1. Make changes to the network card configuration file. 2. Change the hosts file so that local DNS is used. 3. Make changes to the DNS configuration file, /etc/resolv.conf.

2. Method 1. Modifying the network card configuration file

Check the network card's name by running below command.
# ip addr
On the server, you can see the configuration of each network card, where the second column gives the network card's name, such as lo, eth1, or ens33, and so on.

Assume your network card's name is xxxx.

You can use your prefurred DNS provided by your ISP or as per your network configuration, In this tutorials I am going to use google DNS server IPs ,8.8.8.8 and 4.2.2.2

Change the primary DNS, that is, DNS1, to 8.8.8.8, and run the following command change xxxx with netwrok device name:

"Root access required."

 echo 'DNS1="8.8.8.8" ' >> /etc/sysconfig/network-scripts/ifcfg-xxxx
Set the backup DNS, i.e., DNS is 4.2.2.2, and the command is as follows.

Root access is also necessary.

echo 'DNS2="4.2.2.2" ' >> /etc/sysconfig/network-scripts/ifcfg-xxxx
CentOS 7 network restart command:
# systemctl restart network.service

This command is also applicable to RHEL 7.

CentOS 8 network restart command:

# nmcli c up xxx

This command also works on RHEL 7

The basic idea behind restarting the network is to add the DNS server to the DNS configuration file /etc/resolv.conf.

Check to see if the setting is effective.
 #cat /etc/resolv.conf 

3. Method 2: Directly alter the /etc/resolv.conf DNS configuration file.

Keep in mind that this setting only functions momentarily.
# echo 'nameserver 223.5.5.5' >> /etc/resolv.conf 
# echo 'nameserver 223.6.6.6' >> /etc/resolv.conf 
Use the vi/vim editor to change the DNS server address if necessary.

Verify the setting's effectiveness.
# cat /etc/resolv.conf

4. Method 3: 4. Implement local mapping for the prospective domain name.

Change the local host file, in other words.

The vi/vim editor should be used for customization.

# vi /etc/hosts

Set the IP and domain name correspondence.


Example
192.168.10.1 www.example.com 

5. Conclusion

With Linux, there are three ways to specify the DNS server address. In this article, there are two methods: the recommended approach, which permanently sets the DNS server address, and a temporary method, which only does so briefly. The third approach is changing the hosts file and statically setting the connection between a certain IP address and a particular domain

Jay

I love keeping up with the latest tech trends and emerging technologies like Linux, Azure, AWS, GCP, and other cutting-edge systems. With experience working with various technology tools and platforms, I enjoy sharing my knowledge through writing. I have a talent for simplifying complex technical concepts to make my articles accessible to all readers. Always looking for fresh ideas, I enjoy the challenge of presenting technical information in engaging ways. My ultimate aim is to help readers stay informed and empowered on their tech journeys.

Post a Comment

Previous Post Next Post

Contact Form