Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
server can't find NXDOMAIN

training@guest1:/etc/network$ cat /etc/hosts   localhost
#  Slave1 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

training@guest1:/etc/network$ ping MyUbuntuLaptop
ping MyUbuntuLaptop ( 56(84) bytes of data.
64 bytes from MyUbuntuLaptop ( icmp_req=1 ttl=64 time=0.113 ms
64 bytes from MyUbuntuLaptop ( icmp_req=2 ttl=64 time=0.222 ms
share|improve this question
You're using Google's nameservers ( 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
up vote 13 down vote accepted

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:


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:


In which you tell it to serve the 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 '14 at 21:12

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

DNS server applications for finding DNS informations are very rigid and takes more times than comparing to other DNS lookup search sites on internet which is very clear and short.I always look up my DNS queries at where it is by simple search to identify the details.

share|improve this answer

Your Answer


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.