美文网首页cocoapods相关
mac快速设置终端代理

mac快速设置终端代理

作者: sky_kYU | 来源:发表于2019-10-29 15:47 被阅读0次

    有时候需要频繁的切换终端代理,可以试用以下操作,快捷方便的开关代理。

    • 在~/.bash_profile 文件中,添加如下代码:
    function proxy_off(){
            unset http_proxy
            unset https_proxy
            unset ftp_proxy
            unset rsync_proxy
            echo -e "已关闭代理"
    }
     
    function proxy_on() {
            export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
            export http_proxy="http://127.0.0.1:1087"#注意,根据自己的配置设置有可能会是1080或1086
            export https_proxy=$http_proxy
            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 "已开启代理"
    }
    
    • 执行source ~/.bash_profile,使其立刻生效。
    • 需要使用代理时开启ss全局模式,然后打开终端,输入proxy_on就会启动。如果需要关闭,只需要输入proxy_off。

      如果出现 command not found: XX先执行source ~/.bash_profile,再执行XX。

    • 判断终端是否走了代理服务器的方法

      curl cip.cc
      对比下设置前后是否有区别

    • ps,该设置仅对当前终端窗口生效,关闭窗口,下次需要在设置一次proxy_on

    相关文章

      网友评论

        本文标题:mac快速设置终端代理

        本文链接:https://www.haomeiwen.com/subject/xihgvctx.html