9

Ubuntu uses 'avahi' to perform host name lookups on the local network, which allows me to find other computers just by adding '.local' to the name, e.g. laptop.local or desktop.local.

However, avahi does not seem to perform reverse lookups for the IP addresses of computers on the local network. So when applications look up IP addresses for local computers, a request goes out to an Internet DNS server on the Internet which returns NXDOMAIN (name does not exist).

Is it possible for avahi to perform reverse lookups for IP addresses? If it is, how do I do it?

  • Reverse lookups of local IP-addresses return the appropriate *.local hostname here. What tools are you using to do reverse lookups? – JanC Feb 02 '11 at 03:31
  • Thanks, JanC. You were right! I have learned that how you check this can make all the difference. –  Feb 13 '11 at 10:07

3 Answers3

7

Yes, avahi supports reverse IP address lookups for the .local names that are registered on the local network. However, most of the commands for performing test queries contact DNS servers directly without using avahi. In order to confirm that this is working at the command line, you have to use the getent hosts command instead of nslookup, dig, or host.

For example, you can look up an IP address using the following commands:

$ nslookup 192.168.0.1
$ dig -x 192.168.0.1
$ host 192.168.0.1
$ getent hosts 192.168.0.1

Only the getent hosts command will return the corresponding name because it is the only command that uses avahi to perform the reverse lookup.

(Actually, this also applies to looking up names, but it is usually simpler to just type ping hostname.local which performs a name lookup using DNS or avahi and checks connectivity at the same time.)

  • getent hosts <ip> did not work for me, and neither did nslookup, dig or host on Ubuntu 24.10. But avahi-resolve-address <ip> did work for me. – Flimm Nov 18 '24 at 18:10
5

dig also could perform reverse DNS lookup using avahi:

dig -x 192.168.0.1 @224.0.0.251 -p 5353

  • That's fantastic, vagran. I didn't realise dig could perform multicast DNS queries. I investigated and found that you can also do this using nslookup: nslookup -port=5353 -querytype=PTR 192.168.0.1 224.0.0.251. However, I also found that if ufw (which allows multicast by default) is running, only getent hosts 192.168.0.1 works. Aargh! If I figure this out, I'll update my answer. –  Feb 20 '11 at 22:18
  • This didn't work for me on Ubuntu 24.10, it gave me the error "no servers could be reached") – Flimm Nov 18 '24 at 18:11
3

There is an avahi command for it: avahi-resolve-address. E.g.:

avahi-resolve-address 192.168.0.1

Or, an equivalent variant:

avahi-resolve --address 192.168.0.1