Change Dns Linux Ubuntu

7 min read Oct 10, 2024
Change Dns Linux Ubuntu

Changing DNS Servers in Linux Ubuntu: A Comprehensive Guide

Linux Ubuntu users often find themselves needing to change DNS servers. This could be for several reasons, like wanting to use a different DNS provider for faster speeds or improved security, or even to bypass local internet restrictions. Whatever the reason, changing your DNS servers in Ubuntu is a straightforward process.

What are DNS Servers?

DNS (Domain Name System) servers act as translators between human-readable domain names (like "google.com") and the numerical IP addresses that computers actually use to communicate. When you type a website address into your browser, your computer queries a DNS server to find the corresponding IP address.

Why Change DNS Servers?

  • Speed: Some DNS providers offer faster lookup times, which can lead to quicker website loading speeds.
  • Security: Public DNS servers, like those offered by Google or Cloudflare, often employ security features like DNSSEC that can help prevent DNS hijacking attacks.
  • Privacy: Certain DNS providers prioritize user privacy by not tracking or logging user activity.
  • Geo-restrictions: Changing to a DNS server located in a different country might allow you to access content that is normally blocked in your region.

How to Change DNS Servers in Ubuntu

There are two main ways to change your DNS servers in Ubuntu:

1. Using the Network Manager:

This method is ideal for beginners as it involves a simple graphical interface.

  • Open Network Settings: Click on the network icon in the top right corner of your Ubuntu desktop, then select "Network Settings".
  • Choose Your Connection: Select the network connection you want to change DNS servers for (e.g., Wi-Fi or Ethernet).
  • Edit Connection: Click on the cogwheel icon next to the connection name to open its settings.
  • Go to IPv4 Settings: Under the "IPv4 Settings" tab, choose the option "Manual".
  • Enter New DNS Servers: In the "Addresses" field, enter the IP addresses of the new DNS servers you want to use.
    • For example, to use Google Public DNS, you would enter:
      • 8.8.8.8
      • 8.8.4.4
  • Save Changes: Click on "Apply" and then "Save" to save your changes.

2. Editing the /etc/resolv.conf File:

This method gives you more control over your DNS settings but requires you to be comfortable editing text files in a terminal.

  • Open Terminal: Press Ctrl+Alt+T to open a terminal window.
  • Become Root: Use the following command to gain root access:
sudo su 
  • Edit /etc/resolv.conf: Use the following command to open the /etc/resolv.conf file in your preferred text editor (nano is a lightweight editor):
nano /etc/resolv.conf 
  • Change DNS Servers: The file should look like this:
nameserver 127.0.0.1

Delete the existing line and enter the new DNS server IP addresses like this:

nameserver 8.8.8.8
nameserver 8.8.4.4
  • Save and Exit: Press Ctrl+X to exit nano, type Y to save changes, and then press Enter.

Common DNS Server Providers

  • Google Public DNS: 8.8.8.8 and 8.8.4.4
  • Cloudflare DNS: 1.1.1.1 and 1.0.0.1
  • OpenDNS: 208.67.222.222 and 208.67.220.220
  • Quad9: 9.9.9.9 and 149.112.112.112

Verifying DNS Changes

Once you've changed your DNS servers, you can verify that the changes have taken effect using a DNS lookup tool. There are several online DNS lookup tools available, or you can use the nslookup command in your terminal.

For example, to check the DNS settings for google.com, use the following command:

nslookup google.com 

The output will show you the IP address of google.com resolved by your current DNS servers.

How to Reset DNS Settings

If you want to reset your DNS settings to their default values, you can use the same methods outlined above:

  • Network Manager: In the "IPv4 Settings" tab, select the "Automatic (DHCP)" option.
  • /etc/resolv.conf: Delete all lines within the file and save your changes.

Conclusion

Changing your DNS servers in Linux Ubuntu is a straightforward process. By choosing a reliable DNS provider, you can improve your browsing experience, enhance security, and even bypass geo-restrictions. Experiment with different DNS servers to find the one that best suits your needs.