ubuntu-连接ssr的socks5代理

ubuntu-连接ssr的socks5代理


前篇

所有 命令 连接某个机子上的 ssr 的 socks5 请求外网. 需要用到 proxychains-ng: https://github.com/rofl0r/proxychains-ng.git


前置物料

开启机子A ( 192.168.1.200 ) 的 ssr socks5, 端口: 10088


使用流程

参考: ubuntu下安装proxychains - https://blog.csdn.net/lazybones_3/article/details/85129470

  1. 下载源码包

    1
    $ git clone https://github.com/rofl0r/proxychains-ng.git
  2. 编译生成

    1
    2
    3
    4
    $ cd proxychains-ng/ // cd 进去编译生成
    $ ./configure --prefix=/usr --sysconfdir=/etc
    $ make && make install
    $ make install-config // 创建配置文件
    • 如果命令报错: make: cc: Command not found , 需要安装编译工具

      1
      2
      $ apt install make
      $ apt install gcc
  3. 修改配置

    1
    2
    3
    $ vi /etc/proxychains.conf
    // 最后一行, 修改 socks4 为目标机子的ssr端口
    socks5 192.168.1.200 10088
  4. 测试一下, 只要命令带上 proxychains4 就可以走代理

    • 测试 ping 一下 google

      1
      2
      3
      4
      5
      6
      7
      8
          $ proxychains4 ping google.com
      [proxychains] config file found: /etc/proxychains.conf
      [proxychains] preloading /usr/lib/libproxychains4.so
      [proxychains] DLL init: proxychains-ng 4.14-git-8-gb8fa2a7
      PING google.com (224.0.0.1) 56(84) bytes of data.
      64 bytes from 192.168.1.155 (192.168.1.155): icmp_seq=1 ttl=64 time=0.443 ms // 有回复
      64 bytes from 192.168.1.155 (192.168.1.155): icmp_seq=2 ttl=64 time=0.230 ms
      64 bytes from 192.168.1.155 (192.168.1.155): icmp_seq=3 ttl=64 time=0.268 ms
    • 测试 拉 GitHub 代码

  5. proxychains4 加个别名, 方便使用

    1
    2
    3
    4
    5
    $ vi ~/.bash_profile

    alias pc='proxychains4' # 添加别名

    $ source ~/.bash_profile // 使其生效

    done

    1
    2
    3
    4
    5
    6
    7
    root@ubuntu:~# pc ping google.com
    [proxychains] config file found: /etc/proxychains.conf
    [proxychains] preloading /usr/lib/libproxychains4.so
    [proxychains] DLL init: proxychains-ng 4.14-git-8-gb8fa2a7
    PING google.com (224.0.0.1) 56(84) bytes of data.
    64 bytes from 192.168.1.155 (192.168.1.155): icmp_seq=1 ttl=64 time=0.287 ms
    64 bytes from 192.168.1.155 (192.168.1.155): icmp_seq=2 ttl=64 time=0.150 ms

设置所有 http 请求都走代理

添加一个环境变量 ALL_PROXY 即可, 指定 socks 的地址端口

1
$ export ALL_PROXY=socks5://127.0.0.1:10088

然后测试一下

1
2
$ curl https://www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="zh-HK"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="CoJYPpJBh1wCiSWxL32mLQ==">(function(){window.google={kEI:'_U9LX4uYJtvmwQOby5m4DA',kEXPI:'0,202130,32,1151584,5663,731,223,5104,207,3204,10,1226,364,1499,611,206,383,2

设置所有 tcp 请求都走代理