How to Flush DNS in Ubuntu Linux 18.04

Posted on


The main purpose for writing this article is to show how to flush DNS in Ubuntu Linux 18.04. This is actually happening almost all the time. It happens when there is a new entry added in this context in the local DNS Server. Sometimes, a client with an installed Ubuntu Linux in it cannot resolve that entry. It is a new entry of a specific IP Address of any resources in the network. Normally, the IP Address has a representative string format address pointing on those resources. The following is an example of it :     app.myapp.web

After adding the entry in the local DNS Server, across the time there can be a possibility for changing or modifying either the representative string format address or the specific IP Address of the server. The example above is  an example of a representative string format address of a specific web application running on it. If there is a change or modification of the entry in the local DNS Server, it takes time to resolve the address for any kind of clients even with an Ubuntu Linux installed on it.


In order to solve the above problem, there is an easy way to do it. The client or PC with the installed Ubuntu Linux need to flush its cache containing the old address of the resources. Just type the following command in the command line interface. Generally, Ubuntu Linux provides a terminal as means for executing that specific command. The following is the command for it :

sudo systemd-resolve --flush-caches

The following is the sample of the above command execution :

user@hostname:~$ sudo systemd-resolve --flush-caches
[sudo] password for user:  

In order to prove that the cache has already flushes, below is the example for resolving name a website name as an example of resources in the network. So,  just type the following command :

dig name-of-website

For an example, the following is the execution of the above command :

user@hostname:~$ dig app.mywebapp.web

; <<>> DiG 9.11.3-1ubuntu1.5-Ubuntu <<>> app.mywebapp.web
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5810
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 65494
;app.mywebapp.web.	IN	A

app.mywebapp.web. 0	IN	A

;; Query time: 0 msec
;; WHEN: Tue Mar 12 21:52:16 2019
;; MSG SIZE  rcvd: 69


Since there is an answer from the command in the ANSWER SECTION, it means the address for the website name has finally resolved.  Flushing the cache in the local operating system as shown in the above sometimes is necessary. It is because the address for accessing the resources in the network  may change across the time.  Therefore, it is a good idea to avoid IP Address conflict or unresolved IP Address by clearing the cache. Flushing the cache is also a good way to clear unnecessary data residing in the local operating system.

Leave a Reply