Use proxy in linux

0x01 Make it work

  1. wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py
  2. pip install shadowsocks
  3. sslocal -s your-ss-ip -p 443 -k "your-ss-code" -l 1080 -m aes-256-cfb --user nobody -d start
  4. curl --socks5 127.0.0.1:1080 ip.cn
  5. yum -y install privoxy
  6. service privoxy start
  7. cp /etc/privoxy/config /etc/privoxy/config_bak
  8. vim /etc/privoxy/configensure below lines are not commented, line1 usually not, line2 need modify
     listen-address 127.0.0.1:8118 
     forward-socks5t / 127.0.0.1:1080 . 
    
  9. run below in bash
     export http_proxy=http://127.0.0.1:8118
     export https_proxy=http://127.0.0.1:8118
    
  10. chkconfig privoxy on && service privoxy start
  11. curl ipinfo.io

0x02 Be elegant

  1. CentOS install
     yum -y install privoxy pip -y
     pip install shadowsocks
     cp /etc/privoxy/config /etc/privoxy/config_bak
    

    Ubuntu install

     sudo apt install python-pip git privoxy -y
     pip install -U git+https://github.com/shadowsocks/shadowsocks.git@master
     cp /etc/privoxy/config /etc/privoxy/config_bak
    
  2. vim /etc/privoxy/config uncomment below line
     forward-socks5t / 127.0.0.1:9050 . 
    
  3. save below code to a file like setproxy , then . setproxy on means open,. setproxy off means shutdown
     #!/bin/bash
    
     ip=1.1.1.1
     port=11111
     key=123456
    
     if [ "$1" == "on" ]; then
         sslocal -s $ip -p $port -k $key -l 9050 -m aes-256-cfb --user nobody -d start
         service privoxy start
         export http_proxy=http://127.0.0.1:8118
         export https_proxy=http://127.0.0.1:8118
     elif [ "$1" == "off" ]; then
         sslocal -s $ip -d stop
         service privoxy stop
         export http_proxy=""
         export https_proxy=""
     elif [ "$1" == "status" ]; then
         service privoxy status
     elif [ "$1" == "log" ]; then
         tail -f /var/log/shadowsocks.log
     elif [ "$1" == "test" ]; then
         sslocal -s $ip -p $port -k $key -l 9050 -m aes-256-cfb
    
     else
         echo 'Please input argument: on,off,status'
     fi
     echo 'Now your ip is: '
     curl ipinfo.io
     echo ''
    

0x03 Another host comes

An image that the stream flow:

  • Listen: ss-server[socks 1080] –> privoxy(forward-socks5t[socks 1080]>listen-address[http,https 8118])
  • Request: application, like curl –> localhost[http,https 8118]

Now comes another machine: C (A is ss-server, B is ss-client configured as 0x02), let C join the play:

  1. on B, change listen-address 127.0.0.1:8118 to listen-address 0.0.0.0:8118 in /etc/privoxy/config
  2. on C, run export http_proxy=http://127.0.0.1:8118; export https_proxy=http://127.0.0.1:8118, or make a proxy_switch.sh:
     #!/bin/bash
     if [ "$1" == "on" ]; then
             export http_proxy=http://B_ip:8118
             export https_proxy=http://B_ip:8118
         echo 'http and https proxy has set to B_ip:8118'
             curl ipinfo.io
     elif [ "$1" == "off" ]; then
             export http_proxy=""
             export https_proxy=""
         echo 'http and https proxy OFF'
     else
         echo 'http_proxy:'
         echo $http_proxy
         echo 'https_proxy'
         echo $https_proxy
             echo 'Please input argument: on,off'
     fi
    	
    
  3. run . proxy_swtich.sh on to enjoy C ~