MacOS – How to lookup the IP address of a Bonjour host

bonjourdnsmacosNetwork

Normally, if I want to point to a Bonjour-capable host on my local network, I can use its local network hostname, hostname.local, as in:

$ ssh pi@raspberrypi.local

Unfortunately, this doesn't work for all programs. I get DNS lookup errors when I try this notation in Cyberduck, for example.

Cyberduck's DNS lookup error

So I tried the usual ways of looking up hostnames so I could just type in its IP address. First try, thanks to muscle memory was whois:

$ whois raspberrypi.local
% IANA WHOIS server
% for more information on IANA, visit http://www.iana.org
% This query returned 0 objects.
%
% You queried for raspberrypi.local but this server does not have
% any data for raspberrypi.local.

Duh. Of course this of course didn't work because the Internet has no idea who my local machine is. I tried some more:

$ nslookup raspberrypi.local
Server:     1.1.1.1
Address:    1.1.1.1#53

** server can't find raspberrypi.local: NXDOMAIN
host -a raspberrypi.local
Trying "raspberrypi.local"
Host raspberrypi.local not found: 4(NOTIMP)

Oops. That's also asking the Internet. How about…

$ host -t NS raspberrypi.local
Host raspberrypi.local not found: 3(NXDOMAIN)

Still no luck. Help me out folks, how can I lookup the IP address of another machine on my local network if all I know is its Bonjour hostname?


Update: Apparently, Cyberduck gives the misleading DNS lookup error if you accidentally type the username into the Server field, as in pi@raspberrypi.local instead of raspberrypi.local. ??‍♂️ It's still a valid question, but not a great premise.

Best Answer

Use dns-sd

It's the Multicast DNS (mDNS) & DNS Service Discovery (DNS-SD) tool for BSD.

$ dns-sd -Gv4v6 <hostname>.local

For my example, I write:

$ dns-sd -Gv4v6 raspberrypi.local

And get the IP (redacted) in the address column:

DATE: ---Wed 19 Jun 2019---
14:23:40.213  ...STARTING...
Timestamp     A/R    Flags if Hostname               Address         TTL
14:23:40.531  Add        2  5 raspberrypi.local.     <redacted MAC>  120
14:23:40.548  Add        2  5 raspberrypi.local.     10.1.2.3        120
14:23:40.838  Add        3  5 raspberrypi.local.     <redacted MAC>  120
14:23:40.838  Add        2  5 raspberrypi.local.     10.1.2.4        120

Hostnames and IP addresses have been changed to protect the innocent. I found this answer by looking for other questions about finding Bonjour machines.