Forrest logo
back to the nc tool

nc:tldr:1a731

nc: Act as proxy and forward data from a local TCP port to the given remote host.
$ nc -l ${local_port} | nc ${hostname} ${remote_port}
try on your machine

This command sets up a network connection between two computers using the nc (netcat) command.

Here is the breakdown of the command:

  1. nc: This is the command used to establish a network connection.

  2. -l: This option tells nc to listen for incoming connections.

  3. ${local_port}: This is a placeholder for the local port number. It should be replaced with an actual port number. The local port is the port on your local machine where nc will listen for incoming connections.

  4. |: This is the pipe operator, which connects the output of the first nc command to the input of the second nc command.

  5. nc: This is the second nc command, which will establish the connection to the remote host.

  6. ${hostname}: This is a placeholder for the hostname or IP address of the remote host. It should be replaced with the actual hostname or IP address.

  7. ${remote_port}: This is a placeholder for the remote port number. It should be replaced with an actual port number. The remote port is the port on the remote host where nc will establish the connection.

In summary, this command sets up a network connection by listening for incoming connections on the local machine's ${local_port}, and establishes a connection to the ${hostname} on the ${remote_port}. Any data received on the local machine's ${local_port} will be sent to the remote host on the ${remote_port}.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the nc tool