GFW的日益强大,使国内的网络日益安全。不过真心苦了我们这帮程序员,要知道,看一个程序员是否优秀就看他如何使用Google。喜欢折腾的我当然是一直以优秀程序员自居,所以一定要做出些样子。这就总结了一些科学上网的小招子,望与各位想成为优秀程序员的人们共勉。

1.SSH Socks5

这是个很犀利的招式,windows怎么使用网上太多了,我就不说了,mac的用法更是简单,不过这一招并不在于怎么使用,前期攒起来才是最重要的。

原料:Mac电脑一台,openshift/koding帐号一个

1
ssh -qTfnN -D port xxx@xxx.xx.x 

打开浏览器,使用socks5代理,地址127.0.0.1:port

注:关闭步骤

1
2
lsof -i tcp:端口号
sudo kill -9 PID

此招式缺点:一小时断一次,不过别太沉迷于墙外的世界可以规避这个风险

2.SSH Socks5 + polipo 终端科学上网

为终端设置Shadowsocks代理

准备工作

配置好一个可用的shadowsocks

安装

Mac下使用Homebrew安装

1
brew install polipo

修改配置(Mac)

设置每次登陆启动polipo

1
ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents

修改文件

1
/usr/local/opt/polipo/homebrew.mxcl.polipo.plist

设置parentProxy

1
2
3
4
5
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/polipo/bin/polipo</string>
<string>socksParentProxy=localhost:1080</string>
</array>

修改的地方是增加了

1
socksParentProxy=localhost:1080

启动(Mac)

1
2
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plis

注意:请确保Shadowsocks正常工作。

验证及使用

安装完成就需要进行验证是否work。这里展示一个最简单的验证方法,打开终端,如下执行

1
2
3
4
07:56:24-androidyue/var/log$ curl ip.gs
当前 IP:125.39.112.15 来自:中国天津天津 联通
08:09:23-androidyue/var/log$ http_proxy=http://localhost:8123 curl ip.gs
当前 IP:210.140.193.128 来自:日本日本

如上所示,为某个命令设置代理,前面加上

1
http_proxy=http://localhost:8123

后接命令即可。

注:8123是polipo的默认端口,如有需要,可以修改成其他有效端口。

设置别名

bash中有一个很好的东西,就是别名alias. Linux用户修改/.bashrc,Mac用户修改/.bash_profile文件,增加如下设置

1
alias hp="http_proxy=http://localhost:8123"

然后Linux用户执行

1
source ~/.bashrc

Mac用户执行

1
source ~/.bash_profile

测试使用

1
2
3
4
5
20:39:39-androidyue~$ curl ip.gs
当前 IP:125.39.112.14 来自:中国天津天津 联通
20:39:44-androidyue~$ hp curl ip.gs
当前 IP:210.140.193.128 来自:日本日本
20:39:48-androidyue~$

当前会话全局设置

如果嫌每次为每一个命令设置代理比较麻烦,可以为当前会话设置全局的代理。即使用

1
export http_proxy=http://localhost:8123

即可。 如果想撤销当前会话的http_proxy代理,使用

1
unset http_proxy

即可。 示例效果如下

1
2
3
4
5
6
7
8
21:29:49-androidyue~$ curl ip.gs
当前 IP:125.39.112.14 来自:中国天津天津 联通
21:29:52-androidyue~$ export http_proxy=http://localhost:8123
21:30:07-androidyue~$ curl ip.gs
当前 IP:210.140.193.128 来自:日本日本
21:30:12-androidyue~$ unset http_proxy
21:30:37-androidyue~$ curl ip.gs
当前 IP:125.39.112.14 来自:中国天津天津 联通

如果想要更长久的设置代理,可以将

1
export http_proxy=http://localhost:8123

加入

1
.bashrc

或者

1
.bash_profile

设置Git代理

复杂一些的设置Git代理

1
2
3
4
5
6
7
8
git clone https://android.googlesource.com/tools/repo --config http.proxy=localhost:8123

Cloning into 'repo'...
remote: Counting objects: 135, done
remote: Finding sources: 100% (135/135)
remote: Total 3483 (delta 1956), reused 3483 (delta 1956)
Receiving objects: 100% (3483/3483), 2.63 MiB | 492 KiB/s, done.
Resolving deltas: 100% (1956/1956), done.

其实这样还是比较复杂,因为需要记忆的东西比较多,下面是一个更简单的实现

首先,在

1
.bashrc

或者

1
.bash_profile

文件加入这一句

1
gp=" --config http.proxy=localhost:8123"

然后执行source操作,更新当前bash配置。

更简单的使用git的方法

1
2
3
4
5
6
7
8
git clone  https://android.googlesource.com/tools/repo $gp

Cloning into 'repo'...
remote: Counting objects: 135, done
remote: Finding sources: 100% (135/135)
remote: Total 3483 (delta 1956), reused 3483 (delta 1956)
Receiving objects: 100% (3483/3483), 2.63 MiB | 483 KiB/s, done.
Resolving deltas: 100% (1956/1956), done.

3. SSH Socks5 + proxychains安装 终端科学上网

proxychains安装

1
2
3
4
5
6
git clone https://github.com/rofl0r/proxychains-ng.git
cd proxychains-ng
./configure
make && make install
cp ./src/proxychains.conf /etc/proxychains.conf
cd .. && rm -rf proxychains-ng

编辑proxychains配置

1
vim /etc/proxychains.conf

1
socks4 127.0.0.1 9095

改为

1
socks5 127.0.0.1 1080

,1080改为你自己的端口

使用方法

在需要代理的命令前加上proxychains4 ,如:

1
proxychains4 curl ip.gs

未完待续~~~