88

How can I flush the DNS on Ubuntu 17.04?

I seem to have a few DNS issues at the moment since upgrading to 17.04 from 16.10 and went to flush the DNS but I can't find how to.

Can anyone tell me please?

dibs
  • 3,479
  • 8
  • 27
  • 38
  • 1
    I ran into the same thing yesterday. This took care of my issue: https://superuser.com/a/1200745 – Clay Oster Apr 19 '17 at 14:01
  • 3
    Possible duplicate of [How do I clear the DNS cache?](https://askubuntu.com/questions/2219/how-do-i-clear-the-dns-cache) – Chai T. Rex Apr 22 '17 at 00:50
  • 1
    I have removed the solution part from the question. But you can find it [here](https://askubuntu.com/revisions/906476/2). Please post the solution part in the "Your Answer" field below. It's completely okay to answer your own question and accept your answer. Also please [don't add "SOLVED" tag to title](https://meta.stackexchange.com/questions/116101/is-it-ok-to-add-solved-to-the-title-of-a-question). – pomsky Mar 31 '18 at 10:41
  • I've found nothing works short of rebooting the system and walking on egg-shells – ThorSummoner Feb 11 '19 at 17:47
  • 1
    If you are using Chrome and are having cache issues, it'll also help to clear Chrome's dns cache chrome://net-internals/#hsts – Peter Chaula Jun 22 '19 at 11:34

3 Answers3

124

You may use this command: sudo systemd-resolve --flush-caches

To verify that flush was sucessfull, use: sudo systemd-resolve --statistics

Sample output:

Cache
  Current Cache Size: 0
          Cache Hits: 101
        Cache Misses: 256
Dmitry Sidorenko
  • 1,364
  • 1
  • 8
  • 4
34

This command should restart the local name service and flush the local DNS cache:

systemctl restart systemd-resolved.service

There is probably a way of getting it to just flush the cache instead of restart, but restart suited my purposes.

tigs001
  • 451
  • 3
  • 3
0

I made this: https://github.com/dunderrrrrr/dnscache

Maybe thats what youre looking for.

Installation

$ git clone git@github.com:dunderrrrrr/dnscache.git
$ cd dnscache/
$ sudo cp dnscache /usr/local/bin/
$ sudo chmod +x /usr/local/bin/dnscache

Usage

There are two arguments that can be passed to the script, clear or stats. Both of them should be self explanatory.

$ sudo dnscache clear
DNS cache has been cleared!
[...]
Cache
  Current Cache Size: 0
[...]