默认现在本机已经安装好了代理软件客户端,暴露出的 http 端口为7890,socks5 端口为7891。
因为此域名是接受过国内备案的,不易多说 🤫Linux Shell使用网络代理
当前终端使用代理
设置代理:export http_proxy=http://127.0.0.1:7890 && export https_proxy=http://127.0.0.1:7890
取消代理:unset http_proxy && unset https_proxy
全局使用代理
如果是root用户,修改/etc/profile。如果是普通用户,修改~/.bashrc。在文件最后添加如下内容
1 2 3
| export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7891
|
然后刷新配置文件:source /etc/profile
或者source ~/.bashrc
Docker使用网络代理
Docker本身使用代理(如docker pull)
1
| mkdir -p /etc/systemd/system/docker.service.d
|
添加代理
1
| vim /etc/systemd/system/docker.service.d/http-proxy.conf
|
1 2 3
| [Service] Environment="HTTP_PROXY=http://127.0.0.1:7890" Environment="HTTPS_PROXY=http://127.0.0.1:7890"
|
重启docker
1 2
| systemctl daemon-reload systemctl restart docker
|
Docker容器使用代理
- 如果是在Dockerfile中,则直接设置
1 2
| ENV http_proxy='http://127.0.0.1:7890' ENV https_proxy='http://127.0.0.1:7890'
|
- 如果是在docker run时想添加代理,则使用
-e
进行添加,如
1
| docker run -d -e http_proxy=http://127.0.0.1:7890 -e https_proxy=http://127.0.0.1:7890 image
|
Git使用网络代理
如果已经用上述 “Linux Shell使用网络代理” 配置过了,则 git 会默认使用上面配置的。如果只想单独给 git 配置代理,参考下面的方法。
- 方法一:编辑文件
编辑文件~/.gitconfig
1 2 3 4
| [https] proxy = http://127.0.0.1:7890 [http] proxy = http://127.0.0.1:7890
|
- 方法二:命令行
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git config --global http.proxy http://127.0.0.1:7890 git config --global https.proxy http://127.0.0.1:7890
git config --global http.http://github.com.proxy socks5://127.0.0.1:7891 git config --global https.https://github.com.proxy socks5://127.0.0.1:7891
git config --global http.http://github.com.proxy http://127.0.0.1:7890 git config --global https.https://github.com.proxy http://127.0.0.1:7890
git config --global --unset http.proxy git config --global --unset https.proxy
|