others-how to solve 'Request timeout for icmp_seq' when ping localhost or ping 127.0.0.1 ?

1. Purpose

In this post, I would demo how to solve the below exception when using ping in macos.

➜  ~ ping localhost
PING localhost (127.0.0.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1

➜  ~ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1

2. Environment

  • MacOS

3. The debug

3.1 Check your /etc/hosts

Make sure you have this line in the /etc/hosts

127.0.0.1	localhost

3.2 Check the nslookup result

$ nslookup localhost

4. The solution

4.1 Check your proxy

If you are using a proxy in your machine, you can try to close the proxy.

4.2 Check your network firewall settings

Goto system preferences –> security –> firewall –> click to change –> firewall options –> uncheck ‘block all incoming connections’ and make sure stealth mode is off.

5. Summary

In this post, I demonstrated how to solve the ping localhost/127.0.0.1 timeout problem, the key process is check your local proxy or your firewall settings.