socat
is a powerful and versatile utility that can be used for a wide range of network-related tasks, including TCP port forwarding.
To use socat
for TCP port forwarding, you can use the following command:
$ socat TCP-LISTEN:local_port,fork TCP:remote_host:remote_port
In this command, replace local_port
with the port number on your local machine that you want to forward, remote_host
with the IP address or hostname of the remote machine that you want to forward to, and remote_port
with the port number on the remote machine that you want to forward to.
The fork
option instructs socat
to handle each connection in a separate process, allowing it to handle multiple connections simultaneously.
Here is an example:
$ socat TCP-LISTEN:8080,fork TCP:example.com:80
This command will forward all incoming connections to port 8080 on the local machine to port 80 on the remote machine example.com
.
You can also use socat
to forward UDP traffic, by replacing TCP
with UDP
in the command.
socat
has many other options and capabilities that make it a powerful tool for network-related tasks. Refer to its manual page for more information on its options and usage.