Categories: Networking

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.

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.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Linux gdisk command (partitioning disk) [Basic Guide]

The gdisk command in Linux is similar to fdisk and allows you to manipulate and…

2 years ago

This website uses cookies.