Skip to content

Instantly share code, notes, and snippets.

@craigvantonder
Last active February 3, 2021 04:42
Show Gist options
  • Star 43 You must be signed in to star a gist
  • Fork 22 You must be signed in to fork a gist
  • Save craigvantonder/e9ee426f4108094d56e76ba1f756035e to your computer and use it in GitHub Desktop.
Save craigvantonder/e9ee426f4108094d56e76ba1f756035e to your computer and use it in GitHub Desktop.
Flushing the DNS in Ubuntu 16.04
#!/bin/bash
# NB: First install nscd with sudo apt-get install nscd
# run this command to flush dns cache:
sudo /etc/init.d/dns-clean restart
# or use:
sudo /etc/init.d/networking force-reload
# Flush nscd dns cache:
sudo /etc/init.d/nscd restart
# If you wanted to refresh your settings you could disable and then run
sudo service network-manager restart
echo "DNS Flushed!";
# Output:
# craig@laptop:~$ sh Desktop/Scripts/flush-dns.sh
# [sudo] password for craig:
# [ ok ] Reloading networking configuration (via systemctl): networking.service.
# [ ok ] Restarting nscd (via systemctl): nscd.service.
# DNS Flushed!
@whitegray
Copy link

hy Craig
please help me
my output is as follows:
,,
sudo /etc/init.d/dns-clean restart (((= NO MESSAGE AT ALL)))
sudo /etc/init.d/nscd restart
sudo: /etc/init.d/nscd: command not found
,,
why is this happening ?
thanks a lot
have them nice :)

@Mario-paul
Copy link

All of these give me command not found.

@Anti-gravitry
Copy link

@Ineptsmeagol
Copy link

It looks like you do not have nscd installed you can install it by doing sudo apt-get install nscd on Ubuntu

@craigvantonder
Copy link
Author

Correct, you must install nscd first. Added this and example output to the gist.

@lain0
Copy link

lain0 commented Apr 13, 2018

if you use systemd-resolve in 16.04

sudo systemd-resolve --flush-caches

@monsterddq
Copy link

when i run: sudo systemd-resolve --flush-caches , I get a error: sudo systemd-resolve --flush-caches in Ubuntu 16.04.
Please help me.

@nonintanon
Copy link

Couldn't get sudo systemd-resolve --flush-caches to work on Ubuntu 16.04 as well.

@lmj0011
Copy link

lmj0011 commented Sep 5, 2018

Couldn't get sudo systemd-resolve --flush-caches to work on Ubuntu 16.04 as well.

systemd-resolved doesn't seem to be an active service by default in Ubuntu 16.04.

You have to start it first with sudo systemctl start system-resolved

@panayotkulchev
Copy link

I had ERR_NAME_NOT_RESOLVED Error in Chrome. sudo /etc/init.d/dns-clean restart helped. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment