一歩前進

プログラミングに関する雑多なメモ

tracerouteで応答がないときはtcptracerouteを試す

tracerouteコマンド(Windowsはtracert)を使った時に、経路上のゲートウェイがUDPやICMPに対して応答を返さないようになっていて、経路が分からないときがあります。
そんなときは、TCPを用いてtracerouteを行うtcptracerouteコマンドを使うと経路がわかることがあります。

試しに使ってみましょう。

インストール

Debian系の場合:

$ apt-get install tcproute

Mac(MacPorts)の場合:

$ sudo port install tcptraceroute

実行例

UDPやICMPで経路が分からないホストに対して、TCPで経路を調べていきます。

UDPでtraceroute

まずはUDPです。Unix/LinuxのtracerouteはデフォルトでUDPを使うようになっています。(WindowsのtracertはICMPを使う)

$ traceroute www.microsoft.com
 1  192.168.0.1 (192.168.0.1)  4.197 ms  0.953 ms  0.641 ms
(中略)
14  te0-0-0-1.ccr21.sea02.atlas.cogentco.com (154.54.11.77)  106.739 ms
    te0-7-0-1.ccr21.sea02.atlas.cogentco.com (154.54.13.181)  93.777 ms
    te0-3-0-1.ccr21.sea02.atlas.cogentco.com (154.54.11.205)  96.185 ms
15  38.104.127.26 (38.104.127.26)  120.712 ms  108.404 ms  117.788 ms
16  * * xe-8-1-0-0.bl2-96c-1a.ntwk.msn.net (207.46.47.95)  137.991 ms
17  xe-2-0-0-0.co1-96c-1b.ntwk.msn.net (207.46.33.181)  148.959 ms  129.953 ms *
18  * * *
19  * * *
20  * * *
21  * * *
(以下略)

上記の例では、tracerouteを使ってwww.microsoft.comへのネットワークの経路を調べていますが、途中から応答が返ってきていません。
18番目以降は、おそらくUDPパケットをフィルタリングしているか、Time Exceeded Messageを返さないルーターなのでしょう。

ICMPでtraceroute

次は、ICMPで同じことをしてみます。

  • I オプションを指定すると、ICMPで経路を調べます。
 1  192.168.0.1 (192.168.0.1)  2156.173 ms  0.785 ms  0.759 ms
(中略)
14  te0-7-0-1.ccr21.sea02.atlas.cogentco.com (154.54.13.181)  134.897 ms
    te0-3-0-1.ccr21.sea02.atlas.cogentco.com (154.54.11.205)  135.232 ms
    te0-7-0-1.ccr21.sea02.atlas.cogentco.com (154.54.13.181)  125.241 ms
15  38.104.127.26 (38.104.127.26)  131.162 ms  135.686 ms  125.549 ms
16  207.46.44.69 (207.46.44.69)  159.945 ms  135.894 ms  139.980 ms
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
(以下略)

同様に、途中から応答がありません。

TCPでtraceroute

UDPもICMPでも経路が辿れなかったので、次はTCPで試してみます。ここで、さきほどインストールしたtcptracerouteコマンドを使います。
ホスト名の後にポート番号を指定することができます。今回はポート80(HTTP)で確認します。

$ tcptraceroute www.microsoft.com 80
Selected device en0, address 192.168.0.5, port 57051 for outgoing packets
Tracing the path to www.microsoft.com (64.4.11.42) on TCP port 80 (http), 30 hops max
 1  192.168.0.1  0.708 ms  0.567 ms  0.564 ms
(中略)
14  te0-0-0-1.ccr21.sea02.atlas.cogentco.com (154.54.11.77)  94.864 ms  96.656 ms  96.046 ms
15  38.104.127.26  111.067 ms  184.925 ms  110.731 ms
16  xe-1-1-2-0.by2-96c-1a.ntwk.msn.net (207.46.40.66)  110.524 ms  156.835 ms  116.685 ms
17  xe-7-0-1-0.bay-16c-1a.ntwk.msn.net (207.46.46.140)  109.773 ms  110.032 ms  113.010 ms
18  * * *
19  64.4.11.42 [open]  131.831 ms  126.131 ms  126.740 ms

今度はゴールまで辿れました。
18番目のゲートウェイから応答が返っていないので、我が家のルーターからwww.microsoft.comまでは18ホップで辿れるということですね。

ちなみに、Macの場合、以下のように"Got root?"とメッセージが返ってきます。この場合、sudo で実行しなおしてください。

$ tcptraceroute www.microsoft.com
Got root?

おまけ

Macの最大ホップ数

Linuxの場合、tracerouteのデフォルトのTTLの最大値(最大ホップ数)は30ですが、Macの場合は、"net.inet.ip.ttl"の値がTTLの最大値になっています。
"net.inet.ip.ttl"の値は、以下のように確認できます。

$ sysctrl net.inet.ip.ttl
net.inet.ip.ttl: 64

なお、MacPortsからインストールしたtcptracerouteは" net.inet.ip.ttl"の値を使っておらず、デフォルト値は30でした。

hatenablog.com

hatenablog.comはAmazon Web Servicesを使っているようです。

$ tcptraceroute hatenablog.com
Selected device en0, address 192.168.0.5, port 60346 for outgoing packets
Tracing the path to hatenablog.com (54.249.30.47) on TCP port 80 (http), 30 hops max
 1  192.168.0.1  0.796 ms  0.572 ms  0.566 ms
(中略)
15  27.0.0.129  9.807 ms  12.558 ms  9.704 ms
16  27.0.0.147  9.605 ms  9.763 ms  9.760 ms
17  ec2-54-249-30-47.ap-northeast-1.compute.amazonaws.com (54.249.30.47) [open]  9.869 ms  10.952 ms  9.751 ms

ためしに、http://ec2-54-249-30-47.ap-northeast-1.compute.amazonaws.com
としてブラウザでアクセスすると、hatenablogのページが表示されます。