Linux Network Tools - Netcat


Netcat (nc)

Sometimes it is useful to listen to a port a monitor what requests/data are being sent to it.


Open a client to port 7000 on localhost. Type something and hit enter to send a message. If the client is unable to make a connection then it will close.

Add the -l optiont to listen to port 7000 on localhost.


Use the -u option to send to UDP packets.

Use the UDP and listen options together to create a simple UDP server.

Port scan with Netcat

The -z option performs a scan. The -v option give a verbose output.

We can also use a range of ports. Another useful option is -n which tells nc to not resolve the IP address using DNS. You have to use the IP address. This improves performance.

nc sends messages to standard error. In order to pipe the results to another program, we need to redirect standard error to standard output via 2>&1. We can then filter the results with grep.

Using files with Netcat

Put received messages into a file.

Send file from client to server.

You can even serve html files with netcat and access it with your browser.


-w keep connection open for x seconds.

-k flag forces it to stay open forever, even after the client logs off.

IPV4 and IPV6

-4 IPV4 address

-6 IPV6 address


mkfifo make first in, first out named pipe. Pipes are generally unidirectional. This allows the proxy to send and receive data from the target server. We can access via localhost:7000.



python -m SimpleHTTPServer 7000