Bash终端命令行,使用privoxy将socks代理转成http代理

安装privoxy

# Ubuntu/debian
sudo apt-get install privoxy

# Centos
sudo yum install privoxy

# Mac osx
sudo port install privoxy

修改配置文件

vi /etc/privoxy/config

#      HTTP parent looks like this:
#
       forward-socks4   /               127.0.0.1:1080  .
#
#      To chain Privoxy and Tor, both running on the same system, you
#      would use something like:
#
       forward-socks5   /               127.0.0.1:1080 .

主要是forward-socks 这两行,1080是socks代理开启的端口,根据自己实际情况修改

配置完成后,重启privoxy,sudo service privoxy restart

添加代理开关函数

vi ~/.bashrc,添加如下代码:

function proxy_off(){
    unset http_proxy
    unset https_proxy
    unset ftp_proxy
    unset rsync_proxy
    echo -e "已关闭代理"
}

function proxy_on() {
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    export http_proxy="http://127.0.0.1:8118"
    export https_proxy=$http_proxy
    export ftp_proxy=$http_proxy
    export rsync_proxy=$http_proxy
    export HTTP_PROXY=$http_proxy
    export HTTPS_PROXY=$http_proxy
    export FTP_PROXY=$http_proxy
    export RSYNC_PROXY=$http_proxy
    echo -e "已开启代理"
}

使用的时候,需要开启http代理时,就在命令行输入:proxy_on

此种情况多数用于命令行需要链接的服务器,被墙需要扶梯子时,比如下载android源码,chromium源码 …

留言