Not able to get the reverse DNS working

Solution 1:

About private addresses

The IP addresses you're trying to resolve to names (the reverse lookups) are so-called private addresses, as defined in RFC 1918. In short, the following IPv4 range of addresses are defined in there:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16

Opposed to public addresses, these aren't routed across the Internet and are solely to be used behind NAT in a private network. Many people are using this and therefore absolutely not unique. For this reason it is of no interest to have public DNS servers respond to reverse lookup requests for private ones.

Why it isn't working

Google and all other public DNS servers on the Internet aren't interested in private addresses as they're not routable over the Internet. So, basically, you're doing it wrong by asking a server totally not responsible for your network.

In case you were looking to override this with a local configuration like in /etc/hosts, this won't work:

  • Can /etc/hosts config reverse resolution? No.
  • Do entries in local 'hosts' files override both forward and reverse name lookups? Yes, but no, actually

Local DNS server

If you want to be able to do reverse lookups within your private LAN, then you'll have to set up your own DNS server with the appropriate records and have all your local clients using this DNS server. You may already be running one, but you didn't specify anything of it in your question and if you have, you appear not to be using it.

A quick all-in-one solution I can recommend is Dnsmasq Install Dnsmasq. It's a DHCP and DNS server in one1 with the advantage of using the hostname for DHCP also in DNS. From the manpage of dnsmasq is the following excerpt:

Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. It loads the contents of /etc/hosts so that local hostnames which do not appear in the global DNS can be resolved and also answers DNS queries for DHCP configured hosts.

Setting up a complete Dnsmasq is a bit out of the scope here as it will replace your current DHCP server, which I don't know is an accepted solution. Anyway, for this part of the configuration this setting will be important:

domain=mydomain.lan,192.168.1.0/24,local

In which you tell it to serve the 192.168.1.0/24 network with short hostnames to use the mydomain.lan domain name and will not be forwarded to the upstream recursive DNS server. Result will be that a machine with the hostname myhost requesting a dynamic address will be automatically used in the local resolver and listens to queries myhost.mydomain.lan and the reverse pointer will resolve likewise.

I'm not aware of a "How do I set up Dnsmasq for a home network the good way?" question on this site. If you or others are interested, I'll be happy to Q&A it.

1Actually even more, like TFTP server as well.

Solution 2:

Short Answer: nslookup does not use the /etc/hosts file to do anything.

Long Answer:

It seems like when you run nslookup it will only use the nameservers listed in the /etc/resolv.conf. This behavior is replicated in host as well. If you have the IP addresses listed in the /etc/hosts files you should not need reverse DNS, or vice versa. I believe that was the thinking in this process.

Upon stracing the process I saw that it did not even look at the /etc/hosts file even though in my /etc/nsswitch.conf I had DNS set to files dns.

Sources: man host man nslookup