通过VMess进行SSH端口转发

    技术教程 vpnxxw 来源:nicho1as.wang 99次浏览 0个评论 扫描二维码

    0x00 惯例找起因

    由于有需求访问自己在国内家里的局域网,然而家里穷,又不是专线,辣鸡移动又死活没法给公网IP,于是一个端口转发/映射实现的需求应运而生。本来以为 V2Ray自带的dokodemo-door可以直接拿来用,毕竟要过境访问,直接ssh tunnel或者ngrok之类估计效果不佳,所以又到了编程小白用奇技淫巧实现需求的时候(自己造轮子什么的多麻烦,反正要求是能通就行,求诸位dalao不要在评论去喷性能辣(逃(滑稽

    0x01 实现

    所以具体操作就是。。本地V2Ray正常配客户端,添加一个dokodemo-door的inbound把服务器的22端口映射到本地。然后本地再SSH Tunnel到映射到本地的远程22端口的端口。

    (最近说话真的不知道为啥就是容易绕。。。勿怪)(反正会看我文章的估计也不会管前面的,都是来直接复制粘贴命令的吧(这么白的东西))

    当然你也可以选择其他任何基于TCP的网络服务对外开放,比如ngrok一样可以达到向外端口映射的功能。(不用是因为1 配置麻烦 2 需要单独证书 3 停止开源了不清真(

    不多说了直接丢 V2Ray 配置:

    {
          <span class="hljs-attr">"protocol"</span>: <span class="hljs-string">"dokodemo-door"</span>,
          <span class="hljs-attr">"port"</span>: [forwarded_ssh_port],
          <span class="hljs-attr">"settings"</span>: {
             <span class="hljs-attr">"address"</span>: <span class="hljs-string">"[remote_host]"</span>,
             <span class="hljs-attr">"port"</span>: [remote_ssh_port],
             <span class="hljs-attr">"network"</span>: <span class="hljs-string">"tcp,udp"</span>,
             <span class="hljs-attr">"timeout"</span>:<span class="hljs-number">0</span>
          }
        }

    以及 SSH Tunnel 命令

    <span class="hljs-selector-tag">ssh</span> <span class="hljs-selector-tag">-C</span> <span class="hljs-selector-tag">-f</span> <span class="hljs-selector-tag">-N</span> <span class="hljs-selector-tag">-R</span> <span class="hljs-selector-attr">[remote_service_port]</span><span class="hljs-selector-pseudo">:0.0.0.0</span>:<span class="hljs-selector-attr">[local_service_port]</span> <span class="hljs-selector-tag">user</span>@<span class="hljs-selector-attr">[local_host]</span> <span class="hljs-selector-tag">-p</span> <span class="hljs-selector-attr">[forwarded_ssh_port]</span>

    0x03 速度测试

    user@local_host<span class="hljs-symbol">:~</span>$ iperf3 -s -p <span class="hljs-number">2526</span>
    user@local_host<span class="hljs-symbol">:~</span>$ ssh -C -f -N -R <span class="hljs-number">2526</span><span class="hljs-symbol">:</span><span class="hljs-number">0</span>.<span class="hljs-number">0</span>.<span class="hljs-number">0</span>.<span class="hljs-number">0</span><span class="hljs-symbol">:</span><span class="hljs-number">2526</span> root@127.<span class="hljs-number">0</span>.<span class="hljs-number">0</span>.<span class="hljs-number">1</span> -p <span class="hljs-number">2222</span>
    user@remote_host<span class="hljs-symbol">:~</span>$ iperf3 -c <span class="hljs-number">127.0</span>.<span class="hljs-number">0</span>.<span class="hljs-number">1</span> -p <span class="hljs-number">2526</span> -R -n <span class="hljs-number">100</span>M -i <span class="hljs-number">5</span>

    测试结果

    测试环境:华东某省移动家宽20Mbps + DGCHOST 香港

    Connecting to host <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>, port <span class="hljs-number">2526</span>
    Reverse mode, remote host <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> is sending
    [  <span class="hljs-number">4</span>] local <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> port <span class="hljs-number">55064</span> connected to <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> port <span class="hljs-number">2526</span>
    [ ID] Interval           Transfer     Bandwidth
    [  <span class="hljs-number">4</span>]   <span class="hljs-number">0.00</span><span class="hljs-number">-5.00</span>   <span class="hljs-built_in">sec</span>  <span class="hljs-number">11.5</span> MBytes  <span class="hljs-number">19.3</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]   <span class="hljs-number">5.00</span><span class="hljs-number">-10.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">12.7</span> MBytes  <span class="hljs-number">21.4</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">10.00</span><span class="hljs-number">-15.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">12.5</span> MBytes  <span class="hljs-number">21.0</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">15.00</span><span class="hljs-number">-20.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">11.0</span> MBytes  <span class="hljs-number">18.4</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">20.00</span><span class="hljs-number">-25.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">7.38</span> MBytes  <span class="hljs-number">12.4</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">25.00</span><span class="hljs-number">-30.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">8.45</span> MBytes  <span class="hljs-number">14.2</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">30.00</span><span class="hljs-number">-35.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">6.42</span> MBytes  <span class="hljs-number">10.8</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">35.00</span><span class="hljs-number">-40.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">10.1</span> MBytes  <span class="hljs-number">17.0</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">40.00</span><span class="hljs-number">-45.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">9.53</span> MBytes  <span class="hljs-number">16.0</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">45.00</span><span class="hljs-number">-50.00</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">8.11</span> MBytes  <span class="hljs-number">13.6</span> Mbits/<span class="hljs-built_in">sec</span>                  
    [  <span class="hljs-number">4</span>]  <span class="hljs-number">50.00</span><span class="hljs-number">-51.25</span>  <span class="hljs-built_in">sec</span>  <span class="hljs-number">2.22</span> MBytes  <span class="hljs-number">14.9</span> Mbits/<span class="hljs-built_in">sec</span>                  
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bandwidth       Retr
    [  <span class="hljs-number">4</span>]   <span class="hljs-number">0.00</span><span class="hljs-number">-51.25</span>  <span class="hljs-built_in">sec</span>   <span class="hljs-number">110</span> MBytes  <span class="hljs-number">18.0</span> Mbits/<span class="hljs-built_in">sec</span>    <span class="hljs-number">0</span>             sender
    [  <span class="hljs-number">4</span>]   <span class="hljs-number">0.00</span><span class="hljs-number">-51.25</span>  <span class="hljs-built_in">sec</span>   <span class="hljs-number">102</span> MBytes  <span class="hljs-number">16.7</span> Mbits/<span class="hljs-built_in">sec</span>                  receiver
    
    iperf Done.

    0x04 TODO

    增加UDP支持

    anyShare分享到:

    VPN信息网 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明-VPN信息网-通过VMess进行SSH端口转发
    喜欢 (0)
    发表我的评论
    取消评论

    表情 贴图 加粗 删除线 居中 斜体 签到

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址