(目录)
动态转发
$ ssh -D local-port tunnel-host -N
参数说明
-D
:动态转发-N
:不发送任何命令,只用来建立连接。没有这个参数,会在 SSH 服务器打开一个 Shelllocal-port
是本地端口tunnel-host
是 SSH 服务器
举例
# 开启本地端口2121 动态转发
$ ssh -D 2121 root@127.0.0.1 -N
# curl 的-x参数指定代理服务器
# 通过 SOCKS5 协议的本地2121端口,访问 https://httpbin.org/get
$ curl -x socks5://localhost:2121 https://httpbin.org/get
本地转发
$ ssh -L -N local-port:target-host:target-port tunnel-host
参数说明
-L
:转发本地端口
远程转发
$ ssh -R remote-port:target-host:target-port -N remotehost
参数说明
-R
表示远程端口转发