DNS (Domain Name System) caching is a technique used by operating systems and applications to store the resolved domain names’ IP addresses, reducing the time it takes to access websites and services. While it can be advantageous in certain situations, you may want to disable local DNS caching on your Ubuntu or Linux Mint system for various reasons, such as troubleshooting DNS issues, ensuring accurate results during development, or enhancing privacy.
In this step-by-step guide, we will walk you through the process of disabling local DNS caching on Ubuntu and Linux Mint systems. You can also clear current DNS cache instead of disable it completely.
Step 1: Identify your DNS caching service
First, determine which DNS caching service is running on your system. The most common services are ‘systemd-resolved’ (default on Ubuntu 16.04 and later) and ‘dnsmasq’ (common on Linux Mint). You can check which service is running using the following command:
sudo systemctl list-units --type=service | grep -E 'systemd-resolved|dnsmasq'
Step 2: Disable the DNS caching service
Depending on the service you identified in step 1, follow the appropriate instructions below.
A. Disabling systemd-resolved (Ubuntu default):
Open the systemd-resolved configuration file using a text editor (we’ll use nano in this example):
sudo nano /etc/systemd/resolved.conf
Find the line starting with ‘Cache’, uncomment it (remove the ‘#’ at the beginning), and set its value to ‘no’:
1 | Cache=no |
Save the changes and exit the text editor by pressing ‘Ctrl + X’, followed by ‘Y’, and then ‘Enter’.
Restart the systemd-resolved service to apply the changes:
sudo systemctl restart systemd-resolved
B. Disabling dnsmasq (Linux Mint default):
Open the dnsmasq configuration file using a text editor:
sudo nano /etc/dnsmasq.conf
Add the following line at the end of the file:
1 | cache-size=0 |
Save the changes and exit the text editor.
Restart the dnsmasq service to apply the changes:
sudo systemctl restart dnsmasq
Step 3: Verify the changes
To ensure that local DNS caching is disabled, you can use the ‘dig’ command to query a domain name multiple times and check the TTL (Time To Live) value. If the TTL value decreases after each query, it means the DNS cache is not being used. To install ‘dig’, use the following command:
sudo apt install dnsutils
Now, run the ‘dig’ command twice with a domain name of your choice (e.g., example.com):
dig example.com
Compare the TTL values in the ‘ANSWER SECTION’ of the output. If they differ, local DNS caching has been successfully disabled.
TTL Value Before Disabling Local DNS Cache:
TTL Value After Disabling Local DNS Cache:
Conclusion
In this article, we demonstrated how to disable local DNS caching on Ubuntu and Linux Mint systems by identifying and configuring the appropriate DNS caching service. Disabling local DNS caching can be helpful for troubleshooting, development, or privacy purposes. Keep in mind that without caching, your system may experience slightly slower DNS resolutions as it will always need to query external DNS servers.