1

I'm having a bizarre problem. It started with postgresql-9.3 not installing. I found it couldn't find localhost.

I checked /etc/hosts and it has localhost properly as 127.0.0.1

But when I

ping localhost

I get

PING localhost.Home (198.105.244.21) 56(84) bytes of data.

when I

whois 198.105.244.21

I get "SearchGuide Inc" in Colorado

How do I get my system to properly recognize localhost?

I'm running trusty tahr 14.04.2 lts

Here is my /etc/hosts file:

127.0.0.1   localhost
127.0.0.1   ourcomp

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

I had a typo earlier. It is now corrected.

Here is the output of nslookup localhost:

nslookup localhost
Server:     127.0.1.1
Address:    127.0.1.1#53

Non-authoritative answer:
Name:   localhost.Home
Address: 198.105.244.21
Name:   localhost.Home
Address: 198.105.254.21

Output of iptables -L:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  

ufw status is inactive

/etc/nsswitch is blank

contents of /etc/resolv.conf:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search Home

ifconfig:

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:46904 errors:0 dropped:0 overruns:0 frame:0
          TX packets:46904 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2538766 (2.5 MB)  TX bytes:2538766 (2.5 MB)

p5p1      Link encap:Ethernet  HWaddr f0:4d:a2:9b:3b:b9  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:1b:b1:81:06:3d  
          inet addr:192.168.0.14  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21b:b1ff:fe81:63d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8968 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7779 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4212369 (4.2 MB)  TX bytes:1142565 (1.1 MB)
12
  • 2
    127.0.0.0 is the network address, localhost should be 127.0.0.1 (other IPs of this subnet is allowed although not prefarable)..could you please edit your question and add the output of cat /etc/hosts ?
    – heemayl
    Jul 9, 2015 at 10:50
  • 1
    Do you have iptables or ufw or any other means of forwarding mechanisms configured ?
    – heemayl
    Jul 9, 2015 at 11:02
  • Not that I know of. That is, I didn't purposely configure them, but I don't know if something else I installed did.
    – Trashman
    Jul 9, 2015 at 11:07
  • localhost.Home looks like an mDNS hostname: please add the contents of your /etc/nsswitch.conf and /etc/resolv.conf files, and output of ifconfig Jul 9, 2015 at 11:11
  • Run the command echo 'hosts: files mdns4 mdns4_minimal [NOTFOUND=return] dns' | sudo tee -a /etc/nsswitch.conf and then check..
    – heemayl
    Jul 9, 2015 at 11:29

1 Answer 1

2

The problem turned out to be missing relevant entries in the /etc/nsswitch configuration file.

While resolving hostnames to IP address, the GNU C library libc uses this file to get the sources and the order in which will be queried. The database name of /etc/nsswitch.conf involved here is hosts. There are also many other databases understood by libc e.g. passwd, protocols etc.

The databases are mentioned at the start of the line followed by the name of the sources to be queried. For example the required configuration for hosts database (used for finding IP address of a host) can take the form :

hosts:          files mdns4 dns
  • files indicates that at first the relevant configuration files in /etc directory to be queried first, hence /etc/hosts is queried first

  • Then mDNS (Multi-cast DNS) is used up to check if the IP can be retrieved

  • Then DNS i.e. the name servers are queried for the IP address.

As your /etc/nsswitch configuration file does not contain anything, i would suggest you to put the default entries to the file :

passwd:         compat
group:          compat
shadow:         compat

hosts: files mdns4 mdns4_minimal [NOTFOUND=return] dns

networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

Check man 5 nsswitch.conf to get more idea.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .