For most versions of OSX and macOS I have found the following works
sudo killall -HUP mDNSResponder
I have seen notes to indicate that
dnscacheutil -flushcache
or
discoveryutil udnsflushcaches
are needed for Yosemite and older versions.
Thanks to: https://help.dreamhost.com/hc/en-us/articles/214981288-Flushing-your-DNS-cache-in-Mac-OS-X-and-Linux amongst other sites.