brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: dscacheutil -q host looks up a host name on your Mac

Terminal
~/tips/tip-macos-dscacheutil-host-lookup

dscacheutil -q host -a name example.com

Queries the Mac's Directory Service cache for a host name or an IP address.

Sometimes I want to ask the Mac itself what a name or an address maps to. dscacheutil has a host query for that, and it also shows what sits in the Directory Service cache.

The man page says -q starts a query using standard calls. The results either come from the cache or are fetched live and then placed in the cache. For the host category the key is name or ip_address, and it covers both IPv6 and IPv4:

dscacheutil -q host -a name example.com

The other direction uses the same category:

dscacheutil -q host -a ip_address 192.168.1.10

Leave out -a and you get everything in that category, so dscacheutil -q user lists all users. The other categories are group, mount, protocol, rpc and service.

Two read-only switches are worth knowing. -statistics prints cache statistics, and -configuration prints the current configuration, such as the search policy from Directory Service and the cache parameters. -cachedump gives an overview of the cache, and adding -entries host dumps the host entries, which only administrative users can do.

The caveat is -flushcache. It flushes the entire cache, and the man page says it should only be used in extreme cases, because validation information in the cache is part of how the OS makes sure it has valid data. I would look at the statistics first and leave the flush alone.

Further reading: dscacheutil man page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link