美文网首页
ssh代理设置

ssh代理设置

作者: 火星来的农民 | 来源:发表于2022-02-20 01:33 被阅读0次

    • 将所有本地127.0.0.1:2222端口数据通过root@s1.aaa.us的ssh转发到s1.aaa.us所在内网的192.168.1.20:2222端口。
    ssh -NfL 127.0.0.1:2222:192.168.1.20:2222 root@s1.aaa.us
    
    • sock5代理,本机端口2222
    ssh -NfD 127.0.0.1:2222 root@s1.aaa.us
    
    • 这个命令里面,其中 7070 是要建立加密隧道的本地一个未占用的端口,username@sshserver.com 分别指代你的 SSH 服务器的用户名和密码。

      在终端中输入这个命令,回车,然后输入密码,即可建立 SSH 端口转发了。这个命令的好处是即使你关闭了终端窗口,ssh 仍然会在后台运行,
      成功建立了一个 ssh 加密代理后,设置你的 FireFox 浏览器的 socks 代理服务器为 127.0.0.1 端口为 7070 即可绕道访问正常情况下打不开的目标网址了。

    ssh -qTfnN -D 7070 username@sshserver.com
    

    动态转发

    适用场景:在本地搭建socks5代理服务,可用于代理上网

    #[www.baidu.com] - sock5 127.0.0.1:1080 -> [SSH client] - ssh -> [SSH server 192.168.1.1] -> #[www.baidu.com]
    
    ssh -NfD 127.0.0.1:1080 root@192.168.1.1
    

    本地转发

    适用场景:在本地搭建正向代理服务,可以隐藏客户端IP

    # [mysql client] -> 127.0.0.1:2206 -> [SSH client] ->ssh-> [SSH server 192.168.1.1] ->192.168.1.2:3306-> [mysql server]
     ssh -NfL 127.0.0.1:3306:192.168.1.2:3306 root@192.168.1.1
    

    远程转发

    #[mysql client]     ********  [SSH client] - ssh -> [SSH server 192.168.1.1] -192.168.1.2:3306-> [mysql server]
    
    #修改SSH server的配置文件
    
    root@localhost:~# vim /etc/ssh/sshd_config
    GatewayPorts yes
    root@localhost:~# vim /etc/ssh/sshd_config
    ssh -NfR 1.1.1.1:3306:192.168.1.2:3306 root@192.168.1.1
    
    

    [ssh 端口映射到本地]

    
    ssh -f -N -g -L 12345:localhost:19229 root@ss -b 0.0.0.0
    
    ssh -f -N -g -L 12346:localhost:19229 root@ss -b 0.0.0.0
    
    ssh -f -N -g -L 12347:localhost:19229 root@ss -b 0.0.0.0
    
    ssh -f -N -g -L 12348:localhost:19229 root@ss -b 0.0.0.0
    
    

    1.-L选项表示本地没有远程服务器ss 19229端口提供的服务映射到本地12348的端口上,ss是远程服务器的别名,-b表示是bind绑定到本地机器网卡 ,0.0.0.0表示任何网卡

    ssh -f -N -g -R 12345:localhost:19229 root@ss -b 0.0.0.0
    
    ssh -f -N -g -R 12345:localhost:19228 root@ss -b 0.0.0.0
    
    

    2.-R表示把本地12345端口提供的服务绑定到服务器ss的19228端口,-b表示是绑定远程主机的任何网卡

    相关文章

      网友评论

          本文标题:ssh代理设置

          本文链接:https://www.haomeiwen.com/subject/ltyjlrtx.html