If using systemd-resolved as your DNS resolver (i.e. the hosts line of your /etc/nsswitch.conf file includes the word resolve and/or /etc/resolv.conf contains the line nameserver 127.0.0.53), then this command will flush its cache:
sudo systemd-resolve --flush-caches
A newer version of this command seems to be:
sudo resolvectl flush-caches
