MAC linux Windws代理
macOS & Linux
通过设置http_proxy
、https_proxy
,可以让终端走指定的代理。
配置脚本如下,在终端直接执行,只会临时生效:
export https_proxy=http://127.0.0.1:12333
export http_proxy=http://127.0.0.1:12333
export all_proxy=http://127.0.0.1:1087
export https_proxy=http://127.0.0.1:1087
export https_proxy=$http_proxy
1080
是http
代理对应的端口,根据你的实际情况修改。
你可以在Sh的设置界面中查找代理端口信息。
便捷脚本
这里提供一个便捷脚本,里面包含打开、关闭功能:
function proxy_on() {
export http_proxy=http://127.0.0.1:1080
export https_proxy=$http_proxy
echo -e "终端代理已开启。"
}
function proxy_off(){
unset http_proxy https_proxy
echo -e "终端代理已关闭。"
}
通过proxy_on
启动代理,proxy_off
关闭代理。
接下来需要把脚本写入.bash_profile
或.zprofile
,这样就可以永久生效。
你可能会问,怎么写入脚本,耐心点,下文提供了安装脚本的方法。
至于你应该写入哪个文件,请根据命令echo $SHELL
返回结果判断:
/bin/bash
=>.bash_profile
/bin/zsh
=>.zprofile
然后执行安装脚本(追加内容+生效),注意一定根据要上面结果修改.zprofile
名称:
cat > ~/.zprofile << EOF
function proxy_on() {
export http_proxy=http://127.0.0.1:1080
export https_proxy=$http_proxy
echo -e "终端代理已开启。"
}
function proxy_off(){
unset http_proxy https_proxy
echo -e "终端代理已关闭。"
}
EOF
source ~/.zprofile
可以执行curl cip.cc
验证:
IP : xxx
地址 : 中国 台湾 台北市
运营商 : cht.com.tw
数据二 : 台湾省 | 中华电信(HiNet)数据中心
数据三 : 中国台湾 | 中华电信
URL : http://www.cip.cc/xxx
看到网上说通过curl -I http://www.google.com
可能会遇到403
问题,使用Google
域名验证时需要注意下这个情况。
Windows
根据网上的文章,在Windows
下使用全局代理方式也会对cmd
生效(未经验证)。
cmd
set http_proxy=http://127.0.0.1:1080
set https_proxy=http://127.0.0.1:1080
还原命令:
set http_proxy=
set https_proxy=
Git Bash
设置方法同"macOS & Linux"
PowerShell
$env:http_proxy="http://127.0.0.1:1080"
$env:https_proxy="http://127.0.0.1:1080"
还原命令(未验证):
$env:http_proxy=""
$env:https_proxy=""
其他代理设置
git代理
# 设置
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1089'
# 恢复
git config --global --unset http.proxy
git config --global --unset https.proxy
npm
# 设置
npm config set proxy http://server:port
npm config set https-proxy http://server:port
# 恢复
npm config delete proxy
npm config delete https-proxy
git clone ssh 如何走代理
macOS
打开~/.ssh/config
,如果没有这个文件,自己手动创建。
# 全局
# ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
# 只为特定域名设定
Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
Windows
打开C:\Users\UserName\.ssh\config
文件,没有看到的话,同样手动创建。
# 全局
# ProxyCommand connect -S 127.0.0.1:1080 %h %p
# 只为特定域名设定
Host github.com
ProxyCommand connect -S 127.0.0.1:6600 %h %p
posted on 2022-08-11 13:11 Ra7ing安全实验室 阅读(148) 评论(0) 编辑 收藏 举报