Linux - How to change your DNS

Overview

This guide walks through the process of changing DNS on Linux based systems.

We recommend you to use either Google's or Cloudflare's DNS as these are less prone to name resolution failures.



1️⃣ DNS Server Options

  • Google DNS Primary: 8.8.8.8
  • Google DNS Secondary: 8.8.4.4
  • Cloudflare Primary: 1.1.1.1
  • Cloudflare Secondary: 1.0.0.1


Note: Choose either Google or Cloudflare DNS servers - don't mix them


2️⃣ Clear DNS Cache

  • For systemd-based systems (Ubuntu, Debian, etc.):
sudo systemd-resolve --flush-caches
  • For Ubuntu/Debian you might also need:
sudo service network-manager restart



3️⃣Temporary DNS Change: 
  • Change DNS for current session using Terminal
sudo resolvectl dns NETWORK_INTERFACE 8.8.8.8 8.8.4.4    # For Google DNS
sudo resolvectl dns NETWORK_INTERFACE 1.1.1.1 1.0.0.1    # For Cloudflare DNS


Info: To know your NETWORK_INTERFACE, please use the below 
ip link show
# or
ip addr
# or
nmcli device status



4️⃣ Permanent DNS Change:

  • Edit resolv.conf file  

sudo nano /etc/resolv.conf
  • Add these lines (remove or comment out existing nameserver lines): 
# For Google DNS
nameserver 8.8.8.8
nameserver 8.8.4.4

# OR for Cloudflare DNS
nameserver 1.1.1.1
nameserver 1.0.0.1
  • Save the file and Exit Nano.



5️⃣ Verify DNS Settings

  • Check current DNS configuration: 
resolvectl status
  • Verify which DNS server is handling queries: 
nslookup google.com


Warning: Some systems might revert resolv.conf changes after reboot. You may need to make the file immutable or use other methods for permanent changes.


Note: If you encounter any difficulties during the process, please do reach out to our support team.

 


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article