Mac 为终端设置代理

释放双眼,带上耳机,听听看~!
🤖 由 ChatGPT 生成的文章摘要

这里我使用ClashX当做代理

首先我们需要确保浏览器可以正常访问

其次复制proxy
Mac 为终端设置代理

接下来我们打开iTerm

iTerm主要使用.zshrc为环境变量,我们.zshrc主要是引用脚本文件

  • 编辑bash_profile文件,创建脚本
➜  ~ vim .bash_profile
#添加下面内容
function proxy_off(){
        unset no_proxy
        unset all_proxy
        unset HTTP_PROXY
        unset HTTPS_PROXY
        unset FTP_PROXY
        unset RSYNC_PROXY
    unset https_proxy
    unset http_proxy
    unset ftp_proxy
    unset rsync_proxy
        echo -e "已关闭代理"
        curl cip.cc
}

function proxy_on() {
        export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
        export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
        export ftp_proxy=$http_proxy
        export rsync_proxy=$http_proxy
        export HTTP_PROXY=$http_proxy
        export HTTPS_PROXY=$http_proxy
        export FTP_PROXY=$http_proxy
        export RSYNC_PROXY=$http_proxy
        echo -e "已开启代理"
        echo -e "当前IP:" && curl ip.sb
}

编辑家目录下 .zshrc文件

source /Users/yuhong.cong/.bash_profile

#脚本默认为加目录下,可以 通过下面的命令查看家目录路径
➜  ~ pwd
/Users/yuhong.cong
➜  ~

添加完毕 后 打开新的窗口

开启proxy

➜  ~ proxy_on
已开启代理
13.250.38.250

此时可以测试Google和github是否可以正常通信

➜  ~ curl google.com -I
HTTP/1.1 301 Moved Permanently
Content-Length: 219
Cache-Control: public, max-age=2592000
Connection: keep-alive
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-Mp0HoLpVZw9AaEMFG368Dg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=UTF-8
Date: Mon, 30 Oct 2023 03:11:58 GMT
Expires: Wed, 29 Nov 2023 03:11:58 GMT
Keep-Alive: timeout=4
Location: http://www.google.com/
Proxy-Connection: keep-alive
Server: gws
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

➜  ~ curl github.com -I
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Keep-Alive: timeout=4
Location: https://github.com/
Proxy-Connection: keep-alive
Content-Length: 0

关闭代理

➜  ~ proxy_off
已关闭代理
IP  : 111.x.x.x
地址  : 中国  北京
运营商 : 联通

数据二 : 北京市 | 联通

数据三 : 中国北京北京市 | 联通

URL : http://www.cip.cc/111.x.x.x

给TA打赏
共{{data.count}}人
人已打赏
Mac

MAC接入PC键盘后如何正常使用command等功能键

2022-10-11 11:00:06

prometheus

Prometheus Operator 修改数据存储时间

2020-4-23 13:47:23

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索