Ubuntu代理使用总结
Howard Yin 2019-11-29 01:30:02 服务器运维Linux实操网络代理
在Ubuntu系统(14.04)中里,使用代理有一种通用方式:系统设置 –> 网络 –> 网络代理 –> 应用到整个系统,这里设置的代理是全局代理,整个系统都会走这个代理设置。但一般我们不会这样使用,我们需要对我们指定的工具或软件设置代理。
# apt-get
# 全局代理
APT工具集使用的默认配置文件是/etc/apt/apt.conf,打开后发现文件默认是空文件。但是当我们设置了全局代理后,文件的内容变为:
Acquire::http::proxy "http://127.0.0.1:1080/";
Acquire::https::proxy "https://127.0.0.1:1080/";
1
2
2
# 临时代理
当只有某个或某几个包无法下载时就要用临时代理。apt-get工具可以使用-o参数来使用配置字符串,或使用-c参数使用指定配置文件。
# 使用-o选项
sudo apt-get -o Acquire::http::proxy="http://127.0.0.1:1080/" update
sudo apt-get -o Acquire::http::proxy="http://127.0.0.1:1080/" install XXX
1
2
2
# 使用-c选项
创建apt-get代理配置文件~/apt_proxy.conf,内容:
Acquire::http::proxy "http://127.0.0.1:1080/";
Acquire::https::proxy "https://127.0.0.1:1080/";
1
2
2
代理的使用命令:
sudo apt-get -c ~/apt_proxy.conf update
sudo apt-get -c ~/apt_proxy.conf install XXX
1
2
2
# 使用系统变量
如果我们设置了环境变量APT_CONFIG,那么APT工具集将使用APT_CONFIG指向的配置文件。
export APT_CONFIG=~/apt_proxy.conf
sudo apt-get update
1
2
2
# curl
# 临时普通HTTP代理
curl -x http://[user:password@]proxyhost[:port]/ -I url
1
# 临时socks5代理
curl -x socks5://[user:password@]proxyhost[:port]/ url
curl --socks5 proxyhost[:port] url
1
2
2
# 文件设置代理
编辑 ~/.curlrc 文件:
proxy = proxyhost[:port]
proxy-user = "user:password"
1
2
2
然后就可以按正常的使用方法使用curl。
# 系统变量设置代理
export http_proxy=proxyhost[:port]
export https_proxy=proxyhost[:port]
1
2
2