Cannot resolve localhost

Matthew Seaman matthew at
Thu Feb 14 23:02:54 UTC 2013

On 14/02/2013 22:35, Martin Pola wrote:
> I'm trying to get my FreeBSD system to resolve localhost into
>, but unfortunately it doesn't work. It appears the resolver is
> never reading from /etc/hosts, where I have this line:
> localhost
> Here's a sample output of what I get when I try to resolve the name:
> $ nslookup localhost
> ;; Got recursion not available from, trying next server
> Server:
> Address:
> ** server can't find localhost: NXDOMAIN
> What am I missing?

The understanding that looking stuff up in the DNS[*] is never going to
return anything from the contents of your /etc/hosts file?

You can do a more generic lookup using whatever means are configured in
your /etc/nsswitch.conf by:

% getent hosts localhost
::1               localhost         localhost

although with localhost, that really should also be available in the
DNS, both forwards and reverse:

% dig +short IN A localhost
% dig +short IN AAAA localhost
% dig +short -x
% dig +short -x ::1

Although I note that Google's DNS resolver specifically *doesn't* have it...

% dig +short @ -x ::1
% dig +short @ -x
% dig +short @ localhost
% dig +short @ IN AAAA localhost

Just a peculiarity of the Google DNS service.



[*] BTW. nslookup is *so* 20th Century.  All the cool kids are using
dig(1) or drill(1) nowadays.

Dr Matthew J Seaman MA, D.Phil.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 268 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the freebsd-questions mailing list