How to flush DNS resolver cache on Linux (and FreeBSD)

I am admin for several Linux and FreeBSD servers and here is a problem I have:

The servers run a tool that does a lot of DNS queries every minute for the entire network. When it does a query, the result gets cached system-wide. If a DNS entry changes, the change gets picked up much later.

What would be the way to flush DNS cache? My boss almost pushes me to move software to Windows that has ipconfig /flushdns call. I told my boss I will resolve this issue during weekend and on Monday all Linux and FreeBSD will flush cache. If I don't do that he will force me to make Windows servers and run software on them.

How to flush DNS cache on Linux and FreeBSD?


I don't get your question because you say some nonsense.

If you are on a Linux/Unix system that does not run a DNS server 'named/bind/other' the system does not cache any DNS query. Applications (DNS clients) just query the DNS server every time without caching, they query the DNS server every time. If you use a DNS server 'named/bind' and want to clear the cache just restart this service (Freebsd: /etc/rc.d/named restart) but there is no point for this.

If a DNS entry changes, the change gets picked up much later.

How this can be? Do you run a DNS server or not? If you run a secondary DNS server you just get a copy of the zone from primary server and there is no point to flush cache. You can push the server update zone from the primary server by deleting the zone file and restarting your DNS service. If you run primary DNS and want to update zone information, change the serial in zone and restart service:

# /etc/rc.d/named restart (for named)
# rndc (for bind9)

To update zone information. To check if you get right dns answer use:

# dig @dns_server example.com

pushes me to move software to Windows that has ipconfig /flushdns

For what?


Presuming you are running the Name Service Caching Daemon, you run "nscd -i hosts" as root


What you might want to do is a combination of the following.

If you know that various entries change in your DNS zone change quickly, then set the TTL down to a smaller value for the zone.

Generally, there is a NameServerCacheDaemon (nscd) process that runs in standard release Linux (not sure about FreeBSD). A quick way to clear the cache is to restart this daemon.

Finally, if you are running a caching DNS server on your hosts, you can easily restart the dns service and that will clear the cache. I think that there might even be a cache clear if you use the dns control command.