Flush DNS on Linux to Fix Connectivity Issues

Flush DNS on Linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Have you ever come across a phenomenon where your Linux system refuses to run a specific website, despite the URL being valid and your Internet connection appears in order? Commonly, DNS Cache is Outdated or Corrupt and therefore unable to resolve the domain names accordingly. The fix is simple. Flush DNS on Linux.

One of the most common ways to fix DNS issues is by flushing the DNS cache, which clears the cache and makes your system request the latest. To correctly ensure that your web pages are displayed on the proper addresses, you need to go through this step as this will be the one to resolve problems of domain name resolution. If you are struggling to flush DNS on Linux, you need to read this guide as it covers all the basic Linux commands such as running DNS lookups on Linux, checking and setting DNS servers, and much more.

In this article, we will discuss the need for DNS lookup on Linux, show you how to flush your DNS cache, and give you an all-in-one setting DNS on Linux guide. This empowers you to do effective troubleshooting of DNS issues and have a system that works efficiently.

Why You Should Flush DNS on Linux

DNS (Domain Name System) is the service that translates domain names (www. example. com) into IP addresses. It allows you to search for websites, obtain services, and utilize numerous web applications. Each time you go to a website, the IP address of that site is saved in your system’s DNS cache and speeds up loading times for the next time you go to the site.

But over time, the cached DNS can become outdated or corrupted, resulting in issues like:

  1. Websites are not accessible: DNS cache may consist of stale or wrong information preventing domain resolutions.
  2. Mistaken website loads: You could be sent to a previous version of a site, or, worse, a different website altogether.
  3. Website IP address changes: When sites switch to a new server, your cache may not reflect the changes immediately.

To fix these problems, flushing DNS on Linux forces your system to clear its cache and renew DNS, refreshing your network running on  up-to-date information.

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

How to Flush DNS on Linux

Methods to Flush DNS on Linux

Flushing DNS on Linux is not complex, but the command you need to run might vary depending on the distribution and the DNS service you are using. The most common ways include:

Viewing Details with the systemd-resolve Command

If you have a modern Linux distribution with systemd (Ubuntu 18.04+), the easiest method to flush the DNS cache is with the systemd-resolve command.

systemd-resolve --flush-caches pseudo

This command immediately clears your DNS cache and renews it with new data.

Using the resolvectl Command

Some Linux operating systems (like a newer version of Ubuntu) use resolvectl to set the DNS settings.

sudo resolvectl flush-caches

Running this command will flush the DNS cache.

Using the DNS Service Command

Older Linux distributions running services like dnsmasq or bind will have a different flush command. If you are using dnsmasq, this screenshot,

sudo systemctl restart dnsmasq

Alternatively, for BIND:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

sudo rndc flush

Restarting network service

In some cases, simply restarting your network service will flush your DNS cache. The command below will help you do that:

sudo systemctl restart network-manager

This action restarts the network manager and clears the DNS cache along the way.

How to Check DNS on Linux

Once you’ve flushed your DNS cache, you’ll want to make sure your system is resolving domain names properly. There are a couple of commands to do that:

Using the dig Command

Domain Name Dig (Domain Information Groper) command when run, gives detailed information about domain name queries and the DNS records associated with the domain. You may use it to do a DNS lookup at the Linux level:

dig example.com

For instance this would return DNS records. com—so that you can verify that your system is resolving the domain properly.

Using the nslookup Command

Another tool you can use, one that really gives you the raw DNS query result, is nslookup. It’s more user-friendly and operates like dig:

nslookup example.com

This will display example IP address and other DNS-related information. com.

Using the host Command

Host command: A more straightforward command than dig and nslookup for DNS lookups:

host example.com

This command gives you basic DNS info, as the resolved IP address.

Setting DNS on Linux

Clearing the DNS cache is sometimes only one element of the fix. You may also have to update your DNS settings, particularly if your internet speed is slow or you are facing issues with DNS resolution. Linux uses the /etc/resolv.conf file or via a network manager utility.

Updating DNS Servers in /etc/resolv. conf

For manually setting DNS servers, edit the /etc/resolv. nano or vim to open the haproxy. conf file:

sudo nano /etc/resolv.conf

To use specific DNS servers (like Google’s DNS), append these lines:

nameserver 8.8.8.8

nameserver 8.8.4.4

Feel free to replace these with whatever DNS servers you like (e.g., Cloudflare, OpenDNS).

DNS Settings using Network Manager

If you are running something like Ubuntu with NetworkManager, you can configure DNS through the GUI or using the nmcli command:

nmcli dev show | grep DNS

To change the DNS servers:

nmcli con mod "your-connection-name" ipv4.dns "8.8.8.8 8.8.4.4"

nmcli con up "your-connection-name"

This will change the Google DNS servers of your selected connection.

CyberPanel and DNS Management

CyberPanel

A highly popular web hosting control panel that manages websites and DNS — CyberPanel This streamlines DNS administration, making it fully compatible with your Linux server setup. Let’s discuss how CyberPanel can assist you with DNS management:

DNS Zone Management:

With the CyberPanel GUI, you can tour your DNS zones and plus records (A, CNAME, MX), and configure your domain DNS settings no individual editing.

Automatic DNS Setup:

If you are hosting in CyberPanel, CyberPanel automatically handles the DNS settings for the domains of your websites, so you know that all the traffic will get routed correctly and the DNS will be resolved at the optimal level.

DNS Troubleshooting:

Not only can CyberPanel check the health of your DNS, but it also provides you with tools that help you troubleshoot things like incorrect DNS configurations, server downtimes, etc.

FAQs: Flush DNS on Linux

1. Why do I need to flush DNS on Linux?

Flushing the DNS cache resolves issues caused by outdated or corrupted DNS information. It can fix problems like websites not loading, loading incorrect pages, or failing to resolve IP addresses after a server migration.

2. How do I flush DNS on a modern Linux system? 

On newer Linux distributions (Ubuntu 18.04+), you can use the systemd-resolve –flush-caches command to clear the DNS cache. Alternatively, use sudo resolvectl flush-caches for systems utilizing resolvectl

3. What command should I use if I’m running dnsmasq or BIND? 

For older Linux distributions using dnsmasq, you can flush the DNS cache by running sudo systemctl restart dnsmasq. For BIND, use the sudo rndc flush command.

4. Can I check if my DNS is working after flushing the cache?

Yes! You can use tools like dig, nslookup, or host to check DNS resolution. For example, run dig example.com to verify that your system is resolving domains correctly.

5. How do I change my DNS servers on Linux?

You can manually change your DNS servers by editing the /etc/resolv.conf file or using nmcli for distributions like Ubuntu. For example, you can add nameserver 8.8.8.8 to use Google’s DNS.

Culmination: Keep Your Linux System Running Smoothly with DNS Flushing

Flushing the DNS cache on your Linux system is a straightforward yet essential task that can fix many connectivity issues, from slow website loading to domain resolution errors. By following the simple commands listed above, you can ensure your system stays up-to-date with the latest DNS information, keeping your browsing experience smooth and error-free.

Need more help with Linux troubleshooting or DNS management? Keep reading our guides, and don’t hesitate to reach out for expert advice!

Hasib Iftikhar
I'm Hasib Iftikhar, a dedicated technical writer at CyberPanel, joining the team in July 2024. With three years of extensive experience in content writing, I specialize in copywriting, article writing, guest posting, affiliate content writing, and SEO. My expertise ensures that each piece of content I create is engaging, informative, and optimized for search engines, helping businesses enhance their online presence and reach their target audience effectively.
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!