为 Mac Terminal 设置proxychains4代理

更好的方案

为了使用 proxychains4 需要关闭 System Integrity Protection(SIP)系统完整性保护。不少小伙伴提出这样影响系统稳定性。最近有网友提供了更好的方案。使用一下办法添加俩 alias 来开启和关闭终端代理。

.bash_profile 文件添加一下 alias:


 

1

2


 

alias setproxy="export http_proxy=http://127.0.0.1:8899; export https_proxy=$http_proxy; echo 'HTTP Proxy on';"

alias unsetproxy="unset http_proxy; unset https_proxy; echo 'HTTP Proxy off';"


 

1


 

http://127.0.0.1:8899 你的 ss 客户端本地端口

使用方法:


 

1

2

3

4


 

$ setproxy #开启代理

HTTP Proxy on

$ unsetproxy #关闭代理

HTTP Proxy off

推荐使用 PlutoX 作为 SS 客户端

SSH 隧道方法

如果没有 ss 代理,可以使用 SSH 隧道方式使用 proxychains4。


 

1


 

ssh -D 1089 remote_user@remote_host -p ssh_port

然后 proxychains4 配置文件增加 socks5 127.0.0.1 1089

安装 proxychains4

使用 shadowsocks 发现用全局模式也不能为 Terminal 设置代理,可以用一下方法为 Terminal 设置代理。


 

1


 

brew install proxychains-ng

修改配置文件


 

1


 

sudo nano /usr/local/Cellar/proxychains-ng/4.7/etc/proxychains.conf

在文件末尾添加


 

1


 

socks5 127.0.0.1 1080

其中1080为 Shadowsocks 本地端口。

用法


 

1

2


 

proxychains4 pip install shadowsocks

proxychains4 git push -u origin master

注:不知为什么代理下 ping 还是不通,但是其他命令可以正常走代理。

————————————2015-08-05 更新————————————

如果按照上述路径打开设置文件为空文件,则运行命令


 

1

2


 

$  /usr/local/bin/proxychains4 curl http://ident.me/

[proxychains] config file found: /usr/local/Cellar/proxychains-ng/4.10/etc/proxychains.conf

可以输出配置文件目录,修改配置文件后再次运行,则可以测试是否配置正确。配置正确情况下最后一行 IP 为代理服务器 IP


 

1

2

3

4

5

6


 

$ /usr/local/bin/proxychains4 curl http://ident.me/

[proxychains] config file found: /usr/local/Cellar/proxychains-ng/4.10/etc/proxychains.conf

[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.10/lib/libproxychains4.dylib

[proxychains] DLL init: proxychains-ng 4.10

[proxychains] Strict chain ... 127.0.0.1:1080 ... ifconfig.me:80 ... OK

xxx.xxx.xxx.xxx

————————————2015-08-05 更新————————————

————————————2015-10-28 更新————————————

El Capitan 支持

升级 El Capitan 后 proxychains4 没法使用了,每次提示如下


 

1

2

3

4


 

$ /usr/local/bin/proxychains4 curl http://ident.me/

[proxychains] config file found: /usr/local/Cellar/proxychains-ng/4.10/etc/proxychains.conf

[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.10/lib/libproxychains4.dylib

xxx.xxx.xxx.xxx - 真实IP

查一些资料后发现是 System Integrity Protection(SIP)系统完整性保护 导致 proxychains 无法正常运行。根据https://github.com/rofl0r/proxychains-ng/issues/78 暂时的办法就是禁用 SIP。禁用 SIP 步骤如下。

  1. 重启 Mac,按住Option键进入启动盘选择模式,再按⌘ + R进入 Recovery 模式。
  2. 实用工具(Utilities)-> 终端(Terminal)。
  3. 输入命令csrutil disable运行。
  4. 重启

————————————2015-08-05 更新————————————

————————————2016-06-12 更新————————————

优化体验

每次使用 proxychains4 命令其实有些不爽,太长容易输错。
编辑 ~/.bash_profile 文件,添加下面一行命令为 proxychains4 设置别名为 gfw 或者你喜欢的任何命令。重启终端。


 

1


 

alias gfw='proxychains4'

现在可以简化使用方式,具体为


 

1

2


 

gfw pip install shadowsocks

gfw git push -u origin master

————————————2016-06-12 更新————————————

————————————2016-11-1 更新————————————

Xcode 8 Command line tool 引起的问题

最近升级 Serria 选择了全盘格式化安装。安装完系统难免要安装各类依赖,第一不就是先安装 proxychains-ng。 不过此时进入了怪圈,需要安装 Homebrew 来安装 proxychains-ng ,但是为了安装 Homebrew 需要用 proxychains-ng 来翻墙。

还好 proxychains-ng 也可以自己手动编译,具体的 Github 上就有。

Homebrew 上最新版本已经修复了这个问题,如果有问题先卸载 proxychains-ng,再重新安装即可,不需要替换 Xcode7 的 Command Line Tool。

如果 Serria 上还有问题,按照上面 El Capitan 支持步骤重新打开 SIP,重启电脑即可

但是不管手动编译还是 Homebrew 安装安装完成后,运行 proxychains4 curl ip.cn 能正常翻墙,其他命令的报一下错误。


 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16


 

[proxychains] config file found: /usr/local/Cellar/proxychains-ng/4.11/etc/proxychains.conf

[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib

[proxychains] DLL init: proxychains-ng 4.11

[proxychains] DLL init: proxychains-ng 4.11

[proxychains] DLL init: proxychains-ng 4.11

[proxychains] DLL init: proxychains-ng 4.11

Updating spec repo `master`

[proxychains] Strict chain ... 127.0.0.1:1080 ... api.github.com:443 ... OK

$ /usr/bin/git pull --ff-only

[proxychains] DLL init: proxychains-ng 4.11

dyld: warning: could not load inserted library '/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib' into library validated process because no suitable image found. Did find:

/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib: code signing blocked mmap() of '/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib'

dyld: warning: could not load inserted library '/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib' into library validated process because no suitable image found. Did find:

/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib: code signing blocked mmap() of '/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib'

dyld: warning: could not load inserted library '/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib' into library validated process because no suitable image found. Did find:

/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib: code signing blocked mmap() of '/usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib'

研究折腾很久后,才发现 proxychains-ng 编译需要用 Xcode command line tool,然而我这里默认的 Xcode 8 的 command line tool 太新导致编译有问题。解决办法:

  1. 先删除 proxychains-ng, brew uninstall proxychains-ng
  2. 切换 command line tool 为 Xcode 7.x 版本的。sudo xcode-select -s /Applications/Xcode7.app/Contents/Developer
  3. 重新安装 proxychains-ng brew install proxychains-ng

————————————2016-11-1 更新————————————

参考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章