Note – this works on Ubuntu 18.04, 20.04 and Centos 8
Check that systemd-resolved is running by entering the command below.
> sudo systemctl status systemd-resolved
To check the number of items in the cache run:
>sudo systemd-resolve statistics
To clear the local DNS cache run the command below
> sudo systemd-resolve --flush-caches
If you run the command systemd-resolve –statistics again you will now see the cache is empty.