apt curl wget git 命令行临时设置代理

发布于:2024-07-11 ⋅ 阅读:(30) ⋅ 点赞:(0)

一、linux 代理全局设置

export http_proxy=http://192.168.6.9:8080/
export https_proxy=https://192.168.6.9:8080/ 可以
export https_proxy=http://192.168.6.9:8080/  也可以

缺点,有些工具不生效,每次要取消代理设置也麻烦



二、linux 命令行临时设置代理,推荐
apt

http proxy
sudo apt -o Acquire::http::proxy="192.168.6.9:8080/" install gcc
sudo apt -o Acquire::http::proxy="http://192.168.6.9:8080/" install gcc
https proxy
sudo apt -o Acquire::https::proxy="https://192.168.6.9:8080/" install gcc
SOCKS proxy
sudo apt -o Acquire::http::proxy="socks5h://192.168.6.9:8080/" install gcc
sudo apt -o Acquire::https::proxy="socks5h://192.168.6.9:8080/" install gcc

curl

curl -x http://192.168.6.9:8080 http://www.google.com
curl -x socks5h://192.168.6.9:8080 http://www.google.com
curl -k --proxy socks5h://192.168.6.9:8080 http://www.google.com
-x, --proxy [protocol://]host[:port] Use this proxy
-k, --insecure      Allow insecure server connections when using SSL

wget

wget -e use_proxy=yes -e http_proxy=http://192.168.6.9:8080 https://www.google.com
wget --no-check-certificate -e use_proxy=yes -e https_proxy=https://192.168.6.9:8080  https://www.google.com
wget不支持SOCKS代理,如下不行
wget -e "http_proxy=socks5h://localhost:2000"  https://google.com
wget -e "https_proxy=socks5h://localhost:2000"  https://google.com

git

export http_proxy=http://192.168.6.9:8080/
export https_proxy=http://192.168.6.9:8080/  可以
export https_proxy=https://192.168.6.9:8080/ 也可以
这样设置,git clone概率错误,需要git config https.proxy或者git config --global https.proxy

git config http.proxy 'http://192.168.6.9:8080'
git config https.proxy 'https://192.168.6.9:8080'
git config --global http.proxy 'http://192.168.6.9:8080'
git config --global https.proxy 'https://192.168.6.9:8080'

推荐下面三个
git -c http.proxy='http://192.168.6.9:8080' -c https.proxy='https://192.168.6.9:8080'  clone 

git -c http.proxy='socks5://192.168.6.9:8080' -c https.proxy='socks5://192.168.6.9:8080'  clone
git -c http.proxy='socks5h://192.168.6.9:8080' -c https.proxy='socks5h://192.168.6.9:8080' clone