在文件 .bashrc 中添加 export http_proxy="proxy IP:port"
如 export http_proxy="192.168.0.1:8080"
export https_proxy="192.168.0.1:8080"
在/etc/profile文件里写入:
export http_proxy=username:password@ip:port
https://github.com/z3APA3A/3proxy
https://github.com/isayme/socks5
https://github.com/lparam/xSocks
二、linux bash为http站点设置代理:
根据代理类型,将下面对应的设置项添加到~/.bashrc文件末尾,然后运行". ~/.bashrc"(前面是一个“.”号)命令使用之在当前环境生效。
1、为http站点设置http代理(默认):
export http_proxy=10.0.0.52:8080 |
1
2
3
4
5
6
|
# 设置 socks 代理,自动识别socks版本 export http_proxy=socks: //10 .0.0.52:1080 # 设置 socks4 代理 export http_proxy=socks4: //10 .0.0.52:1080 # 设置 socks5 代理 export http_proxy=socks5: //10 .0.0.52:1080 |
1
|
export http_proxy=user:pass@192.158.8.8:8080 |
三、linux bash为https站点设置代理:
如果需要为https网站设置代理,设置https_proxy环境变量即可;设置方法完全与http_proxy环境变量相同:
1
2
3
4
5
6
|
# 任意使用一项 export https_proxy=10.0.0.52:8080 export https_proxy=user:pass@192.158.8.8:8080 export https_proxy=socks: //10 .0.0.52:1080 export https_proxy=socks4: //10 .0.0.52:1080 export https_proxy=socks5: //10 .0.0.52:1080 |
四、举例:
现在我们要设置http、https网站都使用socks5代理10.0.0.52:1080,下面为完整设置方法:1、vim ~/.bashrc,在文件尾部添加下面内容:
1
2
3
|
export http_proxy=socks5: //10 .0.0.52:1080 export https_proxy=socks5: //10 .0.0.52:1080 export no_proxy= "*.aiezu.com,10.*.*.*,192.168.*.*,*.local,localhost,127.0.0.1" |
1
2
3
4
5
|
[root@aiezu.com ~] # . ~/.bashrc [root@aiezu.com ~] # echo $http_proxy socks5: //10 .0.0.52:1080 [root@aiezu.com ~] # echo $https_proxy socks5: //10 .0.0.52:1080 |
1
2
3
4
5
6
7
8
9
10
|
[root@aiezu.com ~] # curl -I http://www.fackbook.com HTTP /1 .1 200 OK Content-Length: 2423 Content-Type: text /html Last-Modified: Mon, 14 Nov 2016 22:03:32 GMT Accept-Ranges: bytes ETag: "0521af0c23ed21:0" Server: Microsoft-IIS /7 .5 X-Powered-By: ASP.NET Date: Sun, 11 Dec 2016 13:21:33 GMT |