nc Command: Tutorial & Examples

Send data over the network

nc (short for "netcat") is a command-line utility in Linux that allows you to read and write data across networks using the TCP and UDP protocols. It is often referred to as the "Swiss Army knife" of networking tools because it can be used for a wide range of tasks, including network debugging, port scanning, and file transfers.

nc can be used in a variety of ways, but some of the most common uses include:

  • Connecting to a remote server on a specific port: nc <server-name> <port-number>
  • Listening on a specific port for incoming connections: nc -l <port-number>
  • Sending data to a remote server: echo "Hello, world!" | nc <server-name> <port-number>
  • Reading data from a remote server: nc <server-name> <port-number>

nc can also be used in combination with other commands, like grep or sed to filter and process the data that is read or written.

It can also be used as a simple server or client to connect and transfer data between two hosts.

nc can also be used for port scanning, it can be used to check if a specific port is open on a remote server, for example:

nc -vz <server-name> <port-number>

nc is a powerful command-line tool that can be used for a wide range of networking tasks. It is simple to use and can be integrated with other commands and scripts to automate network-related tasks.

The text above is licensed under CC BY-SA 4.0 CC BY SA