Total Pageviews

Friday, 8 March 2013

在linux vps上编译socat并在vps中做端口转发

wget http://www.dest-unreach.org/socat/download/socat-2.0.0-b8.tar.gz
tar zxvf socat-2.0.0-b8.tar.gz
cd  socat-2.0.0-b8
./configure
make
make install
(执行文件为/usr/local/bin/socat)

socat TCP4-LISTEN:1823,reuseaddr,fork TCP4:1723 &
在vps监听1823端口,并把进来的对1823端口的连接请求转发至vps的1723端口

另一个例子:socat TCP-LISTEN:1823,fork TCP:www.domain.org:80 &

TCP4-LISTEN:在vps建立的是一个TCP ipv4协议的监听端口;
fork:设定多链接模式,即当一个链接被建立后,自动复制一个同样的端口再进行监听
socat启动监听模式会占用一个shell,因此需使其在后台执行。

附:socat官方文档:http://www.dest-unreach.org/socat/doc/socat.html
http://technostuff.blogspot.de/2008/10/some-useful-socat-commands.html
http://blog.rootshell.be/2010/10/31/socat-another-network-swiss-army-knife/
http://www.nikhef.nl/~janjust/socat/ 
教程:http://wenku.baidu.com/link?url=k-JCkeHs3I0b0RpuNgixXDaxk5LkOz3An0N1NlJVbP4xecFXS-J7iAX8qEpKENuKOJ9rm7UBbvKARDZ68dUrH6KikFtUqQrrvMeCHdj3kP3

https://blog.csdn.net/w3045872817/article/details/78235917
-----------------------------------------------
“转发端口”好像不起作用 
-----------------------------------------------
Socat is a relay for bidirectional data transfer between two independent data channels. Each of these data channels may be a file, pipe, device (terminal or modem, etc.), socket (Unix, IP4, IP6 - raw, UDP, TCP), SSL, a client for SOCKS4, or proxy CONNECT. It supports broadcasts and multicasts, abstract Unix sockets, Linux tun/tap, GNU readline, and PTYs. It provides forking, logging, and dumping and different modes for interprocess communication. Many options are available for tuning socat and its channels. Socat can be used, for example, as a TCP relay (one-shot or daemon), as a daemon-based socksifier, as a shell interface to Unix sockets, as an IP6 relay, or for redirecting TCP-oriented programs to a serial line.

from http://freecode.com/projects/socat