How to flush the DNS cache of Safari on macOS Mojave without restarting the system? I've experimenting with configuring dnsmasq on macOS for Apache vhosts instead of creating entries in /etc/resolver/&lt;domain&gt; for each domain. In my case, I configured dnsmasq to resolve .dev to localhost.

Since Safari had previously visited foo.dev, it kept requesting that page, although dig resolved foo.dev to localhost.

It didn't help to clear Safari's web cache and flush the system's DNS cache:

sudo dscacheutil -flushcache


It was first after a reboot that Safari properly visited the localhost instance of foo.dev (vhost).

So, is Safari mantaining its own DNS cache - and if so, how can it be flushed without restarting the system?
To clean DNS cache on macOS, the following command should be used. (commands used to clean caches seems to be different on different version of macOS)

sudo killall -HUP mDNSResponder

Clean the DNS cache in Safari. Open Safari, Preferences -> Advanced. Check "Show develop menu in menu bar". Then go to menu bar, Develop -> Empty Caches. The shortcut is ⌥⌘E. (Restart of Safari may be needed)


References


Flush cache of DNS on macOS Sierra &amp; High Sierra