ssh -N -D 127.0.0.1:7777 -p <port> root@<host>
上述命令将本机7777端口与远程服务器的ssh端口之间做了一个端口转发(port forwarding)。
本机应用配置好代理之后,就相当于运行在服务器的网络上,对于调试或者访问内网资源比较方便。
下面是ssh协议关于-D参数的部分说明
Specifies a local “dynamic” application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as a SOCKS server. Only root can forward privileged ports. Dynamic port forwardings can also be specified in the configuration file.
-R 参数也可以设置端口转发,具体没有操作过。
在程序开发的过程中,经常会遇到这样的情况:数据和数据都运行在客户内网,出现问题只能通过输出日志的方式进行调试。现在好了,通过SOCKS代理的方式可以解决这个问题了。
比如java程序,可以指定jvm参数来使用网络代理
-DsocksProxyHost=localhost -DsocksProxyPort=7777
关于jvm代理方面的内容见官方说明
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用。你还可以使用@来通知其他用户。