What would cause 'ping localhost' to fail?

the /etc/hosts file contains a line: 127.0.0.1 localhost so localhost should be a valid hostname, but any attempt to connect to a port on localhost fails, including ping.

Connection attempts into this server from outside, using the same clients, work.

Connection attempts from this server to other servers using these clients also work.

On further investigation, it also fails to ping the loopback ip 127.0.0.1 when ping is invoked directly on that ip. In addition to pinging, I tested with 'socat TCP4..'.

Would a bad iptables prevent a localhost connection?


Solution 1:

Is there an interface configured with lo0 or any other interface with 127.0.0.1? Check the Rx packets/Tx packets count. Also, check to see if lo0 is configured in /etc/network/interfaces.

output of '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:16436  Metric:1
          RX packets:24 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1440 (1.4 KB)  TX bytes:1440 (1.4 KB)

Solution 2:

Yes, iptables can firewall localhost from itself. If you've been playing with that, it would be an excellent place to look first.

Try running iptables -L -n. If you're not sure about how to read the output, post it.

A classic mistake is to set the policy to DENY and not to add an exception for localhost.