The method for clearing or flushing the local cache in Mac OS has changed over the years. Here are all the Mac OS versions on one page that details how to clear Mac OS DNS cache via command line.

Clear your DNS cache on macOS Tahoe 26, macOS Sequoia 15, macOS Sonoma 14, macOS Ventura 13, macOS Monterey 12, macOS Big Sur 11, macOS 10.15 Catalina, macOS 10.14 Mojave, macOS 10.13 High Sierra, macOS 10.12 Sierra, OS X 10.11 El Capitan, OS X 10.10 Yosemite, OS X 10.9 Mavericks, OS X 10.8 Mountain Lion, OS X 10.7 Lion, OS X 10.6 Snow Leopard, and OS X 10.5 Leopard using the following Terminal commands:

macOS Tahoe 26

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS Sequoia 15

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS Sonoma 14

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS Ventura 13

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS Monterey 12

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS Big Sur 11

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS 10.15 Catalina

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS 10.14 Mojave

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS 10.13 High Sierra

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

macOS 10.12 Sierra

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Mac OS X 10.11 El Capitan

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Mac OS X 10.10 Yosemite

sudo discoveryutil udnsflushcaches

Mac OS X 10.9 Mavericks

dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Mac OS X 10.8 Mountain Lion

sudo killall -HUP mDNSResponder

Mac OS X 10.7 Lion

sudo killall -HUP mDNSResponder

Mac OS X 10.5 Leopard & 10.6 Snow Leopard

sudo dscacheutil -flushcache

There you have it, how to clear Mac OS DNS cache via command line.