89

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?

5
  • 1
    I ran into the same thing yesterday. This took care of my issue: superuser.com/a/1200745
    – Clay Oster
    Apr 19, 2017 at 14:01
  • 3
    Possible duplicate of How do I clear the DNS cache? Apr 22, 2017 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, 2018 at 10:41
  • I've found nothing works short of rebooting the system and walking on egg-shells Feb 11, 2019 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 Jun 22, 2019 at 11:34

3 Answers 3

125

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
6
  • This answer improves on the previous one so I have marked it as the one true answer.
    – dibs
    Apr 26, 2017 at 21:54
  • 17
    When I run sudo systemd-resolve --flush-caches, I get systemd-resolve: unrecognized option '--flush-caches'. Jan 19, 2018 at 17:35
  • 1
    Same as @NathanFriend - Checking the --help output, this subcommand was removed in 17.10 Feb 27, 2018 at 22:48
  • 3
    I'm running Ubuntu 18.04 and the subcommand is there.
    – the_drow
    Jun 5, 2018 at 14:48
  • 1
    Not there in Ubuntu 16.04
    – adamczi
    Nov 27, 2018 at 10:41
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.

1
  • This seems like the only way to clear everything to 0 when running --statistics immediately after. On Ubuntu 18 Oct 12, 2018 at 19:45
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
[...]
6
  • 3
    Could you please expand the answer and maybe add installation process and usage?
    – pomsky
    Mar 28, 2018 at 23:02
  • It's all on github. Mar 31, 2018 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, 2018 at 10:35
  • 4
    It's only running systemd-resolve --flush-caches then systemd-resolve --statistics. : github.com/dunderrrrrr/dnscache/blob/master/dnscache Jun 28, 2018 at 15:00
  • 1
    seems like a cheap attempt to farm rep.
    – Phil
    Feb 18, 2019 at 21:48

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.