{"id":17319,"date":"2022-05-22T10:22:38","date_gmt":"2022-05-22T10:22:38","guid":{"rendered":"https:\/\/linuxways.net\/?p=17319"},"modified":"2022-05-30T07:36:33","modified_gmt":"2022-05-30T07:36:33","slug":"how-to-view-the-contents-of-dns-cache-on-ubuntu-and-windows","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-view-the-contents-of-dns-cache-on-ubuntu-and-windows\/","title":{"rendered":"How to View the Contents of DNS Cache on Ubuntu and Windows"},"content":{"rendered":"<p>Have you ever thought about how your web browser works? When you type in a URL (or a domain name) into the address bar of your web browser, it takes the URL and sends it to the Domain Name System to decipher the IP address of the webserver. Once the browser has the details, it then connects with the webserver to load up your requested website. If you want to read in detail about what is a Domain Name System and how it works, you can read about it in our other post \u201c<a href=\"https:\/\/linuxways.net\/de\/centos\/what-is-a-dns-cache\/\" target=\"_blank\" rel=\"noopener\">What is a DNS Cache?<\/a>\u201d.<\/p>\n<p>Now there might be times when you would run into network issues, for instance, you might be typing in the right URL but the website which loads could be different, or you might run into errors similar to the \u201cDNS server not responding\u201d errors. While running into these issues occasionally might not be such a huge hindrance, if you know that the error has something to do with your local DNS, knowing how to display the contents of your DNS cache can be a lifesaver.<\/p>\n<h2>How to check the contents of your DNS Cache on Ubuntu<\/h2>\n<p>Since Fedora 33 along with Ubuntu 20.10, many Linux distributions have switched to \u201csystem-resolved\u201d for handling DNS along with many other necessary operations of the Internet. Though it has been around for longer than a while, many of the distros showed hesitation to make the switch.<\/p>\n<p>Though systemd is more than capable of handling the requirements of running tasks related to the DNS, there is no straightforward way to view the entries of the DNS cache. To get started, we need to send a kill signal to the service. Don\u2019t worry, it doesn\u2019t kill the service altogether but it writes the current entries of the cache to the system log. The kill command is:<\/p>\n<pre><strong><em>$sudo killall -USR2 systemd-resolved<\/em><\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"93\" class=\"wp-image-17320\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-90.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-90.png 525w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-90-300x53.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/p>\n<p>As you see, you\u2019ll need to remember the sudo password for your account. Once you input the password, you\u2019re going to get an instantaneous response with the return of your prompt.<\/p>\n<p>Now you need to export these commands from the system log into a text file. You can achieve this goal through this command:<\/p>\n<pre><strong><em>$sudo journalctl -u system-resolved &gt; ~\/dns-cache.txt<\/em><\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"54\" class=\"wp-image-17321\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-91.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-91.png 689w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-91-300x24.png 300w\" sizes=\"auto, (max-width: 689px) 100vw, 689px\" \/><\/p>\n<p>The command shown above will create a file with the same name, i.e., \u201cdns-cache.txt\u201d in your home directory. You can keep the name of the file to anything you please. Depending on how many entries you have in your DNS Cache, this command can take anywhere from 2-30 seconds.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"222\" class=\"wp-image-17322\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-92.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-92.png 890w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-92-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-92-768x192.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/p>\n<h3>Viewing the file through the text editor<\/h3>\n<p>You can directly open up this text file to view the entries in your DNS cache, by double-clicking on the file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"124\" class=\"wp-image-17323\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-93.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-93.png 900w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-93-300x41.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-93-768x106.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>You can view all the entries of your DNS cache and easily edit the file if you want to.<\/p>\n<h3>Viewing the file through the terminal<\/h3>\n<p>In your terminal, type the following to open up the file in the terminal.<\/p>\n<pre><strong><em>$less ~\/dns-cache.txt<\/em><\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"166\" class=\"wp-image-17324\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-94.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-94.png 738w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-94-300x67.png 300w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/p>\n<h2>How to check the contents of your DNS Cache on Windows<\/h2>\n<p>There are various ways you can check the contents of your local DNS cache on Windows. Let\u2019s take a look at the top two ways you can easily employ:<\/p>\n<h3>Through the command prompt<\/h3>\n<p>This is fairly simple and easy to remember. Start by opening your command prompt and type:<\/p>\n<pre>\u201cipconfig \/displaydns\u201d<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"387\" height=\"91\" class=\"wp-image-17325\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-95.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-95.png 387w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-95-300x71.png 300w\" sizes=\"auto, (max-width: 387px) 100vw, 387px\" \/><\/p>\n<p>Upon pressing enter with this command, you\u2019ll get results such as the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"152\" class=\"wp-image-17326\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-96.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-96.png 442w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-96-300x103.png 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/p>\n<p>Let\u2019s break down this output further. The \u201cRecord Name\u201d is the name your browser uses to query the DNS server for and its records. The \u201cRecord Type\u201d refers to the type of entry which corresponds with a DNS protocol. \u201cTime to Live\u201d or TTL describes how long an entry is valid for, displayed in seconds. Data Length describes the length of the entry in bytes, an IPv4 address is 4 bytes and IPv6 addresses are 16 bytes. The \u201cSection\u201d holds the answer to the query.<\/p>\n<p>Last but not the least, \u201cA (Host) Record\u201d is the IP address corresponding to the URL in your browser.<\/p>\n<h4>Exporting the records<\/h4>\n<p>You can export the results of this query by typing \u201cipconfig \/displaydns &gt; dnscacheoutput.txt\u201d in your command prompt.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"377\" height=\"115\" class=\"wp-image-17327\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-97.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-97.png 377w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-97-300x92.png 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/p>\n<p>In this command, you can replace \u201cdnscacheoutput\u201d with any name of your choice.<\/p>\n<p>Executing this command will create a file containing all of the contents of your DNS cache in your current directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"304\" height=\"99\" class=\"wp-image-17328\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-98.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-98.png 304w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-98-300x98.png 300w\" sizes=\"auto, (max-width: 304px) 100vw, 304px\" \/><\/p>\n<h3>Through the PowerShell<\/h3>\n<p>As discussed, you can also view the contents of your local DNS cache using the Windows PowerShell. Open the Windows PowerShell with Admin privileges, and then type this \u201cGet-DnsClientCache\u201d. It will list all of the entries in a tabular form as such:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"158\" class=\"wp-image-17329\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-99.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-99.png 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-99-300x65.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>If you\u2019ve followed through the tutorial step by step, you now know how to view the contents of your local DNS cache on Windows and Ubuntu 20.04. Though the process isn\u2019t as easy on Ubuntu as compared to Windows, it requires you to understand the flow and execute 3 commands. If you run into any issues with these commands, or if you want to know more about the DNS cache and its entries, feel free to drop us a comment below and we\u2019ll be glad to help.<\/p>","protected":false},"excerpt":{"rendered":"<p>Have you ever thought about how your web browser works? When you type in a URL (or a domain name) into the address bar of your web browser,&hellip;<\/p>","protected":false},"author":1,"featured_media":17369,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[864,185,31,30],"class_list":["post-17319","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-dns","tag-flush-dns-cache","tag-ubuntu","tag-windows"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/17319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=17319"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/17319\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/17369"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=17319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=17319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=17319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}