# Flush dnsmasq cache automatically after vpn connection

**URL:** <https://linux-tips.com/t/flush-dnsmasq-cache-automatically-after-vpn-connection/811>\
**Category:** Network\
**Created:** [October 5, 2020, 7:21pm UTC](https://linux-tips.com/t/flush-dnsmasq-cache-automatically-after-vpn-connection/811 "2020-10-05T19:21:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debuser](https://linux-tips.com/letter_avatar_proxy/v4/letter/d/96bed5/32.png) [@Debuser](https://linux-tips.com/u/Debuser)\
**Post date:** [October 5, 2020, 7:21pm UTC](https://linux-tips.com/t/flush-dnsmasq-cache-automatically-after-vpn-connection/811/1 "2020-10-05T19:21:34Z")

</div>

There are some cases which will be good to flush dnsmasq internal cache.

Lets assume that you have an openvpn connection profile and when you connect to vpn in network-manager, you’re getting a custom dns server address. Most of the distributions uses dnsmasq internally in network-manager and can update dns server list of dnsmasq successfully. But, if you previously queried a host before the vpn connection is active, it is cached by the dnsmasq and you’ll get same answer after vpn connection is activated.

But, if your newly received dns servers from the vpn connection has some other records for the same dns query, you’ll have to restart or flush the cache’s of dnsmasq.

Dnsmasq has `clear-on-reload` startup parameter for this specific case. In order to flush the cache automatically, you just need to start dnsmasq with this parameter.

On Debian based distros, just add following lines to **/etc/default/dnsmasq** and restart it:

```auto
DNSMASQ_OPTS="--clear-on-reload"

```

Now, dnsmasq will be signalled by network manager on every new connection setup and it will be flush its cache automatically.
