I would like a command that will resolve a hostname to an IP address, in the same way that a normal program would resolve the hostname. In other words, it has to take into account mDNS (.local) and /etc/hosts, as well as regular DNS. So that rules out host, dig, and nslookup, since all three of those tools only use regular DNS and won't resolve .local addresses.

On Linux, the getent command does exactly what I want. However, getent does not exist on OS X.

Is there a Mac OS X equivalent of getent? I'm aware that I could write one in a few lines using getaddrinfo, and that's what I'll do if I have to, but I was just wondering if there was already a standard command that could do it.



I think dscacheutil is what you're looking for. It supports caching, /etc/hosts, mDNS (for .local).

dscacheutil -q host -a name foo.local

Another option is dns-sd

dns-sd -q foo.local

More information about dnscacheutil.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.