the /etc/hosts file contains a line: 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 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?

4 Answers 4


Is there an interface configured with lo0 or any other interface with 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:  Mask:
          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)
  • 2
    @dkeeney -- Apparently this solved your problem, but I can't figure out what part was relevant. Can you elaborate?
    – belacqua
    Apr 13, 2011 at 21:32

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.

  • A POSTROUTING rule in the NAT table was preventing me to ping localhost.
    – pylover
    Feb 18, 2017 at 11:45

Does 'ip neigh show' show that the loopback interface is up?

Yes, it's possible to configure iptables in such a way as to drop all packets received on lo. I'm not sure how that could take place by accident, but it's worth checking.


You might look into /etc/resolv.conf , but I don't know which entry would stop localhost from working.

  • The resolv.conf file is pretty ordinary, with a couple of nameserver lines. Thanks.
    – user14149
    Apr 13, 2011 at 2:47
  • 1
    He's said that he couldn't ping by IP address either, so I doubt it's resolv.conf related.
    – belacqua
    Apr 13, 2011 at 21:30
  • This information was added later. Yes. Apr 13, 2011 at 22:22

You must log in to answer this question.