Systemd-resolved, Flushing DNS in Ubuntu 18.04 (and other distributions).

Today I’ve been playing with static DNS on my router, sadly Miktotik doesn’t support “DNS Doctoring” and it doesn’t look like Ubiquiti Networks equipment does either (as of 2018). It’s likely a feature I got spoilt with on a couple of Cisco routers I had access to.

Anyway, back to the point. Using Ubuntu 16.04 for a long time on my work laptop and now CentOS 7 I have been used to working with dnsmasq and how to clear the cache.

[ [email protected]: ~ ] $ grep -E "^PRETTY_NAME" /etc/os-release && sudo ss -pant | grep -E "^LISTEN" | grep :53
PRETTY_NAME="CentOS Linux 7 (Core)"
LISTEN     0      5      192.168.122.1:53                       *:*                   users:(("dnsmasq",pid=2462,fd=6))

On Ubuntu 18.04, and other distributions of course, this has been replaced with a systemd service called systemd-resolved.

[ [email protected]:~ ] $ grep -E "^PRETTY_NAME" /etc/os-release && sudo ss -pant | grep -E "^LISTEN" | grep :53
PRETTY_NAME="Ubuntu 18.04.1 LTS"
LISTEN      0        128         127.0.0.53%lo:53               0.0.0.0:*        users:(("systemd-resolve",pid=6977,fd=13))

So, to flush! If you’re finding there’s a need to clear the DNS cache here’s how you do it:

Method 1: sudo systemd-resolve --flush-caches

Method 2: sudo systemctl restart systemd-resolved

Sources