Netcat command on Linux (Swiss network knife) [Basic Guide]

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 
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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Need help?