How to: Clear DNS cache on all kind of systems

Contents

Every few weeks I stumble across the same issue again: “How could the DNS cache be cleared again?” I admit, clearing DNS cache is not a daily task, but when it comes to it, you usually forgot the commands. That’s why the following is a short tutorial on how to empty the DNS cache in various operating systems and browsers.

Before we get to the individual solutions, I’d like to quickly explain what the DNS cache is for in the first place and when you should flush it (that’s the English term).

What is the DNS cache and when should you clear it?

The Domain Name System (DNS) is an essential service within IP-based networks, such as the Internet. If a user makes a request to a server via a program and uses a domain such as “code-bude.net”, the program first makes a request to a name server, which then determines the corresponding IP address for the domain and informs the program of this. Using the knowledge of the IP address, the program then makes the actual request. The “program” can be a web browser, a game, the operating system itself or any other application that communicates over the network.

Windows DNS-Cache leeren

However, since the queries to the name server take time and the IP address assigned to the domain usually do not change frequently, operating systems and sometimes also applications operate a so-called DNS cache. In this local cache, the IP address to domains mappings are kept for a certain time. When a domain name is requested again, the cache is first checked to see whether an entry already exists. In practice, this saves time. The period for which an entry is retained in the cache is determined by the name server itself.

When should you proactively empty the cache? This only makes sense if the IP address of a domain has changed, but there is still an old entry in the cache. This is mostly the case if you have changed the entry of your own domain. But also, if third parties have changed the entries of their domain and a website is apparently no longer accessible, it can be useful to clear the DNS cache before you go on further troubleshooting.

Clear DNS cache in Windows

The easiest and fastest way to clear the DNS cache in Windows is to enter a short command in the CMD. To do this, open the command line (Windows key + R, type “CMD”, press Enter).

Within the CMD, issuing the following command is sufficient to flush the DNS cache:

ipconfig /flushdns

Clear DNS cache in OSX / macOS

On Mac OSX it is not quite as simple as on Windows, since there is a different command for almost every OSX version. But all methods have one thing in common – they are all entered into the terminal.

So, to clear the DNS cache in OSX, the Terminal must be opened first. (Either via: cmd+spacebar, type “Terminal”, press Enter or via the application menu.) The command to enter depends on the OSX version.

OSX >= 10.10.4

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder;

OSX >= 10.10

sudo discoveryutil mdnsflushcaches; sudo discoveryutil udnsflushcaches

OSX 10.9

dscacheutil -flushcache; sudo killall -HUP mDNSResponder

OSX >= 10.7

sudo killall -HUP mDNSResponder

OSX >= 10.5

sudo dscacheutil -flushcache

OSX <= 10.4

lookupd -flushcache

Clear DNS cache in Linux

Under Linux it behaves in some respects similarly to Mac OSX. Here, too, there are various commands that can lead to the target. The choice of command depends on the DNS software components used. If one of the commands below does not work, it should be checked again whether an alternative DNS server/cache such as BIND is being used, if necessary.

dns-clean und networking / flush DNS cache

sudo /etc/init.d/dns-clean restart sudo /etc/init.d/networking force-reload

dnsmasq / empty DNS cache

sudo /etc/init.d/dnsmasq restart

nscd / Delete DNS cache

sudo /etc/init.d/nscd restart

Empty BIND DNS

sudo /etc/init.d/named restart

pdnsd / Delete DNS cache

sudo pdnsd-ctl empty-cache

Clear DNS cache in Chrome Browser

To clear the DNS cache in Google’s Chrome browser, a special url must be called that opens a page with information internal to the browser. The page can be reached at the following address:

chrome://net-internals/#dns

If you enter the url in the address bar, you will get to the overview page of Chrome’s internal DNS cache. Here you can view all entries and also flush the internal DNS cache by clicking the “Clear host cache”-button.

Clear DNS cache in Firefox

In Firefox, similar to the procedure in Chrome, you also need to enter a special address in the browser’s address bar. The following url opens the advanced settings of the Firefox browser. The warning message when opening the page can be ignored, since we open the settings for a good reason and with full awareness.

about:config

Within the settings the entry named “network.dnsCacheExpiration” must be searched for and set to the value 0. If the entry does not exist, it must be created. Setting it to 0 will clear the cache. Afterwards the value should be increased again. (e.g. to 3600 to get the cache entries for one hour).

Clear DNS cache in Opera

In Opera, there is no way to clear the cache at your own request. According to senior developer Yngve Nysæter Pettersen, the cache entries are automatically invalidated every 10 minutes and thus requested again. If you don’t want to wait that long, you can close the Opera browser completely once. The next time you open it, the DNS cache is also cleared.

Clear DNS cache in Internet Explorer

Internet Explorer does not have its own DNS cache. It uses Windows’ own DNS cache. Therefore, to clear the Microsoft Internet Explorer DNS cache, it is enough to perform the steps necessary to flush the Windows-wide DNS cache. (The individual commands can be found at the beginning of the article).

Clear DNS cache on iOS on iPhone and iPad

There are three ways to clear the DNS cache on iOS. Variant 1 is to activate and then deactivate the flight mode. Sometimes, however, permanent entries in the DNS cache are not removed correctly. In this case, variants 2 and 3 remain. Variant 2 is to delete the network settings. This can be done via “Settings–>General–>Reset–>Network settings”. Variant 3 is a complete restart of the iOS device.

Clear Android DNS cache

There are also 3 ways to flush the DNS cache on Android. If only the DNS cache of the Chrome browser is to be cleared, the same command as in the above section for the Chrome browser can be used. If the system-wide DNS cache is to be cleared, either the device can be restarted or, if shell access and root are available, the following command can be issued in the terminal.

ndc resolver flushdefaultif

Leave a comment

Please be polite. We appreciate that. Your email address will not be published and required fields are marked