Back to the command reference

nc

NetworkAdvanced In real Linux

netcat: read and write network connections

Name: nc = netcat (cat for the network)

This command needs a real Linux system; you can practise it in real Linux mode.

Description

nc (netcat) reads and writes TCP and UDP connections, the "Swiss army knife" of networking: test whether a port is open, listen on a port, move files between machines or talk to a service by hand. Implementations differ between distributions, so some options vary.

Syntax

nc [OPTION]... HOST PORT

Common options

-lListen
-kWith -l: keep listening after a connection ends
-zJust scan for open ports
-vVerbose
-uUse UDP
-w TIMEOUTGive up after TIMEOUT seconds of connecting or silence
-NClose the connection at the end of the input (when sending a file)
-nDo not look up host names

Examples

  • $ nc -zv db01 5432

    Is port 5432 on db01 open?

    Explain
  • $ nc -l 9000

    Listen on 9000 and print what arrives

    Explain

Related