pingコマンド
WindowsやLinuxなどのOSのコマンドで、ネットワーク上の他のホストにパケットが到達するかを確認するコマンド。ICMPプロトコルを利用している。
このコマンドを実行すると相手のホストからの応答時間が得られる。
OSによりコマンドのオプションが異なるため、注意が必要。
使用例
たとえば、IPアドレス192.168.2.1のホストへパケットを送信するときはコマンドを次のように実行する。
Linuxの場合
オプションcでパケット送信回数を指定します。これを省略すると無限に送信します。
[sakabe@localhost sakabe]$ ping -c 4 192.168.2.1 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.835 ms 64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.693 ms 64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=1.29 ms 64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.383 ms --- 192.168.2.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 0.383/0.800/1.290/0.327 ms
Windowsの場合
C:\sakabe>ping 192.168.2.1 Pinging 192.168.2.1 with 32 bytes of data: Reply from 192.168.2.1: bytes=32 time<1ms TTL=64 Reply from 192.168.2.1: bytes=32 time<1ms TTL=64 Reply from 192.168.2.1: bytes=32 time<1ms TTL=64 Reply from 192.168.2.1: bytes=32 time<1ms TTL=64 Ping statistics for 192.168.2.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
次の実行例は存在しない、あるいは停止中のホストへパケットを送った場合です。
Linuxでの実行例
[sakabe@localhost sakabe]$ ping -c 4 192.168.2.110 PING 192.168.2.110 (192.168.2.110) 56(84) bytes of data. From 192.168.2.11 icmp_seq=1 Destination Host Unreachable From 192.168.2.11 icmp_seq=2 Destination Host Unreachable From 192.168.2.11 icmp_seq=3 Destination Host Unreachable From 192.168.2.11 icmp_seq=4 Destination Host Unreachable --- 192.168.2.110 ping statistics --- 4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3011ms , pipe 3
Windowsでの実行例
[sakabe@localhost sakabe]$ ping -c 4 192.168.2.1 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.835 ms 64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.693 ms 64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=1.29 ms 64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.383 ms --- 192.168.2.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 0.383/0.800/1.290/0.327 ms