Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I had been struggling to get reverse DNS working using nslookup on Ubuntu 12.04. Here is the output of the nslookup command and the content of the different network related configuration files.

What could be the possible reason for the nslookup not working? Also, why do I need an internet connection to get a reverse lookup work for an entry in the /etc/hosts file?

training@guest1:/etc/network$ nslookup 192.168.1.101
Server:     8.8.8.8
Address:    8.8.8.8#53
server can't find 101.1.168.192.in-addr.arpa.: NXDOMAIN

training@guest1:/etc/network$ cat /etc/hosts
127.0.0.1   localhost
#127.0.1.1  Slave1
192.168.1.101 MyUbuntuLaptop

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

training@guest1:/etc/network$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.201
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4

training@guest1:/etc/network$ ping MyUbuntuLaptop
ping MyUbuntuLaptop (192.168.1.101) 56(84) bytes of data.
64 bytes from MyUbuntuLaptop (192.168.1.101): icmp_req=1 ttl=64 time=0.113 ms
64 bytes from MyUbuntuLaptop (192.168.1.101): icmp_req=2 ttl=64 time=0.222 ms
share|improve this question
7  
You're using Google's nameservers (8.8.8.8) and using private (RFC1918) addresses. As these addresses are fairly private, Google doesn't know about those and never will. Nor will any other public DNS server do. You'll have to run your own DNS server in your network. Is that an option? Similar to this tutorial. –  gertvdijk Jan 24 '13 at 16:36
add comment

2 Answers

up vote 12 down vote accepted
+100

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:

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.

1 Actually even more, like TFTP server as well.

share|improve this answer
    
Thanks for the detailed response - I was thinking that nslookup will look at /etc/hosts before going to the DNS server for doing the reverse lookup. I am trying to setup CDH and there was a note that both forward and reverse lookup should work, so I started trying the nslookup command. –  Praveen Sripati Jan 25 '13 at 6:46
    
@PraveenSripati I've added two references on other SE sites that will explain more about the role of /etc/hosts in reverse lookups. –  gertvdijk Jan 25 '13 at 9:05
    
@gertvdijk: Our home private networks are getting filled with a myriad of anonymous devices getting and losing dynamic IPs all the time. It is getting really hard to distinguish between legit hosts and potentially others. There seems to be a great need for a comprehensive quide to having reverse DNS work everywhere on the typical phone/tablet/desktop/game-console/... home network. It would be great if you could add this Q&A on the site. Highly appreciated! –  arielf Jan 10 at 21:12
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.