0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TCP疎通確認用のコマンド2選

Last updated at Posted at 2025-02-24

コマンド一覧

Windows(Powershell)

  • Test-Netconnection
    • 例:Test-NetConnection 172.31.100.10 -port 443

Linux

  • mtr
    • mtr -T -P 443 172.31.100.10

Test-NetConnection

portを指定すれば、TCPでの疎通確認ができます。
詳しい説明は以下を参照。

ここでは一例を説明します。

image.png

TcpTestSucceededがTrueであるため、172.31.100.10の443 Portへ接続できている

手軽なPingの落とし穴

その一方で、pingコマンドはあまり活躍できないです。
あっちこっちでICMPがblockされている可能性があります。
実際には接続できているにも関わらず、pingの応答がないためにで誤って接続不可と判断してしまうケースが多いです。

image.png

Test-NetConnectionの実行時と同じネットワーク設定にも関わらず、ping失敗

mtr

tcp protocolとportを指定すれば、TCPでの疎通確認ができます。
詳しい説明は以下を参照。

ここでは一例を説明します。

  • 172.31.100.10への443 Portへの接続確認
    • mtr -T -P 443 172.31.100.10

episode

あるプロジェクトである日、チームメンバーからmtr失敗の連絡がありました。
しかし、Test-NetConnectionは成功しました。

以下は失敗したとき取った画面キャプチャです。
image.png

一見コマンドに問題ないと思われたが、改めて確認すると、なんと小文字の「-p」になっていました。
mtr optionでは小文字「-p」と大文字「-P」とで意味がまったく異なります。

-p, --split
 Use this option to set mtr to spit out a format that is suitable for a split-user interface.
-P PORT, --port PORT
 The target port number for TCP/SCTP/UDP traces.

「mtr -p 443」で実行すると、IP「0.0.1.187」と通信しようとすることです。当然失敗しました。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?