Resetting the DNS cache on macOSEdit

Sometimes a process will claim that a host is unknown when trying to connect with one process (eg. git push) but others have no trouble doing so (eg. ping). The solution may be to bounce the DNS cache.

macOS Monterey

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Source

macOS High Sierra

sudo killall -HUP mDNSResponder
sudo killall mDNSResponderHelper
sudo dscacheutil -flushcache

Source

Older notes

The finessed approach

$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

Verified to work on OS X 10.11.2 El Capitan.

Source

Via brute force

$ sudo killall -HUP mDNSResponder

Source

See also