I found a couple of ways to do this, but they're both a bit ugly. First, you can use dns-sd -q
and specify the ptr
record type... but you need to convert the address you want to look up into nibble-by-nibble reverse format by yourself. For example, to look up fe80::4e6:97e7:d892:d977
you'd use:
dns-sd -q 7.7.9.d.2.9.8.d.7.e.7.9.6.e.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa ptr
Unfortunately, this only seems to work for link-local addresses, not public addresses. I have no idea why. Also, note that dns-sd
doesn't exit automatically after doing the lookup, but keeps monitoring for changes. You need to kill it after a bit.
You can also use dig
, somewhat like your original command, but you need to tell it which interface to send the query out over, and in a rather weird format. The "standard" thing to do would be to add a zone index for the interface, e.g. to send it to ff02::fb
over en1
you'd use @ff02::fb%en1
. But dig
doesn't like that format, so you have to be sneakier. BSD-based unixes, including macOS, allow you to put a numeric zone index in the second 16-bit word of some kinds of addresses, and that does work here. Here's a (anonymized) example where I use netstat -rn -f inet6
to find out that 2001:db8:1234:5678::/64
is on interface en1
, that interface's link number is 5
, and then use that to do a lookup (I added ^^^s to emphasize the relevant parts):
% netstat -rn -f inet6
Routing tables
Internet6:
Destination Gateway Flags Netif Expire
[...]
2001:db8:1234:5678::/64 link#5 UC en1
^^^^^^ ^^^
[...]
% dig +short @ff02:5::fb -p 5353 -x 2001:db8:1234:5678:109f:8688:b2d1:3f12
^
Gordons-MacBook.local.