nc (netcat)

ネットワーク

書き方

nc [-lv] <host> <port>

TCP や UDP を素のままつないで、ポートが答えるかを見たり二台の間に管を通したりします。名前が同じで互換のない版が三つ(OpenBSD・GNU・Nmap の ncat)あり、`-z` や `-p` が無いこともあります。

よく使うオプション

オプション意味
-lListen instead of connecting. On GNU netcat you also need -p <port>.
-vSay what happened, which is the whole point when testing a port.
-zScan without sending data. OpenBSD/macOS nc only; GNU netcat has no -z.
-w 3Give up after three seconds instead of hanging.
-uUDP instead of TCP.
-4 / -6Force one address family.

nc -zv example.com 443

Is the port open? Works on macOS and OpenBSD netcat.

nc -l 1234 # then on the other host: nc <host> 1234

A raw two-way pipe for a quick test.

nc -l 1234 > incoming.bin

Receive a file that the other side sends with nc host 1234 < file.

つながらないとき、どこまで行けたのかを絞ります — 名前が引けないのか、経路がないのか、ポートが閉じているのか。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. nc (netcat) は何をしますか。

TCP や UDP を素のままつないで、ポートが答えるかを見たり二台の間に管を通したりします。名前が同じで互換のない版が三つ(OpenBSD・GNU・Nmap の ncat)あり、`-z` や `-p` が無いこともあります。

Q. どう打ちますか。

nc [-lv] <host> <port> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man nc にあります。このコマンドはネットワークの仲間です。

関連するコマンド

man ページ: man nc-(netcat)