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?

  • 1
    I ran into the same thing yesterday. This took care of my issue: superuser.com/a/1200745 – Clay Oster Apr 19 '17 at 14:01
  • 3
    Possible duplicate of How do I clear the DNS cache? – Chai T. Rex Apr 22 '17 at 0:50
  • 1
    I have removed the solution part from the question. But you can find it here. 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. – 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 Jun 22 '19 at 11:34

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

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

Sample output:

  Current Cache Size: 0
          Cache Hits: 101
        Cache Misses: 256
  • This answer improves on the previous one so I have marked it as the one true answer. – dibs Apr 26 '17 at 21:54
  • 16
    When I run sudo systemd-resolve --flush-caches, I get systemd-resolve: unrecognized option '--flush-caches'. – Nathan Friend Jan 19 '18 at 17:35
  • 1
    Same as @NathanFriend - Checking the --help output, this subcommand was removed in 17.10 – Routhinator Feb 27 '18 at 22:48
  • 3
    I'm running Ubuntu 18.04 and the subcommand is there. – the_drow Jun 5 '18 at 14:48
  • 1
    Not there in Ubuntu 16.04 – adamczi Nov 27 '18 at 10:41

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.

  • This seems like the only way to clear everything to 0 when running --statistics immediately after. On Ubuntu 18 – sledgeweight Oct 12 '18 at 19:45

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

Maybe thats what youre looking for.


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


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!
  Current Cache Size: 0
  • 3
    Could you please expand the answer and maybe add installation process and usage? – pomsky Mar 28 '18 at 23:02
  • It's all on github. – dunderrrrrr Mar 31 '18 at 8:25
  • I agree, but link-only answers are not considered as answers on Stack Exchange sites. Thanks a lot for expanding your answer. – pomsky Mar 31 '18 at 10:35
  • 3
    It's only running systemd-resolve --flush-caches then systemd-resolve --statistics. : github.com/dunderrrrrr/dnscache/blob/master/dnscache – Ricky Notaro-Garcia Jun 28 '18 at 15:00
  • Well, thats the point. It's much faster typing sudo dnscache clear. Time is money, right. – dunderrrrrr Jul 8 '18 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.