DNS (Domain Name System) is a crucial component of network communication that translates human-readable domain names into IP addresses. In CentOS, setting up the DNS resolver is essential for proper network connectivity and efficient web browsing.
In this blog post, we will explore how to configure the DNS resolver in CentOS using Bash commands. Let’s get started!
Step 1: Checking Current Configuration
Before making any changes, it’s important to know the current DNS resolver configuration on your CentOS system. Open a terminal and run the following command:
$ cat /etc/resolv.conf
This command will display the current DNS resolver settings. You may see entries like nameserver 8.8.8.8
, which indicate the IP addresses of the DNS servers your system is using.
Step 2: Editing resolv.conf
To configure the DNS resolver, we need to edit the /etc/resolv.conf
file. Begin by opening the file in a text editor. For example, using the nano editor:
$ sudo nano /etc/resolv.conf
Note: Ensure you have administrative privileges (sudo
) to edit system files.
Step 3: Adding DNS Servers
In the opened file, you can add one or more DNS servers. Each server should be listed with the nameserver
keyword followed by its IP address. For example:
nameserver 8.8.8.8
nameserver 8.8.4.4
Here, we have added Google’s Public DNS servers (8.8.8.8
and 8.8.4.4
) as examples. Replace them with the IP addresses of the DNS servers you wish to use.
Step 4: Saving and Applying Changes
After adding the desired DNS servers, save the /etc/resolv.conf
file and exit the text editor (in nano, press Ctrl + X
, then Y
, and finally Enter
).
To ensure the changes take effect, restart the network service with the following command:
$ sudo systemctl restart network
Step 5: Verifying Changes
To verify the changes to the DNS resolver, run the cat
command on /etc/resolv.conf
again:
$ cat /etc/resolv.conf
You should now see the newly added DNS servers in the output.
Conclusion
Configuring the DNS resolver in CentOS is a straightforward process that can significantly enhance your network connectivity. By editing the /etc/resolv.conf
file and adding the desired DNS servers, you can ensure efficient domain name resolution.
Remember to keep a backup of your original resolv.conf
file in case you need to revert the changes. Happy networking!