socat
is a command-line utility for transferring data between file descriptors, sockets, or other data sources and sinks. It can be used as a TCP port forwarder on a Linux or Unix system.
To use socat
as a TCP port forwarder, you can use the following command:
socat TCP4-LISTEN:<local_port>,fork TCP4:<remote_host>:<remote_port>
This will listen on the specified <local_port>
and forward all incoming connections to the <remote_host>:<remote_port>
destination. The fork
option allows socat
to handle multiple connections concurrently.
For example, to forward all incoming connections on port 8080 to a remote host on port 80, you can use the following command:
socat TCP4-LISTEN:8080,fork TCP4:remote_host:80
You can also use the -d
option to run socat
in the background and the -v
option to enable verbose output.
Keep in mind that you will need to have permission to bind to the specified <local_port>
and to establish a connection to the <remote_host>:<remote_port>
destination.
You can also use socat
to forward other types of connections, such as UDP, Unix domain sockets, or serial ports. For more information about the options and usage of socat
, you can refer to the socat
manual page or the socat
website.