Linux命令行及各常用工具代理设置

Linux命令行及各常用工具代理设置

命令行代理设置

1 通过命令行指定

直接为当前命令行设置代理

  • 对当前终端的全部工具(apt、curl、wget、git 等全都有效)
  • 以下仅以 http 代理为例,如果是其他协议(如 socks 等)自行改变协议名
# 设置代理 
# export http_proxy=http://proxyAddress:port
# 如果需要账户名密码:export http_proxy=http://userName:password@proxyAddress:port
# 或者加上:export http_proxy_user=username; export http_proxy_pass=passwd
# 例如:
export https_proxy="http://127.0.0.1:7890"
export http_proxy="http://127.0.0.1:7890"

# 取消代理
unset http_proxt
unset https_proxt

测试:

curl www.google.com

2 在bashrc中指定

将上述环境变量的设置写到 ~/.bashrc 中即可。

curl设置代理

1 参数选项指定

通过 -x 参数指定代理:

curl -x 127.0.0.1:7890 https://www.google.com

2 配置文件指定

~/.curlrc 中进行设置:

echo proxy="http://127.0.0.1:5000" >> ~/.curlrc
curl www.google.com

wget代理设置

1 参数选项指定

注意这其实不是 wget 命令本身的参数选项,而相当于是在命令行上指定一个原本出现在 wgetrc 中的设置:

wget www.google.com -e "http_proxy=http://127.0.0.1:7890"

2 配置文件指定

/etc/wgetrc 中找到下列内容,按需修改为自己的代理服务器即可。

注意如果不想每次默认使用代理,可以不打开 use_proxy = on ,而是在每次命令中通过 -Y--proxy 选项为 on/off 来指定。

# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://proxy.yoyodyne.com:18023/
http_proxy = http://proxy.yoyodyne.com:18023/
ftp_proxy = http://proxy.yoyodyne.com:18023/

# If you do not want to use proxy at all, set this to off.
use_proxy = on

git代理设置

1 命令行指定

# 设置代理
git config --global https.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
git config --global http.https://github.com.proxy http://127.0.0.1:7890 # 仅对github设置代理

# 取消代理
git config --global --unset  http.proxy  
git config --global --unset  https.proxy  

2 通过配置文件指定

将代理写到配置文件 ~/.gitconfig 中,如:

[http]
    proxy = http://127.0.0.1:1080

Ref:

https://blog.csdn.net/lovedingd/article/details/118824049

https://blog.imdst.com/untitledlinuxxia-she-zhi-gitdai-li-fang-wen/

https://www.lmlphp.com/user/58209/article/item/1457465/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值