Skip to content

Netcat command on Linux (Swiss network knife)

The Netcat Command in Linux or nc is a utility used to do “almost anything” when it comes to the TCP and UDP protocols. It can be used to open TCP connections, send UDP packets, listen to any TCP or UDP port, and scan a host’s open ports.

It can be useful for serving as a simple TCP proxy, writing simple client and server HTTP scripts, testing network server processes (daemons), and many other functions.

Here are some examples of using Netcat:

To connect to any host:port using netcat, you must provide the host address and port. It’s useful to see if a particular server is responding:

$ nc google.com 80 <br></br>get../..

HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 1419
Date: Tue, 14 Apr 2015 02:11:11 GMT
Server: GFE/2.0

To use netcat as a process that listens on a certain port and sends the result to a file. It is useful to know what a client application is sending to a particular server:

$ nc —l —p 6565 > /tmp/arquivo.tmp

Netcat can even be used to listen to a certain port and play the result on the terminal:

$ nc -l -vv 4343

Netcat can be used to find out which ports are open on a given host. It is useful for verifying whether or not a particular service should be listening on the network:

$ nc -vv -w1 google.com 20-443

This tool can either behave as a server or client application, in order to test the services offered by a particular server or client.