jonathanio/update-systemd-resolved

Flush DNS cache on add/remove DNS server

superjamie opened this issue · 5 comments

A workflow for a user using a VPN might go like this:

  • Not connected to VPN
  • Attempt to visit website
  • systemd-resolved resolves website and caches result
  • Find website is blocked by ISP
  • Connect to VPN, using this script to get DNS servers from VPN
  • Attempt to visit website again to avoid blocking

However, because systemd-resolved has cached the DNS request from the previous attempt, the visit to the website fails.

One can work around this manually by systemd-resolved --flush-cache

It seems more appropriate to invalidate the DNS cache every time this script adds/removes a DNS server so that systemd-resolved will attempt to resolve DNS requests with the newly provided VPN DNS servers when required.

Please have the script flush systemd-resolved DNS cache on every add/remove.

Seems reasonable

However I remember reading somewhere that systemd flushes DNS cache any time interface is added/removed.

Maybe, but there is no additional harm in being explicit in the script at the point just after the DNS setting overrides are confirmed as added to systemd-resolved. 👍

but there is no additional harm (...)

It turns out there is – #72

Ideally I think we should find reference for #62 (comment) and then revert this change.
Alternatively flushing could be make to fail saliently when not supported.

Alternatively flushing could be make to fail [silently?] when not supported.

Yes, this. Continue on #72 as Eduard said:

Doesn't make sense a revert because an outdated version of systemd.
Instead we can just evaluate if the --flush-caches is sucess or not and print some warning.

There's no need to spam the same problem across multiple Issues.