国外有很多优质资源,但国内的外网访问体验一向不好。不少内容因为国外服务器距离远而下载慢,甚至有的直接无法在国内访问,而在 Linux 下,很多优秀工具或网站都是外国人开发的,问题则尤为明显,这个时候如果能通过国外的代理网络访问可以大幅提高访问速度。

很多命令都提供自带的代理网络配置方法,可以在使用命令时直接配置参数,甚至有一些工具可以设置全局参数,这样就不用每次使用都要添加代理配置。当然了,也有一些命令暂时没有配置网络代理的功能,那么就可以通过第三方工具,例如 proxy4chains,单独为此次命令运行配置代理网络环境。

apt

临时使用

BASH
1sudo apt-get -o Acquire::http::proxy="http://127.0.0.1:8000/" update

特定源代理

BASH
1echo \
2'Acquire::https::Proxy::download.sublimetext.com "http://127.0.0.1:10801/";
3Acquire::http::Proxy::download.mono-project.com "http://127.0.0.1:10801/";
4Acquire::https::Proxy::typora.io "http://127.0.0.1:10801/";' \
5| sudo tee -a /etc/apt/apt.conf.d/10proxy

全部走代理

BASH
1echo 'Acquire::http::Proxy "http://127.0.0.1:10801";
2Acquire::https::Proxy "http://127.0.0.1:10801";' | sudo tee /etc/apt/apt.conf.d/proxy.conf

git

设置

BASH
1git config --global https.proxy http://127.0.0.1:10801
2git config --global http.proxy http://127.0.0.1:10801

查看

BASH
1git config --global --get https.proxy
2git config --global --get https.proxy

取消

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

npm

设置代理

BASH
1npm config set proxy http://127.0.0.1:10801
2npm config set proxy http://127.0.0.1:10801

取消代理

BASH
1npm config delete proxy
2npm config delete https-proxy

切换淘宝源

BASH
1npm config set registry https://registry.npm.taobao.org

换回官方仓库

BASH
1npm config set registry https://registry.npmjs.org/

INFO 使用淘宝源有时会遇到 npm ERR! Cannot read properties of null (reading 'pickAlgorithm'),切换回官方源即可

yarn

设置

BASH
1yarn config set proxy http://127.0.0.1:10801
2yarn confit set https-proxy http://127.0.0.1:10801

查看

BASH
1yarn config list

取消

BASH
1yarn config delete proxy
2yarn config delete https-proxy

切换淘宝源

BASH
1yarn config set registry https://registry.npm.taobao.org

wget

wget本身没有专门设置代理的命令行参数,但是有一个"-e"参数,可以在命令行上指定一个原本出现在".wgetrc"中的设置

BASH
1# 针对 https 资源
2wget -e "https_proxy=http://127.0.0.1:10801"
3
4# 针对 http 资源
5wget -e "http_proxy=http://127.0.0.1:10801"

也可以直接通过 export https_proxy=socks5://127.0.0.1:10800; wget 链接 的方式

Go

临时

BASH
1export GOPROXY=https://goproxy.io,direct

永久

BASH
1go env -w GOPROXY=https://goproxy.io,direct

或设置系统代理

BASH
1export http_proxy=http://127.0.0.1:10801
2export https_proxy=http://127.0.0.1:10801

Curl

临时

BASH
1curl -x socks5://127.0.0.1:10800 $url

永久

BASH
1echo 'socks5 = "127.0.0.1:10800"' >> ~/.curlrc

临时不用

BASH
1curl --noproxy "*" $url