Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · sockets & transfer

nc

a raw network connection

nc — netcat — connects to a port and joins it to your keyboard and screen. With nothing else in the way, it shows whether a port is reachable and what the service says first. It can also listen on a port and accept a connection.

nc -zv host port answers the most common network question: is that port open from here?

Test a port
nc -zv HOST PORT
connect, report, close
Talk to a service
nc HOST PORT
type the protocol by hand
Listen
nc -l PORT
wait for a connection
UDP
-u
TCP is the default

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashnetcat-openbsd
$ nc -zv 192.0.2.10 22
1Connection to 192.0.2.10 22 port [tcp/ssh] succeeded!
2$ nc -zv 192.0.2.10 3306
nc: connect to 192.0.2.10 port 3306 (tcp) failed: Connection refused
3$ nc 192.0.2.10 22
SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.5
4$ nc -l 9000
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The port is open

A TCP connection was made and closed. -z sends no data; -v reports the result.

2
Refused

The host answered, but nothing is listening on that port. A firewall silently dropping the packets would instead hang until it timed out.

3
The service’s banner

Connecting without -z shows what the server sends first — here the SSH version string.

4
Listening

nc waits on port 9000. Whatever another machine sends to that port appears here; it is a quick way to test that a firewall rule lets traffic through.

Switches

A switch changes how the command behaves. These are the ones used day to day; man nc lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-z
Zero I/O: just test whether the port is open.
-v
Verbose: report the result.
-l
Listen for an incoming connection.
-u
Use UDP instead of TCP.
-w SECS
Time out after this many seconds.
-n
Numeric only: do not look up names.
-k
Keep listening after a client disconnects.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

nc -zv 192.0.2.10 20-25

Tests a range of ports.

nc -zvw 3 192.0.2.10 443

Gives up after three seconds instead of waiting.

printf "GET / HTTP/1.0\r\n\r\n" | nc example.com 80

Sends an HTTP request by hand and prints the raw response.

nc -zvu 192.0.2.53 53

Tests a UDP port.

In cybersecurity

netcat is equally a diagnostic tool and an attacker’s tool.

Banners disclose versions

Many services announce their software and version on connect. That is what an attacker matches against lists of known vulnerabilities.

Reverse shells

netcat can attach a shell to a network connection. An nc process on a server that nobody started, especially with -e or connected to an outside address, is an incident.

Only test what you may

Probing ports on systems you do not own or have permission to test is unauthorised access in many jurisdictions.

Protocols it shows

TCPUDP

Read alongside