Flushing the dns cache on linux

How to Flush DNS Cache in Linux

DNS, or a Domain Name System, is responsible for resolving website names into their respective IP addresses. There are multiple DNS servers and you can pick and choose the one you want to use. So, if you’re having trouble connecting to a website, or if you just want a DNS change to be seen by your Ubuntu machine, you should try to flush the DNS cache. You can also clear DNS cache in Ubuntu if you made changes to the hosts file, and you want it to be “seen” by your system without having to reboot it. Well, if you’re in any of these situations, and you want to clear DNS cache, here is how to flush DNS cache in Linux.

Note : I’m using an Ubuntu 16.10 “Yakkety Yak” system to demonstrate these methods. However, the process should be similar on most Linux distros.

Flush DNS Cache in Linux in 2020

Before we get to our tutorial, let’s see first if DNS caching is enabled on your machine or not.

Checking if DNS Caching is Enabled

All Linux distros do not behave the same way, when it comes to things like caching DNS. For example, Ubuntu, by default, doesn’t cache DNS. Before we try to clear DNS cache on a Linux machine, let’s check if caching is even enabled. To do this on an Ubuntu system, you can follow the steps below:

1. Launch Terminal, and type “ps ax | grep dnsmasq“.

2. In the output from the command, you will be able to see a field called “cache-size“. Check its value. If the value is zero, it means that caching is disabled on the system.

Note : If you want to enable DNS caching on Linux, you can do so by using the command “sudo dnsmasq -c 150”. You can use any number in place of 150, which is basically the number of entries that dnsmasq can cache.

Flush DNS Cache in Ubuntu

If your Linux system is caching DNS entries, then you can try to flush the DNS cache in order to get rid of any DNS related problems. To clear DNS cache in Ubuntu, you can follow the steps below:

1. Launch Terminal (ctrl + alt + T), and type “sudo /etc/init.d/dns-clean restart“.

2. Next, type the command “sudo /etc/init.d/networking force-reload

This will clear your DNS cache in Ubuntu, and if the problems you were experiencing were due to DNS issues, they should now be gone.

Flush DNS Cache in DNS Services on Linux

Like I said, Ubuntu doesn’t cache DNS entries by default, however, if you have manually installed a DNS service such as nscd, you can clear its cache. Methods to clear cache for some common DNS services are given below:

Читайте также:  Windows для нетбука samsung nc10

Flush nscd DNS Cache

Flush dnsmasq DNS Cache

Flush BIND DNS Cache

If you’re using BIND, you can clear DNS cache by using one of the following commands:

  • sudo /etc/init.d/named restart

  • sudo rndc exec

BIND version 9.3.0, and greater, support flushing DNS cache for a particular domain, as well as for the LAN, or the WAN. You can use the following commands to make use of this feature:

  • To clear DNS cache for a particular domain, use “sudo rndc flushname beebom.com

  • To clear DNS cache for LAN, use “sudo rndc flush lan

  • To clear DNS cache for WAN, use “sudo rndc flush wan

Bonus: Change DNS Settings in Ubuntu

We’ve been talking about flushing the DNS cache in Ubuntu, however, there may be cases where you just want to make a change to the DNS settings in Ubuntu. If you want to change the DNS settings in Ubuntu, you can do that using the GUI, or via the Terminal.

Change DNS Settings using the GUI

Using the GUI to change DNS settings is easier than using the Terminal. However, if you use multiple connections, you will have to change the DNS setting for each one of them. To change DNS settings using the GUI, just follow the steps below:

1. Open System Settings, and click on Network.

2. Click on the arrow next to the name of the network you’re connected to.

3. Now, click on “Settings”. This will open up the settings for that connection.

4. Switch over to the IPv4 tab, and you’ll see an option called “Additional DNS Servers“. You can enter the DNS servers you want to use in this field. If you want to enter more than one DNS server, just separate them with commas.

Change DNS Settings using the Terminal

If you don’t want to use the GUI, and prefer changing DNS settings using the Terminal, you can do this by adding the nameservers to the dnsmasq config file. However, dnsmasq does not come installed by default in Ubuntu systems (dnsmasq-base, does). So, first you’ll have to install dnsmasq by launching a Terminal, and using “sudo apt-get install dnsmasq“.

  • Once you have installed dnsmasq. You can edit the config file with “sudo nano /etc/dnsmasq.conf“.

  • Here, you can add your DNS servers’ IP addresses where it says “Add other nameservers here“.

Clear DNS Cache in Linux Using These Methods

You can use any of these methods to clear DNS cache in a Linux system. Issues with DNS cache can cause problems such as a webpage not loading, nameserver changes not being recognized by your system, and a lot more. Once you flush DNS cache, these problems will most likely go away. So, have you ever had to flush the DNS cache on your Linux system? If so, what method did you use? If you know of any other method to clear the DNS cache on your Linux system, do let us know in the comments section below.

Источник

How To Flush Linux / UNIX DNS Cache

I ‘m on a Dial UP Internet connection under Linux and frequent dial up disconnection causing dns problems. How do I flush DNS cache under UNIX / Linux distribution using a shell prompt?

Under MS-Windows you can use the ipconfig command to flush dns cache. However, Linux and UNIX provides various ways to flush cache. Linux can run nscd or BIND or dnsmasq as the name service caching daemon. Large and work-group servers may use BIND or dnsmasq as a dedicated caching server to speed up queries.

Читайте также:  Cisco прошивка под линукс

HowTo: Flush nscd dns cache

Nscd caches libc-issued requests to the Name Service. If retrieving NSS data is fairly expensive, nscd is able to speed up consecutive access to the same data dramatically and increase overall system performance. Just restart nscd:
$ sudo /etc/init.d/nscd restart
OR
# service nscd restart
OR
# service nscd reload
This daemon provides a cache for the most common name service requests. The default configuration file, /etc/nscd.conf, determines the behavior of the cache daemon.

Flush dnsmasq dns cache

dnsmasq is a lightweight DNS, TFTP and DHCP server. It is intended to provide coupled DNS and DHCP service to a LAN. Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. This software is also installed many cheap routers to cache dns queries. Just restart the dnsmasq service to flush out dns cache:
$ sudo /etc/init.d/dnsmasq restart
OR
# service dnsmasq restart

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Flush caching BIND server dns cache

A caching BIND server obtains information from another server (a Zone Master) in response to a host query and then saves (caches) the data locally. All you have to do is restart bind to clear its cache:
# /etc/init.d/named restart
You can also use rndc command as follows flush out all cache:
# rndc restart
OR
# rndc exec
BIND v9.3.0 and above will support flushing all of the records attached to a particular domain name with rndc flushname command. In this example flush all records releated to cyberciti.biz domain:
# rndc flushname cyberciti.biz
It is also possible to flush out BIND views. For example, lan and wan views can be flushed using the following command:
# rndc flush lan
# rndc flush wan

A note about Mac OS X Unix users

Type the following command as root user:
# dscacheutil -flushcache
OR
$ sudo dscacheutil -flushcache
If you are using OS X 10.5 or earlier try the following command:
lookupd -flushcache

A note about /etc/hosts file

/etc/hosts act as the static table lookup for hostnames. You need to remove and/or update records as per your requirements under Unix like operating systems:
# vi /etc/hosts
Sample outputs:

See also:

Related: Windows Vista / XP Flush DNS Cache with ipconfig Command

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How To Clear Or Flush DNS Cache In Linux

This brief guide explains all possible ways to clear or flush DNS cache in Linux operating systems. For those wondering, DNS cache (or sometimes called a DNS resolver cache) is a small temporary database maintained by the operating systems. It stores the information about all visited websites and other Internet domains. In other words, the DNS cache contains recent DNS lookups. When you visit the same website multiple times, the OS retrieves the DNS records of that website from the local DNS cache database instead of the actual public DNS server. Hence DNS caching improves the website loading time and reduces the origin DNS server’s bandwidth/CPU consumption.

Why should you clear or flush DNS cache?

There could be many reasons to clear the local DNS cache. For instance, you might have customized your website or changed the DNS settings for your domain or you are facing some Internet connectivity issues. In such cases, if you attempt to visit the site, your OS will likely to get the cached version of the site from the local DNS cache. So clearing the local DNS cache will delete all entries from the local DNS cache database and force your system to repopulate the DNS cache with new entries from the actual DNS server and display the fresh copy of the website.

Читайте также:  Как установить erlang windows

Clear Or Flush DNS Cache In Linux

By default, the DNS caching is not installed and/or enabled at the operating system level in Linux. Instead, applications like web browsers maintain their own internal cache. So you can simply clear your browser’s cache or restart them to fix the Internet-connectivity issues, resolve DNS spoofing (e.g. DNS cache poisoning) issues and resolve stale content issues. If your Linux distribution does use any DNS caching services, you need to manually clear them as described below. There are multiple ways to clear DNS cache. It varies depends upon the Linux distribution and DNS caching service you are using. Here I have included instructions to clear the most commonly used DNS caching services in Linux.

1. Clear Systemd-resolve DNS caching service

Systemd-resolve is a systemd service that provides system-level DNS caching service for local applications. It is part of the systemd package which is installed by default. Systemd-resolved service is enabled by default in most modern Linux operating systems such as Fedora and Ubuntu. First, let us check if systemd-resolved service is active or not using command:

If systemd-resolved service is enabled, you will see «active» in the output. If it is not active, it will print «inactive».

Check if systemd-resolved service is active

As you see in the above output, systemd-resolved service is active in my system.

Let us view the statistics of systemd-resolve caching service with command:

Sample output:

As you see, the above output lists the total no of current cache size, hits and missed caches.

To flush the systemd-resolve cache, run:

On successful execution, you will not see any output.

Now, check the systemd-resolve statistics to verify if the local DNS cache is cleared or not.

You will now see current cache size as zero.

Display systemd-resolve statistics

2. Clear Nscd DNS caching service

Nscd, short for name service cache daemon, is a caching daemon that provides a cache for the most common name service requests. It is the preferred caching service for most Redhat-based systems. If your Linux system is using nscd caching service, you can clear or flush the local DNS caching service by simply restarting the nscd service like below:

3. Clear Bind/Named DNS caching service

Berkeley Internet Name Domain (shortly BIND) is the most popular open source DNS server in use today. If you are using BIND for caching DNS queries, use the following commands to clear/flush BIND caching service in Linux:

The latest BID version allows you to clear DNS cache for a specific domain as well. The following command clears the DNS cache for ostechnix.com domain:

You can also clear DNS cache for entire LAN and WAN zones like below:

4. Clear Dnsmasq DNS caching service

Dnsmasq is a lightweight DHCP and caching DNS server with support for PXE and TFTP server. It is suitable for resource constrained routers and firewalls to manage small networks.

If you are using dnsmasq as caching service, you can flush the local DNS caching service like below:

Another way to c lear local DNS cache in Ubuntu and other Ubuntu variants such as Linux Mint is to run the following command:

Источник

Оцените статью