{"id":4182,"date":"2021-02-10T05:54:35","date_gmt":"2021-02-10T05:54:35","guid":{"rendered":"https:\/\/linuxways.net\/?p=4182"},"modified":"2021-02-10T05:54:41","modified_gmt":"2021-02-10T05:54:41","slug":"how-to-flush-dns-cache-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-flush-dns-cache-on-ubuntu-20-04\/","title":{"rendered":"How to Flush DNS Cache on Ubuntu 20.04"},"content":{"rendered":"<p>DNS server is used to convert domain names to IP addresses. When you type a website name in to address bar of your browser, your system does not know where to find this address. It asks for this address from the DNS server. The DNS server contains the mapping of the domain name to IP addresses. This domain name to IP address mapping changes from time to time.<\/p>\n<p>Our system also maintains a temporary database containing domain to IP mapping information about the sites we visited recently. This temporary database is known as DNS cache. It is used to avoid fetching the frequently or recently visited sites more quickly from the locally stores DNS cache instead of retrieving them from DNS servers.<\/p>\n<p>Sometimes, it is required to flush the DNS cache. This is required in cases like when the cache becomes corrupted, and it is redirecting you towards the wrong websites. It is also needed when a site is moved to a different address but you the browser is still loading the old site. Flushing the DNS cache deletes the entire domain to IP mapping entries including old and invalid records. The next time when the system tries to access the websites, DNS cache repopulates the new entries.<\/p>\n<p>Let\u2019s see how to flush the DNS cache on Ubuntu.<\/p>\n<p><strong>Note<\/strong>: The procedure described here has been tested on <strong>Ubuntu 20.04 LTS<\/strong>. The commands have been executed on Terminal which can be opened through <strong>Ctrl+Alt+T<\/strong> shortcut.<\/p>\n<h2>How to Flush the DNS Cache<\/h2>\n<p>Most Ubuntu (18.04 and later) and Debian systems use systemd-resolved daemon to cache DNS queries. We can also use it to flush the DNS cache.<\/p>\n<h3>1. Check \u201csystemd-resolved\u201d Status<\/h3>\n<p>Let\u2019s first check if systemd-resolved is running. Execute the below command to do so:<\/p>\n<pre>$ sudo systemctl is-active systemd-resolved<\/pre>\n<p>If you see \u201c<strong>active<\/strong>&#8221; in the above command&#8217;s output, it means systemd-resolved is running on your system.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"71\" class=\"wp-image-4183\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-89.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-89.png 653w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-89-300x33.png 300w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/p>\n<h3>2. View Current Cache Size<\/h3>\n<p>Now if you want to view the current cache size along with some other information, execute the below command in Terminal:<\/p>\n<pre>$ sudo systemd-resolve --statistics<\/pre>\n<p>Following is the output of the above command, which shows different information. At present, we are only concerned with the \u201c<strong>Current Cache Size<\/strong>\u201d, which is <strong>8.<\/strong> We want to make the cache size <strong>0<\/strong> by flushing it.<\/p>\n<h3>3. Flush DNS Cache<\/h3>\n<p>Now in order to flush the DNS cache, execute the below command in Terminal:<\/p>\n<pre>$ sudo systemd-resolve --flush-caches<\/pre>\n<h3>4. Verify the Cache Size<\/h3>\n<p>You can then look up the statistics to ensure that the size of your cache is now zero:<\/p>\n<pre>$ sudo systemd-resolve --statistics<\/pre>\n<p>The following output shows the current cache size is \u201c0\u201d which confirms that the DNS cache has been cleared now.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"391\" class=\"wp-image-4185\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-90.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-90.png 574w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-90-300x204.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/p>\n<p>This is how to flush the DNS cache on Ubuntu. If the sites are not loading properly or you are receiving outdated sites, try to flush the DNS cache to see if the issue resolves. Remember, after the DNS cache is flushed, sites will first load slightly slower. But once the DNS cache is re-populated, sites will be loaded faster.<\/p>","protected":false},"excerpt":{"rendered":"<p>DNS server is used to convert domain names to IP addresses. When you type a website name in to address bar of your browser, your system does not&hellip;<\/p>","protected":false},"author":4,"featured_media":4184,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[185,100],"class_list":["post-4182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-flush-dns-cache","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4182","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\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4182"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4182\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4184"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}