server A B C D
<A> <B> <C> <D>
- Local -- Forward local port to remote host.
- Remote -- Forward remote port to local host.
- Dynamic -- Use SOCKS.
#---------------------------------------------------------------
<A>$ ssh -L 8888:<C>:22 root@<B>
<A> 打开本地8888端口,访问<A>的8888端口,实现通过 <B> 跳转到<C>的22端口
#-----------------------------------------------------------------
<B> sshd_config
GatewayPorts no # 不允许外部访问<B>
GatewayPorts yes # 允许外部访问<B>的端口
GatewayPorts clientspecified # 指定被允许的外部IP
<C>$ ssh -R 8888:localhost:22 root@<B>
<A>访问<B>的8888端口,实现通过 <B> 跳转到<C>的22端口
<C>$ ssh -R 8888:<D>:22 root@<B>
<A>访问<B>的8888端口,实现通过 <B> 跳转到<D>的22端口
#--------------------------------
SOCKS:Specifies a local ``dynamic'' application-level port forwarding
<B>$ ssh -D 0.0.0.0:8888 root@<C>
<A>通过<B>的8888端口使用<C>作为代理
来源:oschina
链接:https://my.oschina.net/redhands/blog/3188069