How to clear DNS cache of your Operating System

How to clear DNS cache of your Operating System
5 (100%) 5 votes

DNS Cache (sometimes called DNS resolver cache) is the way your system has to grab a copy of the internet locations (IP addresses) of each website that you recently visited. DNS Resolver Cache is a DNS database that includes records of all the recent visits to websies and other internet domains.

The purpose of DNS Cache

This DNS Cache is stored in your operating system and serves as a fast way to know where the sites are located. However, if a website is migrated to a different network, using a different IP, and your DNS cache is still not updated, you will not be able to access the site unless you clear DNS cache on your OS.

Once you clear your DNS cache, your system will start retrieving the DNS Name Servers for the new DNS records of the website. This is basically how DNS Cache works. Now that you know the basics of DNS Cache, let’s learn how to clear DNS cache on different operating systems.

How to Clear DNS Cache on your local Operating System

Before getting into how to clear the DNS cache of your PC we will learn how to see what’s stored inside your local cache.

How can I see what’s inside my DNS Cache?

On Linux, the best way to see how your DNS Resolver cache is working, is to use dig command.

dig nixcp.com

Which will in return give you a DNS Record from your DNS Server specified in /etc/resolv.conf:

Expected output:

[webtech@localhost ~]$ dig nixcp.com

; <<>> DiG 9.10.4-P5-RedHat-9.10.4-4.P5.fc25 <<>> nixcp.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<nixcp.com.		1800	IN	A	208.167.252.238

On Linux you can find ways to clear the dns cache, and to resolve dns records using dig, but not to see cached dns records on your local system, at least I’m not aware of anything like that.

On Windows operating systems it is a different story. You can easily see the cached records by running this steps.

  1. Open the WinX Menu by pressing: Press Win+X.
  2. Right-click on “Command Prompt”
  3. Select “Run as Administrator”.
  4. Type “ipconfig /displaydns” and hit enter:
ipconfig /displaydns

You should get something like this as this:

C:\Documents and Settings\my.logon>ipconfig /displaydns

Windows IP Configuration

nixcp.com
----------------------------------------
Record Name . . . . . : nixcp.com
Record Type . . . . . : 1
Time To Live . . . . : 1800
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 208.167.252.238


www.cpanel.com
----------------------------------------
Record Name . . . . . : www.cpanel.com
Record Type . . . . . : 1
Time To Live . . . . : 100
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 208.74.123.68


redhat.com
----------------------------------------
Record Name . . . . . : www.redhat.com
Record Type . . . . . : 1
Time To Live . . . . : 3600
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 209.132.183.105

Clear your DNS cache

The next  methods will show you how to clear dns cache of your operating system. This will remove innacurate DNS caching information that will help you to avoid 404 errors while browsing recently migrated websites.

Windows 8

To clear your DNS cache on Windows 8 follow the next steps:

  1. Open the WinX Menu by pressing: Press Win+X.
  2. Right-click on “Command Prompt”.
  3. Select “Run as Administrator”.
  4. Run the following command:
ipconfig /flushdns

The output should show you this message if your dns cache was cleared successfully:

Windows IP configuration successfully flushed the DNS Resolver Cache.

Windows 7

In order to clear DNS cache on Windows 7, follow this steps:

  1. Click Start.
  2. Enter cmd in the Start menu search text box.
  3. Right-click on “Command Prompt”.
  4. Select “Run as Administrator”.
  5. Run the following command:
ipconfig /flushdns

The output should show you this message if your dns cache was cleared successfully:

Windows IP configuration successfully flushed the DNS Resolver Cache.

Windows XP, 2000, and Windows Vista

Flush the DNS cache on Windows XP, 2000 or Vista is easy, follow this steps:

  1. Click Start.
  2. On the Start menu, click “Run”.
  3. If you don’t see the “Run” command in Vista: type “run” in the Search bar.
  4. Run the following command inside the “Run” text box:
ipconfig /flushdns

The output should show you this message if your dns cache was cleared successfully:

Successfully flushed the DNS Resolver Cache.

Linux Systems

Flush DNS cache on Linux is even easier than on Windows.
Follow the next steps to clear DNS cache on Linux if you are using a DNS Caching daemon:

  1. Open your terminal, login as root.
  2. Restart the name service caching daemon:

Flush NSCD dns cache

/etc/init.d/nscd restart

Flush bind dns cache

/etc/init.d/named restart

or you can try

rndc restart

Flush dnsmasq dns cache

service dnsmasq restart

MacOS® 10.10.4 and above

Clear your DNS Cache on MacOS X 10.10.4 or above. Follow the next steps:

  1. Click Applications.
  2. Click Utilities.
  3. Click Terminal.

Type the following command:

sudo killall -HUP mDNSResponder

If the command succeeds the system will not show any output, this means the dns cache was cleared successfully.

MacOS® 10.10.1, 10.10.2, 10.10.3

To clear your DNS cache if you use MacOS X version 10.10 through 10.10.3, perform the following steps:

  1. Click Applications.
  2. Click Utilities.
  3. Click Terminal.

Run the following command:

sudo discoveryutil mdnsflushcache

If the command succeeds the system will not show any output, this means the dns cache was cleared successfully.

MacOS 10.7, 10.8, 10.9

Follow this steps to flush dns cache on MacOS 10.7, 10.8, 10.9:

  1. Click Applications.
  2. Click Utilities.
  3. Double-click Terminal.

Type the following command:

sudo killall -HUP mDNSResponder

If the command succeeds the system will not show any output, this means the dns cache was cleared successfully.

MacOS 10.5 – 10.6

Follow this steps to flush the DNS cache on MacOS X 10.5 or 10.6:

  1. Click Applications.
  2. Click Utilities.
  3. Double-click Terminal.
  4. Type the following command:
sudo dscacheutil -flushcache

If the command succeeds the system will not show any output, this means the dns cache was cleared successfully.

Clear the /etc/hosts file

On previous posts we’ve written about how to preview a website without switching DNS, on that post you saw that /etc/hosts can be configured to force website to resolve on specific IP address.

If you are using the /etc/hosts file to force dns lookups for a certain host, you may need to update your /etc/hosts file entries to avoid getting 404 errors.

Output example of /etc/hosts file with forced dns records:

[webtech@localhost ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

111.111.111.111 dev.nixcp.com
192.168.1.110 www.nixcp.com

As you see, there are two extra records (dev.nixcp.com and www.nixcp.com), if you are using that kind of records you may need to clear them out too.