为什么“curl”命令可以正常工作而“ping”却不工作?

为什么“curl”命令可以正常工作而“ping”却不工作?

我在我的公司网络中发现了一个奇怪的现象:
我可以curl google.com成功执行命令:

[root@localhost ~]# curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

但执行ping google.com失败:

[root@localhost ~]# ping google.com
PING google.com (173.194.33.174) 56(84) bytes of data.
^C
--- google.com ping statistics ---
1569 packets transmitted, 0 received, 100% packet loss, time 1568463ms

我怀疑系统管理员做了一些事情,但不确定。有人能提供一些如何调试此问题的线索吗?例如,系统管理员是否设置了一些可以过滤ping命令的规则?我该如何验证?

答案1

您可以使用以下 perl 程序测试 ICMP 是否被阻止:

ping.pl(编辑至打印端口)

#!/usr/bin/env perl    
use strict;
use warnings;
use Net::Ping;

my @hosts = @ARGV;
die "usage: sudo perl ping.pl host\n" unless @ARGV;

my $timeout = 5;
my @proto = ("tcp", "udp", "icmp","syn");
foreach my $pro ( @proto ) {

    my $p = Net::Ping->new($pro);

    # default port    
    my $port = 7;
    $p->port_number($port);

    # tcp on https port
    if ( $pro eq "tcp"){
      $port = 443;
      $p->port_number($port);
    }

    print "\nProtocol $pro port $port\n";
    foreach my $host( @hosts ) {    
      if ($p->ping($host, $timeout)){
        print "$host is reachable\n";
      }
      else{
        print "$host is NOT reachable\n";
      }
    }
    $p->close();
    sleep(2);
}
exit;

#$ sudo perl ping.pl  google.com 

Protocol tcp port 443
google.com is reachable

Protocol udp port 7
google.com is NOT reachable

Protocol icmp port 7
google.com is reachable

Protocol syn port 7
google.com is reachable

ping 和 curl 输出(videotron 网络)

#$ ping -c 4 google.com
PING google.com (24.200.237.84) 56(84) bytes of data.
64 bytes from google-084.237.cache.videotron.ca (24.200.237.84):    icmp_seq=1 ttl=61 time=7.14 ms
64 bytes from google-084.237.cache.videotron.ca (24.200.237.84):    icmp_seq=2 ttl=61 time=10.1 ms
64 bytes from google-084.237.cache.videotron.ca (24.200.237.84):    icmp_seq=3 ttl=61 time=6.86 ms
64 bytes from google-084.237.cache.videotron.ca (24.200.237.84): icmp_seq=4 ttl=61 time=8.86 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 6.866/8.243/10.102/1.320 ms

#$ curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.ca/?gfe_rd=cr&amp;ei=ArVmVbiOLajd8gfKq4DoCQ">here</A>.
</BODY></HTML>

相关内容