ssh 端口转发

文章目录 (?) [+]

    # 本地转发,正向代理,使用本地端口访问远程端口
    # <user>@<hostname> 为跳板机,不一定要和 <remote host> 一致
    ssh -L <local host>:<local port>:<remote host>:<remote port> <user>@<hostname>
    # ~/.ssh/config
    Host server
        HostName <hostname>
        User <user>
        LocalForward <local host>:<local port> <remote host>:<remote port>
    
    # 远程转发,反向代理,使用远程端口访问本地端口
    # 远程主机 /etc/ssh/sshd_config 需要设置 GatewayPorts yes 否则仅远程本地可访问
    ssh -R <remote host>:<remote port>:<local host>:<local port> <user>@<hostname>
    # ~/.ssh/config
    Host server
        HostName <hostname>
        User <user>
        RemoteForward <remote host>:<remote port> <local host>:<local port>
    
    # 动态转发,SOCKS5 代理,
    ssh -D <local host>:<local port> <user>@<hostname>
    # ~/.ssh/config
    Host server
        HostName <hostname>
        User <user>
        DynamicForward <local host>:<local port>


    远程转发配合 ssh 连接保持是个不错的临时内网穿透方案,再配合 nginx 反代是 Web 、微信公众平台测试开发的不错选择,本站使用案列:https://next.lanseyujie.com  当本地测试程序运行时,用户可以访问到本机服务。

    # -C 为压缩数据
    # -q 安静模式
    # -T 禁止远程分配终端
    # -n 关闭标准输入
    # -N 不执行远程命令
    ssh -CqTnN -R 0.0.0.0:8080:localhost:8080  ubuntu@lanseyujie.com


    本文标题:ssh 端口转发
    本文链接:https://www.lanseyujie.com/post/ssh-port-forwarding.html
    版权声明:本文使用「署名 4.0 国际」创作共享协议,转载或使用请遵守署名协议。
    点赞 0 分享 0
    下一篇:MySQL 主从复制