9月 032018
 

如图:

Local B想访问Remote B的80端口,但是由于网络限制,访问不到,但是,Local A可以访问Remote A的22端口,于是:

这样就可以在Local A上listen一个80端口,将接收到的数据包转发给Remote B的80端口

由于listen的端口在本地,所以叫做本地端口转发。

-f 选项: 后台执行

-N 选项: 不执行任何命令,仅仅是用于端口转发

 

同样是Local A可以主动访问Remote A,但是Remote A不能ssh访问Local A,我们想让Remote B能访问Local B的80端口,如何做呢?(注意: 这里并不是上述逻辑的一个翻版)

命令:

这样就可以在Remote A上listen一个80端口,将接收到的数据转发到Local B的80端口;

由于listen的80在远端,所以叫远程端口转发

 

相关原理:

当通过端口转发创建虚线中的连接时,local A和remote A 之间并不会创建一个新的tcp连接,而是在原有tcp连接上创建了新的channel,这个可以在ssh 时 -vvvv看到相关信息

 

如果想要以daemon的形式只做端口转发,不想交互式的登录的远程机器,可以使用-f -N选项,如下:

如果想30分钟后失效,则可以:

 Posted by at 下午 4:56

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据