Cannot ping to localhost into CentOS

6,735

After checking that local interface is up (ifup lo0 or similar).

Check for routes, firewall or iptables problem.

Here it was a problem from the file located here /proc/sys/net/ipv4/icmp_echo_ignore_all
When set to 1 : There is no response to ICMP Requests, so ping will not work.
When set to 0 : Replies to ICMP Requests are enable.

Check if sets to 1. If so, set it to 0 by using this command : echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

Now, your machine replies to ping.

Share:
6,735

Related videos on Youtube

Neil
Author by

Neil

Updated on September 18, 2022

Comments

  • Neil
    Neil almost 2 years

    I'm connecting to my server (Centos 7) with ssh and I try to ping to localhost: ping 127.0.0.1 but doesn't work:

    ping 127.0.0.1
    
    PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
    ^C
    --- 127.0.0.1 ping statistics ---
    78 packets transmitted, 0 received, 100% packet loss, time 76999ms
    

    Here my files. networks:

    default 0.0.0.0
    loopback 127.0.0.0
    link-local 169.254.0.0
    

    hosts:

    # nameserver config
    # IPv4
    127.0.0.1 localhost.localdomain localhost
    1xx.xxx.xxx.xxx  server
    #
    # IPv6
    ::1     ip6-localhost ip6-loopback
    ...
    

    lo route:

    DEVICE=lo
    IPADDR=127.0.0.1
    NETMASK=255.0.0.0
    NETWORK=127.0.0.0
    # If you're having problems with gated making 127.0.0.0/8 a martian,
    # you can change this to something else (255.255.255.255, for example)
    BROADCAST=127.255.255.255
    ONBOOT=yes
    NAME=loopback
    

    I need make a ping! What I can do?

    • Nico
      Nico over 9 years
      maybe bring up local interface : ifup lo ?
    • Neil
      Neil over 9 years
      Is currently UP :/
    • Nico
      Nico over 9 years
      Check routes, firewall, iptables ? Do you have a resolv.conf ? If no, please create one for testing purpose at least
    • Nico
      Nico over 9 years
      Also check if /proc/sys/net/ipv4/icmp_echo_ignore_all is set to 0 if it exists.
    • Neil
      Neil over 9 years
      iptables and firewall are disabled. I have a resolv.conf file. Lets to check routes.
    • Neil
      Neil over 9 years
      Is set to 1? What I have to do?
    • Neil
      Neil over 9 years
      I've added the lo route file into question.
    • Nico
      Nico over 9 years
      try setting it to 0 with echo 0 > path_to_file. Guess its the cause
    • Neil
      Neil over 9 years
      Like this: echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all IT WORKS! Thanks!
    • Neil
      Neil over 9 years
      And for set this permanently? @Nico you are the best!
    • Nico
      Nico over 9 years
      No problem. This file is saying : Should I answer to ICMP Requests ? with 0 you answer : "Do not ignore all", if sets to 1 you say "Yes, ignore everything". Hope I'm clear enough. Next time, try a google research first with "centos cannot ping 127.0.0.1" with the 5 first links, you should be able to solve and understand the problem ;) You can answer your own question, or I can do it if you prefer
  • Ryan Pendleton
    Ryan Pendleton over 9 years
    Did you accidently switch 0 and 1 in the first part of your answer?