Logo

Armand.nz

Home / About / Linkedin / Github

How to Flush DNS on various OS

#dns #linux #windows #MacOS |

Bouncing around from different Operating Systems I often forget the terminal commands to flush the DNS cache. So here they are…

Ubuntu and Debian

The systemd-resolve service is used on most Ubuntu and Debian systems. It’s already in use on your system for a variety of functions. So, clear the cache with the following command:

sudo systemd-resolve --flush-caches

You can then check the statistics in order to make sure that your cache size is now zero, thus cleared. Run the following command in order to view the statistics:

# You cache size 0 in the below output shows that the DNS cache has been cleared.
sudo systemd-resolve --statistics

Alternatively, you can use dns-clean to flush DNS-Cache

sudo /etc/init.d/dns-clean start
# OR
sudo service dns-clean restart

Linux Misc

If you’re not sure whether your Linux installation uses local DNS caching, consult the documentaiton for your Linux distribution to see if there’s any information about the default DNS software supplied.

Possible options include:

# Flush nscd service DNS Cache:
sudo /etc/init.d/nscd restart
# Alternatively, you can try these commands:
sudo /etc/rc.d/init.d/nscd stop
sudo /etc/rc.d/init.d/nscd start

and some other services

# Flush BIND service DNS Cache:
sudo /etc/init.d/named restart
# Flush dnsmasq service DNS Cache:
sudo /etc/init.d/dnsmasq restart
# Flush the DNS cache for a specific domain
sudo rndc flushname test.com
# Flush DNS cache for entire LAN:
sudo rndc flush lan
# Respectively, to flush DNS cache for entire WAN:
sudo rndc flush wan

Centos

Flush DNS on CentOS use the following command:

systemctl restart dnsmasq.service

Windows XP, Vista, 7, 8, 10, 11

  1. Open the Command Prompt
    • Windows XP: Click on the Start Menu and click Run.Type in cmd and hit enter.
    • Windows Vista/7: Type cmd in the search bar and hit Enter.
    • Windows 8: Press Win key (windows logo key) and X on your keyboard. Click on Command Prompt.
  2. Flush DNS by using the following command
ipconfig /flushdns

Mac OSX

  1. Open the Terminal: Navigate to Applications -> Utilities -> Terminal
  2. Flush DNS - Type the following command and hit enter:
# Mac OS X 10.12 (Sierra) and later
sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo 
dscacheutil -flushcache

# Mac OS X 10.11 (El Capitan) and OS X 10.12 (Sierra)
sudo killall -HUP mDNSResponder

# Mac OS X Yosemite and later*
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Mac OS X Yosemite v10.10 through v10.10.3
sudo discoveryutil mdnsflushcache

# Mac OS X Mavericks, Mountain Lion and Lion
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Mac OS X 10.7 (Lion) and 10.8 (Mountain Lion)
sudo killall -HUP mDNSResponder

# Mac OS X Snow Leopard
sudo dscacheutil -flushcache

# Mac OS X 10.4 (Tiger)
sudo lookupd -flushcache

comments powered byDisqus

Copyright © Armand