How to Set DNS Server in Linux Ubuntu?

How to Set DNS Server in Linux Ubuntu?

In the vast realm of Linux operating systems, Ubuntu stands as one of the most popular and user-friendly distributions. Configuring the Domain Name System (DNS) server settings on Ubuntu can be a crucial step for optimizing your internet connectivity and enhancing network performance. In this guide, we'll explore the step-by-step process of setting DNS servers on Ubuntu, ensuring a smooth and efficient browsing experience.

Checking Current DNS Settings:

Before diving into the DNS configuration, it's essential to check your current DNS settings. Open a terminal and use the following command:

nmcli dev show | grep 'IP4.DNS'

This command will display the current DNS server addresses configured on your system.

Setting DNS Servers Using Network Manager:

Ubuntu utilizes Network Manager for handling network-related settings, including DNS configurations. Follow these steps:

  1. Open the terminal by pressing Ctrl + Alt + T.
  2. Enter the following command to edit your connection settings:
sudo nano /etc/network/interfaces
  1. Locate the line containing dns-nameservers and add your preferred DNS server addresses, separated by commas. For example:

Replace the addresses with your desired DNS servers.

  1. Save the changes and exit the text editor by pressing Ctrl + X, then Y to confirm, and finally Enter.

  2. Restart your network manager with the following command:

sudo service network-manager restart

Setting DNS Servers Using systemd-resolved:

Ubuntu also employs systemd-resolved to manage DNS configurations. Here's how to set DNS servers using this service:

  1. Open the terminal and edit the systemd-resolved configuration file:
sudo nano /etc/systemd/resolved.conf
  1. Uncomment the line #DNS= by removing the # at the beginning and add your DNS server addresses:

Replace the addresses with your preferred DNS servers.

  1. Save the changes and exit the text editor.

  2. Restart systemd-resolved to apply the new settings:

sudo systemctl restart systemd-resolved

Verifying DNS Changes:

After making the changes, it's crucial to verify whether the new DNS servers are in effect. Use the following command to check the updated DNS settings:

systemd-resolve --status | grep 'DNS Servers'

This command will display the currently configured DNS servers.

Additional Tips:

  • If you encounter any issues or want to revert to default settings, you can reset the DNS configuration. For Network Manager:
sudo nano /etc/network/interfaces

Remove or comment out the dns-nameservers line, save, and restart Network Manager.

For systemd-resolved:

sudo nano /etc/systemd/resolved.conf

Comment out the DNS line, save, and restart systemd-resolved.

Configuring DNS servers on Ubuntu is a fundamental aspect of optimizing your network connectivity. Whether you choose Network Manager or systemd-resolved, the process is relatively straightforward. By following the step-by-step instructions outlined in this guide, you can take control of your DNS settings and enjoy a faster and more reliable internet experience on your Ubuntu system.

Related Searches and Questions asked:

  • How to Create DNS Server in CentOS?
  • How to Find DNS on Linux Command?
  • How to Configure DNS Server in Linux Step by Step?
  • How to Configure Primary and Secondary DNS Server in Linux?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.