Linux dns cache reset

Как очистить / сбросить кеш DNS в Linux

В некоторых случаях вам трудно добраться до некоторых сайтов из-за проблемы с DNS, возможно, ваш локальный DNS-кеш поврежден.

Для такой ситуации вам необходимо перезапустить службу кэширования DNS операционной системы.

Кэш-память DNS для системы доменных имен – это временная база данных, которая поддерживается операционной системой компьютера, которая содержит IP-адрес сайтов, которые вы недавно просматривали.

См. Ниже список основных серверов кэширования DNS, используемых в дистрибутиве Linux.

  • nscd DNS cache
  • dnsmasq dns cache
  • BIND server dns cache

nscd DNS Cache: nscd – демон кэша службы имен, Nscd – это демон, который обеспечивает кэш для наиболее распространенных запросов службы имен.

Файл конфигурации по умолчанию, /etc/nscd.conf

dnsmasq DNS Cache: Dnsmasq – легкий, небольшой в размере, простой в настройке, DNS-сервер и DHCP-сервер.

Он предназначен для предоставления DNS и опционально DHCP для небольшой сети и подходит для маршрутизаторов с ограниченным доступом и брандмауэров.

Он может обслуживать имена локальных машин, которые не входят в глобальный DNS.

Он предназначен для использования в персональных компьютерах и небольших сетях, а не для больших сетей.

BIND Server DNS Cache: BIND означает «Berkeley Internet Name Domain».

Наиболее широко используемое программное обеспечение сервера имен, BIND – это программное обеспечение с открытым исходным кодом, которое реализует протоколы доменных имен (DNS) для Интернета.

BIND на сегодняшний день является наиболее широко используемым программным обеспечением DNS в Интернете, обеспечивая надежную и стабильную платформу.

1) Очистить кеш DNS на Ubuntu / Debian / LinuxMint

Используйте приведенную ниже команду для очистки кеша DNS в системах Ubuntu / Debian / Mint.

2) Сброс кеша dns сервера BIND

Используйте приведенную ниже команду для сброса кеша BIND сервера dns

3) Очистить кэш nscd DNS

Используйте команду ниже:

4) Очистить dnsmasq dns кэш

Используйте приведенную ниже команду для стирания кеша dnsmasq server dns

5) Очистка кеша dns в Windows

Используйте приведенную ниже команду для очистки кеша dns в Windows:

Источник

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.

Читайте также:  Сменить пароль администратора 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:

Источник

How do I clear the DNS cache?

I just updated the DNS record ( ns1 , ns2 , ns3.myhostingcompany.com ) for a site I’ve got hosted, but I still get the domain registrar parking page.

I’d like to see if the problem is Ubuntu’s cached DNS records. Is there a way to clear Ubuntu’s DNS cache? (if such a thing exists?)

15 Answers 15

Ubuntu 17.04 and higher (18.04)

From Ubuntu 17.04 and onwards, systemd-resolve is used for DNS. You can flush systemd’s caches like so:

For 18.04 and higher

For 11.10 and below

Ubuntu doesn’t cache dns records by default so unless you’ve installed a dns cache there isn’t anything to clear.

DNS records are likely cached by your provider’s DNS servers so if you want to check if the DNS changes you made were successful you can interrogate a DNS server from your domain hosting service with dig:

dig -t a ns1.myhostingcompany.com @domain_registrar_dns_server

It you want Ubuntu to start caching dns I recommend installing pdnsd together with resolvconf . nscd is buggy and not advisable.

Ubuntu 12.04 uses dnsmasq which is built into network-manager , but it doesn’t cache dns so there is no need to flush it. Here is a sample line from my syslog to prove that point:

Читайте также:  Install windows with parallels

There is also no need for any configuration of dnsmasq . If you are running with stock settings it won’t be caching dns, as for it to do so you have to explicitly set it up as this Ubuntu article describes.

If you wanted to refresh your settings you could disable and then enable networking or run

This restarts dnsmasq because it is built in to network-manager ; check your syslog for the evidence for this.

If you are using a wired connection with dhcp network manager will be taking the settings direct from your router and your connection will be automatically established when you login to Ubuntu. You could check that the settings are correct in your router if you can access it via the web interface, and perhaps reboot it if necessary. If it is a general problem with dns, you could try using Google dns instead of your isp dns, and more information on that is detailed here.

Note that Ubuntu uses systemd-resolve from 17.04 and onwards so this answer doesn’t apply anymore to recent Ubuntu versions. See «flush DNS cache in Ubuntu 17.04 and higher (18.04)»

By default, DNS is not cached in Ubuntu dnsmasq is caching, run ps ax | grep dnsmasq and look at the running command. Here’s a breakdown of my default 13.10 machine:

/etc/NetworkManager/dnsmasq.d is empty by default. So there aren’t any overrides coming in there and just to check —cache-size=0 means what we think it means (instead of an unlimited cache), man dnsmasq shows:

So while dnsmasq can cache DNS, it isn’t caching out the box. You can check your machine and various configuration directories to check you’re on the same page.

If you are seeing cache issues, this is likely happening in one of a few places:

  • Upstream from your computer. Some routers cache. Many corporate networks will cache DNS. Many ISP-run DNS servers and will use their own caches. The only way to guarantee against a network cache is to use a cache you can manually refresh. This is why I like OpenDNS.
  • In the client application (notably browsers). Applications can do all sorts of their own caching that Ubuntu has no effect on. How Firefox caches DNS. How to clear Chrome’s DNS cache. Other browsers (and applications) might have their own mechanisms.

I’m scraping the barrel here but perhaps you’ve installed a non-standard DNS server in Ubuntu instead of turning caching on in dnsmasq . There are many: nscd , DJBDNS dnscache (aka TinyDNS), pdns , pdnsd , Bind9 (and its variants), and more I can’t even remember. These will probably be evidenced in /etc/resolv.conf (with config in /etc/resolvconf/` to autogen that file). The following shows an locally intercepted DNS query:

If you’re not hitting 8.8.8.8 (or whatever you expect your DNS server to be), check what you are hitting instead. In my case I can see this is just dnsmasq set up to mirror DNS queries back for LXC, but in your case it might be doing bad cachey things.

If you have done of the listed caches, the process for clearing each varies:

Источник

How To Flush DNS Cache On Linux (For systemd-resolved, BIND, Dnsmasq Or nscd)

This article explains how to flush the DNS cache (clear it) on Linux, not only for systems that use systemd-resolved (e.g. Ubuntu 18.04 and newer), but also for those using nscd, BIND or Dnsmasq to cache DNS queries.

DNS, or Domain Name System, is like the Internet’s phonebook, translating human-friendly computer hostnames into IP addresses. For example, google.com is translated to the 216.58.214.238 IPv4 address, and 2a00:1450:400d:808::200e IPv6 address. This way the domain name can change the IP address without affecting its users, and without changing the its name.

The DNS cache (or DNS resolver cache) is a temporary database that stores these records, which is used to quickly lookup a website when you’re trying to visit it.

If the DNS is cached, you might not be able to access some hostnames that were changed recently — until your DNS cache is updated or cleared, that’s why it’s useful in some situations to flush / clear the DNS cache. After the DNS cache is cleared, the new addresses are taken from the DNS server set for your network.

How to flush the DNS cache when using systemd-resolved

systemd-resolved is a network name resolution manager. It implements a caching and validating DNS/DNSSEC stub resolver, as well as an LLMNR and MulticastDNS resolver and responder.

systemd-resolved is used by default on recent versions of many Linux distributions, including Ubuntu, Linux Mint and Fedora.

Don’t know if you system uses systemd-resolved? Use:

In case this command returns active , then your system has systemd-resolved enabled and active. If anything else (e.g. inactive ) is shown, then systemd-resolved is not used on your system.

Flush the DNS cache when using systemd-resolved:

Check the DNS cache using:

The Current Cache Size is the value you’re looking for. If it’s 0 , you just flushed the DNS cache.

Example with output (ran immediately after flushing the DNS cache, so the cache size is 0):

How to flush the DNS cache when using BIND

BIND or «named» acts as an authoritative name server for one or more specific domain, as well as a recursive resolver for the DNS system generally, and it can act as a caching DNS server. Bind had three major revisions, with BIND4 and BIND8 being technically obsolete, and BIND9 being the supported version, which features DNSSEC in addition to other features and enhancements.

To check if BIND (the service name is «named») is active on your system (though note that most cases it’s active only if you install and enable it explicitly), you could run:

When active is returned by this command, it means the service is active on your system.

On older systems, or systems without systemd, you could check the service status instead, using

To flush the DNS cache for BIND (named), use:

Checking if the DNS cache has been cleared is a bit more complicated for BIND. After flushing the DNS cache, run the command that follows below to dump the cache:

The cache file is now saved in /var/named/data/cache_dump.db . You can look at this file as root to check if there are any cached DNS entries:

If the cache was flushed (so there are no cached DNS entries), this file should look like this:

If it contains entries like the ones that follow below, the DNS cache was not flushed:

How to flush the DNS cache when using Dnsmasq

Dnsmasq is a DNS forwarder and DHCP server that can be used as a caching DNS server.

To check if dnsmasq is active on your system, you could run:

When active is returned by this command, it means the service is active on your system.

On older systems, or systems without systemd, you could check the service status instead, using:

To flush the DNS cache when using Dnsmasq, restart its service:

On older systems, or systems without systemd, use this command to flush the DNS cache for Dnsmasq:

I couldn’t find a way of checking if the dnsmasq has been flushed.

How to flush the DNS cache when using nscd

nscd is a name service cache daemon.

To check if nscd is active on your system (though note that most cases it’s active only if you install and enable it explicitly), you could run:

When «active» is returned by this command, it means the service is active on your system.

On older systems, or systems without systemd, you could check the service status instead, using:

While most guides you’ll find online mention to restart the nscd service, that doesn’t actually flush the DNS cache, since the files are still stored in /var/db/nscd , and are used after the nscd service starts again. What you actually want to do to flush the DNS cache for nscd is to invalidate the cache.

To invalidate the hosts cache (to flush the DNS hosts cache) when using nscd, use:

To check if the DNS cache was flushed, run:

And look under the hosts section (if you have multiple enabled), and you should see 0 as the value for used data pool size if the DNS cache was just flushed. It will slowly increase as the DNS are used to access various hosts / domains names.

Example with output (after the DNS cache was flushed):

Источник

Читайте также:  Windows help file download
Оцените статью