Linux 设置代理集合 apt yum wget curl git pip 设置代理 使用代理服务器

apt-get 使用代理

仅为apt-get设置代理服务器
添加/etc/apt/文件夹下的apt.conf文件,默认不存在
sudo gedit /etc/apt/apt.conf在的apt.conf文件中加入下面这行。

1
2
3
4
#Acquire::http::Proxy "http://proxyusr:password@yourproxyaddress:proxyport";
Acquire::http::Proxy "http://10.1.249.61:3128";
Acquire::ftp::proxy "ftp://10.1.249.61:3128";
Acquire::https::proxy "https://10.1.249.61:3128";

根据实际情况替换 用户名:密码@地址和端口号。
==注意符号不要少写(不要丢了最后的一个分号)。==

YUM 使用代理

编辑/etc/yum.conf,在最后加入

1
2
# Proxy
proxy=http://username:password@proxy_ip:port/

YUM update不更新内核
修改yum的配置文件 vim /etc/yum.conf,在 [main] 的最后添加 exclude=kernel*

wget 使用代理

编辑/etc/wgetrc,在最后加入

1
2
3
# Proxy
http_proxy=http://username:password@proxy_ip:port/
ftp_proxy=http://username:password@proxy_ip:port/

当前用户永久生效:
创建$HOME/.wgetrc文件,加入以下内容:

1
http_proxy=IP:Port

临时使用:

1
$wget -e "http_proxy=http://[IP:Port]" www.google.com

bash/shell 使用代理

1
2
3
4
export proxy="http://10.20.56.32:8000"
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy

取消代理

1
2
export no_proxy="localhost, 127.0.0.1, ::1"
export all_proxy="http://10.20.56.32:8000"

Git 使用代理

1
2
git config --global http.proxy 10.167.32.133:8080
git config --global https.proxy 10.167.32.133:8080

取消代理

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

pip 使用代理

1
pip install -r requirements.txt --proxy=[IP:Port]

curl 使用代理

1
2
3
4
5
6
# 指定http代理IP和端口
curl -x 113.185.19.192:80 http://baidu.com
curl --proxy 113.185.19.192:80 http://baidu.com
curl -x http_proxy://113.185.19.192:80 http://baidu.com
curl -x https_proxy://113.185.19.192:80 http://baidu.com
curl -x 113.185.19.192:80 --proxy-user aiezu:123456 http://baidu.com

Windows cmd 使用代理

1
2
3
4
5
6
7
8
9
10
11
12
# 使用 http 类型代理
set http_proxy=http://127.0.0.1:8484
set https_proxy=http://127.0.0.1:8484

# 使用 socks 类型代理
netsh winhttp set proxy proxy-server="socks=127.0.0.1:8484" bypass-list="localhost"
netsh winhttp show proxy
netsh winhttp reset proxy

# 使用 socks 类型代理
set http_proxy=socks5://127.0.0.1:8484
set https_proxy=socks5://127.0.0.1:8484