
tcpforward - forward or tunnel TCP connections

tcpforward [OPTIONS] -l|-c host1:port1 -l|-c host2:port2
-l host:port listen on host:port, forward accepted connections -c host:port connect to host:port, forward this connection -N count exit after forwarding count connections -k fork before forwarding (default: no) -s size chunk size for non-blocking reads (default: 1024) -V print version and exit -v turn on parseable logging -h display usage information

Forward local SMTP to a remote mailserver:
$ tcpforward -k -c mailserver:25 -l localhost:25
Forward tunnel the SSH service on 10.0.0.100 to 10.0.0.101:
[10.0.0.100]$ tcpforward -l 10.0.0.100:9922 -c localhost:22 [10.0.0.101]$ tcpforward -c 10.0.0.100:9922 -l localhost:22 [10.0.0.101]$ ssh localhost
Reverse tunnel the SSH service on 10.0.0.100 to 10.0.0.101:
[10.0.0.101]$ tcpforward -l 10.0.0.101:9922 -l localhost:22 [10.0.0.100]$ tcpforward -c 10.0.0.101:9922 -c localhost:22 [10.0.0.101]$ ssh localhost

tcpforward is a userspace TCP connection forwarder. It uses efficient non-blocking I/O and is protocol agnostic.
Some uses include:

tcpforward does not provide encryption of any sort. Forward only encrypted connections if security is an issue. Consider SSH tunneling or stunnel if you need an encrypted tunnel.
That said, part of the original motivation for tcpforward was reverse tunneling of the SSH service itself back through a NAT'ed gateway. Using ssh to establish the tunnel would have incurred the penalty of double encryption.

Connect to host:port, then do forwarding on the socket.
Listen for connections on host:port, then do forwarding on the accepted socket.
Exit after forwarding count TCP connections.
Fork and perform forwarding in a child process. This permits multiple simultaneous forwarded connections. The default is non-forking.
When forwarding, attempt non-blocking reads of size bytes at a time. Setting this to the median packet size for a given protocol may result in some small performance gain.
Print version number and exit.
Turn on parseable logging to standard out. Increase logging level with extra -v options.
Display usage information.

tcpforward should be rewritten in C. Please report other bugs on CPAN.

Alan Grow <agrow+nospam@thegotonerd.com>

Copyright (C) 2007 by Alan Grow
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.