Networking – Why does ping to google.com or 8.8.8.8 fails

centos-6dnsnetworkingpingyum

I am using Cent OS 6.4 and it is in a official lab.

ping google.com gives the below output and hangs:

[root@LAB1 ~]# ping google.com  
PING google.com (74.125.236.195) 56(84) bytes of data.

ping 8.8.8.8 also yields the same result. I am able to access internet from browser(Mozilla). Is there a problem with the network settings or configuration?

Below is the output from traceroute - n 8.8.8.8

[root@LAB1 ~]# traceroute -n 8.8.8.8 traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 *^Z

Below is the output from route -n if it helps

[root@LAB1 ~]# route -n  
Kernel IP routing table  
Destination Gateway Genmask Flags Metric Ref Use Iface  
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0  
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0  

The main reason for me to try the above ping is to resolve an yum update command that fails to resolve the mirror sites…

As I am new to networking, I am not able to identify the issue. Any help here is much appreciated…

Best Answer

Many corporate firewalls block ICMP - which is the protocol is used by ping utility.

Better solution for this is to try TCP connection to google.com:80.

Easiest way to check for basic internet connectivity in shell script is utility nc (it should be easily available on most Linux systems):

nc -w 3 -z google.com 80
echo $?

This means check if port 80 on google.com is open, and timeout after 3 seconds. If connection was successful, it will print 0, and if it failed, it will print 1.


If you want to check internet connectivity without checking DNS (which could be broken in itself), you can use Google's preferred DNS server 8.8.8.8, but the only port that it has open is 53 (aka domain):

nc -w 3 -z 8.8.8.8 53
echo $?

However, port 53 can be also blocked by your corporate firewall (not common, but possible). Ports 80 and 443, on other hand, are almost never firewalled.

Related Question