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,489

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
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
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
[...]