pingコマンドの詳細とエラー通知について説明します。
pingコマンドとは
pingコマンドは、ICMPを利用してネットワークの正常性を確認するためのコマンドです。指定したIPアドレスに対してエコー要求(echo request)を送信して、エコー応答(echo reply)を受け取ることで、ネットワークが疎通可能なことを確認します。また、応答時間を計ることにより、通信の遅延時間を測定する用途でも利用されます。
ネットワークに異常がある場合は、ICMPのType/Codeを利用して通信異常の理由を通知することにより、ネットワークの問題解決にも利用することができます。
ICMPの説明とType/Codeの一覧については下記を参照してください。

ping通信の詳細
ネットワーク構成
下記のネットワークをCiscoCMLで構築し、ping通信の検証を行います。

Desktop → Server へのping実施
Desktopでpingコマンドを実行します。
ping 172.16.1.1
Desktop:~$ ping 172.16.1.1
PING 172.16.1.1 (172.16.1.1): 56 data bytes
64 bytes from 172.16.1.1: seq=0 ttl=42 time=12.133 ms
64 bytes from 172.16.1.1: seq=1 ttl=42 time=6.812 ms
64 bytes from 172.16.1.1: seq=2 ttl=42 time=12.303 ms
64 bytes from 172.16.1.1: seq=3 ttl=42 time=9.219 ms
64 bytes from 172.16.1.1: seq=4 ttl=42 time=8.505 ms
^C
--- 172.16.1.1 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 6.812/9.794/12.303 ms
pingコマンドを実行すると、DesktopからServerに対して、ICMPエコー要求を送信します。

エコー要求は、ICMPのType8が利用されます。
パケットキャプチャ抜粋
Internet Protocol Version 4, Src: 192.168.1.1, Dst: 172.16.1.1
Time to live: 64
Protocol: ICMP (1)
Source: 192.168.1.1
Destination: 172.16.1.1
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0
Checksum: 0x59a7 [correct]
Sequence number (BE): 0 (0x0000)
Sequence number (LE): 0 (0x0000)
ICMPエコー要求を受け取ったServerは、ICMPエコー応答を返信することにより、ネットワークが正常であることをDesktopへ伝えます。

エコー応答は、ICMPのType0が利用されます。
パケットキャプチャ抜粋
Internet Protocol Version 4, Src: 172.16.1.1, Dst: 192.168.1.1
Time to live: 62
Protocol: ICMP (1)
Source: 172.16.1.1
Destination: 192.168.1.1
Internet Control Message Protocol
Type: 0 (Echo (ping) reply)
Code: 0
Checksum: 0x61a7 [correct]
Sequence number (BE): 0 (0x0000)
Sequence number (LE): 0 (0x0000)
代表的なエラー通知の種類
ICMPの代表的なエラー通知である下記について説明します。
- Destination Unreachable (Type 3)
- Host Unreachable (Code 1)
- Communication Administratively Prohibited (Code 13)
- Time Exceeded (Type 11)
- Time to Live Exceeded in Transit (Code 0)
Destination Unreachable (Type 3)
Host Unreachable (Code 1)
経路途中で宛先ホストへの経路が無くなった場合に利用されます。ここでは、Router2のGi0/0をshutdownすることにより、途中経路でルーティングがない状態にして検証します。

Router2は、パケットを破棄したことを送信元(Desktop)へ伝えるために、Destination Unreachable/Host UnreachableのICMPパケットを送信します。

Destination Unreachable/Host Unreachableは、ICMPのType3/Code1が利用されます。また、ICMPのデータ部には送信されたICMPエコー要求の情報が格納されます。
パケットキャプチャ抜粋
Internet Protocol Version 4, Src: 10.0.0.2, Dst: 192.168.1.1
Time to live: 254
Protocol: ICMP (1)
Source: 10.0.0.2
Destination: 192.168.1.1
Internet Control Message Protocol
Type: 3 (Destination unreachable)
Code: 1 (Host unreachable)
Checksum: 0x7242 [correct]
Internet Protocol Version 4, Src: 192.168.1.1, Dst: 172.16.1.1
Time to live: 62
Protocol: ICMP (1)
Source: 192.168.1.1
Destination: 172.16.1.1
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0
Checksum: 0x82a7 [unverified] [in ICMP error packet]
Sequence number (BE): 0 (0x0000)
Sequence number (LE): 0 (0x0000)
Communication Administratively Prohibited (Code 13)
経路途中のアクセスリスト等で通信制御されている場合に利用されます。ここでは、Router2のGi0/1でDesktopからの通信をアクセスリストで拒否することにより、通信が行えない状態にして検証します。

Router2は、パケットを破棄したことを送信元(Desktop)へ伝えるために、Destination Unreachable/Communication Administratively ProhibitedのICMPパケットを送信します。

Destination Unreachable/Communication Administratively Prohibitedは、ICMPのType3/Code13が利用されます。また、ICMPのデータ部には送信されたICMPエコー要求の情報が格納されます。
パケットキャプチャ抜粋
Internet Protocol Version 4, Src: 10.0.0.2, Dst: 192.168.1.1
Time to live: 254
Protocol: ICMP (1)
Source: 10.0.0.2
Destination: 192.168.1.1
Internet Control Message Protocol
Type: 3 (Destination unreachable)
Code: 13 (Communication administratively filtered)
Checksum: 0xfdf2 [correct]
Internet Protocol Version 4, Src: 192.168.1.1, Dst: 172.16.1.1
Time to live: 62
Protocol: ICMP (1)
Source: 192.168.1.1
Destination: 172.16.1.1
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0
Checksum: 0xf6ec [unverified] [in ICMP error packet]
Sequence number (BE): 0 (0x0000)
Sequence number (LE): 0 (0x0000)
RFCでは「Communication Administratively Prohibited」として定義されていますが、Wiresharkでは「Communication administratively filtered」と表示されます。
Time Exceeded (Type 11)
Time to Live Exceeded in Transit (Code 0)
TTL値(Time to Live)が経路途中で0になった場合に利用されます。ここでは、Router2のルーティングに誤りがあったことを想定し、Router1とRouter2の間でルーティングループが起きる状態にして検証します。

Router2は、パケットを破棄したことを送信元(Desktop)へ伝えるために、Time Exceeded/Time to Live Exceeded in TransitのICMPパケットを送信します。

Time Exceeded/Time to Live Exceeded in Transitは、ICMPのType11/Code0が利用されます。また、ICMPのデータ部には送信されたICMPエコー要求の情報が格納されます。
パケットキャプチャ抜粋
Internet Protocol Version 4, Src: 10.0.0.2, Dst: 192.168.1.1
Time to live: 254
Protocol: ICMP (1)
Source: 10.0.0.2
Destination: 192.168.1.1
Internet Control Message Protocol
Type: 11 (Time-to-live exceeded)
Code: 0 (Time to live exceeded in transit)
Checksum: 0x8d01 [correct]
Internet Protocol Version 4, Src: 192.168.1.1, Dst: 172.16.1.1
Time to live: 1
Protocol: ICMP (1)
Source: 192.168.1.1
Destination: 172.16.1.1
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0
Checksum: 0x5fe7 [unverified] [in ICMP error packet]
Sequence number (BE): 0 (0x0000)
Sequence number (LE): 0 (0x0000)
以上で、ICMPを利用した技術(1.pingコマンド)の説明は完了です!