Shadowsocks实现Mac下Terminal翻墙

//Terminal下运用Shadowshocks
//Shadowshocks使用的协议是socks5,而目前很多终端软件只支持http和https协议

mac
Shadowshocks-NG-R8 iTerm2

Shadowsocks

  1. 安装
    下载最新版Shadowsocks-NG-R8,直接安装。

  2. 获取Shadowsocks监听端口,可以在Advance Preferences中获取,笔者的为1086端口,如下图。

polipo

  1. 安装polipo

    brew install polipo 输入polipo直接启动 or polipo &在后台启动,在浏览器中键入http://localhost:8123/可以访问相关polipo信息。

  2. 修改配置文件/usr/local/opt/polipo/homebrew.mxcl.polipo.plist,添加socksParentProxy
    添加一行<string>socksParentProxy=localhost:1086</string>到plist中,其中localhost:10086为上一步获取的Shadowshocks的监听端口。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
     <key>Label</key>
     <string>homebrew.mxcl.polipo</string>
     <key>RunAtLoad</key>
     <true/>
     <key>KeepAlive</key>
     <true/>
     <key>ProgramArguments</key>
     <array>
       <string>/usr/local/opt/polipo/bin/polipo</string>
       <string>socksParentProxy=localhost:1086</string>
     </array>
     <!-- Set `ulimit -n 65536`. The default macOS limit is 256, that's
          not enough for Polipo (displays 'too many files open' errors).
          It seems like you have no reason to lower this limit
          (and unlikely will want to raise it). -->
     <key>SoftResourceLimits</key>
     <dict>
       <key>NumberOfFiles</key>
       <integer>65536</integer>
     </dict>
    </dict>
    </plist>
    
  3. 重启polipo

    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plis
    
  4. 将polipo设置为开机启动

    ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents
    
  5. 使用
    到此,polipo可以直接使用。在终端输入http_proxy=http://localhost:8123 curl ip.gs`
    因为笔者使用的是香港的代理,当前城市已经定位到香港

    需要注意的是,此时如果不生效的话,重启一下Terminal or 电脑可能会收获奇效。

    为了方便使用,不用每次都输入http_proxy=http://localhost:8123,可以将这个变量添加到~/.bash_profile中。然后上面的测试就变成了curl ip.gs

    export http_proxy=http://localhost:8123
    export https_proxy=http://localhost:8123
    
  6. 为git配置代理

    git config --global http.proxy 'socks5://127.0.0.1:1080'
    

    cat ~/.gitconfig查看是否添加成功.

    [http]
     proxy = socks5://127.0.0.1:1086
    

附件

Convert Shadowsocks into an HTTP proxy 为终端设置Shadowsocks代理
Setting Up HTTP Proxy in Terminal

results matching ""

    No results matching ""