
スポンサーリンク
pingコマンドとは、読み方
ネットワークの疎通確認やトラブルシューティングに使用される基本的なツールで、
通信相手が「生きているかどうか」を調べるコマンドです。
コマンドを実行することで相手までのネットワークの経路が正しく設定され、
通信が行える状態になっているかどうかを確かめることができます。
余談ですが、ping
はピン
またはピング
と読みます。
pingの使い方
pingに接続先IPアドレス or ホスト名を指定して使います。
構文
構文は以下の通りです。
ping [オプション] [宛先IPアドレスorホスト名]
コマンドを中断する場合はCtrl+C
で抜けられます。
example.comにpingする
example.comにpingする場合は、以下コマンドを実行します。
ping example.com
コマンドを実行すると以下のように表示されます。
$ ping example.comPING example.com (93.184.215.14) 56(84) bytes of data.64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=1 ttl=51 time=118 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=51 time=111 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=3 ttl=51 time=111 ms^C--- example.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2003msrtt min/avg/max/mdev = 111.029/113.331/117.790/3.153 ms
回数を指定してpingを実行する
回数を指定する場合は、-c 回数
を指定します。
例えば以下コマンドでは、3回pingを実行します。
ping -c 3 example.com
コマンドを実行すると以下のように表示されます。
$ ping -c 3 example.comPING example.com (93.184.215.14) 56(84) bytes of data.64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=1 ttl=51 time=111 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=51 time=113 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=3 ttl=51 time=112 ms
--- example.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2004msrtt min/avg/max/mdev = 111.326/112.282/113.026/0.710 ms
回数指定により途中でCtrl+C
で抜ける必要がなくなります。
パケットサイズ(bytes)を指定してpingを実行する
送信パケットサイズを指定する場合は、-s サイズ
を指定します。
例えば以下コマンドでは、100bytesを指定して実行します。
ping -s 100 example.com
コマンドを実行すると以下のように表示されます。
$ ping -s 100 example.comPING example.com (93.184.215.14) 100(128) bytes of data.108 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=1 ttl=51 time=111 ms108 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=51 time=111 ms108 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=3 ttl=51 time=111 ms^C--- example.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2004msrtt min/avg/max/mdev = 110.801/111.127/111.453/0.266 ms
パケット送信の間隔(秒)を指定してpingを実行する
パケットの送信間隔を指定する場合は、-i 秒
を指定します。
例えば以下コマンドでは、3秒間隔を指定して実行します。
ping -i 3 example.com
コマンドを実行すると以下のように表示されます。
$ ping -i 3 example.comPING example.com (93.184.215.14) 56(84) bytes of data.64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=1 ttl=51 time=111 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=51 time=111 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=3 ttl=51 time=112 ms^C--- example.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 6007msrtt min/avg/max/mdev = 111.148/111.556/112.059/0.377 ms
上記の通り、送信間隔が広がったことによりtime 6007ms
となりました。
タイムアウト(秒)を指定してpingを実行する
パケット送信のタイムアウトを指定する場合は、-W 秒
を指定します。
例えば以下コマンドでは、3秒のタイムアウトを指定して実行します。
ping -W 3 example.com
コマンドを実行すると以下のように表示されます。
$ ping -W 3 example.comPING example.com (93.184.215.14) 56(84) bytes of data.64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=1 ttl=51 time=113 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=51 time=112 ms64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=3 ttl=51 time=111 ms^C--- example.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2004msrtt min/avg/max/mdev = 111.362/111.853/112.694/0.597 ms
上記の通りタイムアウトしなければ、通常通り表示されます。
オプションを組み合わせて実行
以下コマンドのようにオプションを組み合わせて実行することもできます。
(200bytesのパケットを2秒間隔で、5回実行。)
ping -c 5 -s 200 -i 2 example.com
$ ping -c 5 -s 200 -i 2 example.comPING example.com (93.184.215.14) 200(228) bytes of data.208 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=51 time=120 ms208 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=3 ttl=51 time=112 ms208 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=4 ttl=51 time=112 ms208 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=5 ttl=51 time=111 ms
--- example.com ping statistics ---5 packets transmitted, 4 received, 20% packet loss, time 8042msrtt min/avg/max/mdev = 111.220/113.729/119.814/3.529 ms
オプション一覧
各オプションの意味は以下の通りです。
オプション | 意味 |
---|---|
-c | 回数を指定して実行 |
-s | パケットサイズ(bytes)を指定して実行 |
-i | パケット送信の間隔(秒)を指定して実行 |
-W | タイムアウト(秒)を指定して実行 |
以上で本記事の解説を終わります。
よいITライフを!