formats

Can’t ping localhost in Linux

Published on June 9, 2012, by + in linux.



$ ping localhost
ping: unknown host localhost


If you ever find yourself in a situation where you cannot ping localhost, I’ll show you a few things to check!


/etc/hosts

Verify that the /etc/hosts file has entires for localhost which looks like the following:


127.0.0.1 localhost

::1     localhost ip6-localhost ip6-loopback





/etc/nsswitch.conf

The file /etc/nsswitch.conf requires specific permissions. Verify that it is set to 644.



$ sudo chmod 644 /etc/nsswitch.conf



Also verify that /etc/nsswitch.conf has an entry like the following:

hosts:      files dns





Still no luck?

- Temporarily disable iptables, ufw, or any other firewall that may be in place

- Verify you have proper DNS in /etc/resolv.conf

- Restart all network services

- Verify that the output of sudo ifconfig provides something like this:

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:295 errors:0 dropped:0 overruns:0 frame:0
          TX packets:295 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:43479 (42.4 KiB)  TX bytes:43479 (42.4 KiB)



If no local loopback is provided with the above command, inspect the network interface configuration in /etc/network/interfaces (debian/ubuntu) or /etc/sysconfig/network-scripts/ifcfg-lo (red hat/centos).

- Another way to verify the loopback interface is up is with the following command:

$ ip link show lo
1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00




Good luck!

6 Responses

  1. Maxon

    Not working. Is there any other ways to resolve this problem

  2. Arpit Aggarwal

    Great Post.. a life saver for me !!

  3. Tim

    Thank you! The permissions of nsswitch.conf were not correct, reapplying solved the problem.

    Thank you!!

    Tim

  4. Inigo

    Great info! It allowed me to solve my problem after a few hours of searching. It was also a case of wrong nsswitch.conf permissions on Scientific Linux 5.8, btw.

    Thank you very much!!

  5. user

    Finally! Last piece of my puzzle
    X11 forwarding over ssh failed without any warnings or error. Because DISPLAY was set to localhost:10.0, and localhost didn’t resolve. Beacuse my nsswitch.conf was missing. Who would have guessed?

    You cut down with this on my problem fixing with possibly days. Thanks!

  6. Homepage

    … [Trackback]…

    [...] Find More Informations here: scottlinux.com/2012/06/09/cant-ping-localhost-in-linux/ [...]…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Home linux Can’t ping localhost in Linux