Mac OS command to resolve hostnames like "getent" on Linux

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.


(Building on user422009's answer)

Add this to your ~/.bash_profile:

getent() {
  [ "$1" == "hosts" ] && shift
  for x
  do
    echo $x $(dscacheutil -q host -a name $x | awk '/^ip_address/{print $NF}')
  done
}

Then either open a new terminal or source your bash_profile:

. ~/.bash_profile

And then it'll work:

$ getent hosts www.example.com
www.example.com 93.184.216.34

Tags:

Hostname

Mdns

Osx