搭桥笔记

搭桥记录一下

Ubuntu下访问问题

搭建好ss + SwitchOmega即可使用浏览器访问google,但无法在终端或者git中访问外网,这里记录一下配置过程。

安装协议转换器

ss无法在终端上面进行科学上网主要是协议问题,原因如下

Shadowsocks是一个使用SOCKS5(或者SOCK4之类)协议的代理,它只接受SOCKS5协议的流量,不接受HTTP或者HTTPS的流量。所以当你在Chrome上能穿墙的时候,是Proxy SwitchyOmega插件把HTTP和HTTPS流量转换成了SOCKS协议的流量,才实现了Shadowsocks的代理。而终端是没有这样的协议转换的,所以没法直接使用Shadowsock进行代理。

此时可安装Polipo进行协议的转换

sudo apt-get install polipo

修改配置文件

vim /etc/polipo/config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# This file only needs to list configuration variables that deviate
# from the default values. See /usr/share/doc/polipo/examples/config.sample
# and "polipo -v" for variables you can tweak and further information.
logSyslog = false
logFile = "/var/log/polipo/polipo.log"

socksParentProxy = "127.0.0.1:1080"
socksProxyType = socks5

chunkHighMark = 50331648
objectHighMark = 16384

serverMaxSlots = 64
serverSlots = 16
serverSlots1 = 32

proxyAddress = "0.0.0.0"
proxyPort = 8123

重启poplipo服务

sudo /etc/init.d/polipo restart

配置http代理

export http_proxy="http://127.0.0.0:8123"

export https_proxy="http://127.0.0.0:8123"

测试能否科学上网

curl www.google.com

git 走代理

就算git仓库走的是https协议,下面这个配置也能生效,而https.proxy却不能生效。

git config --global http.proxy "localhost:8123"

go走代理

查看帮助

go help goproxy

得知走代理

export GOPROXY=localhost:8123

设置走直接连接

export GOPROXY=direct

一个非常方便的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#shadowsocks.sh

if [[ $# -eq 0 ]]; then
echo "usage:"
echo "$0 start : start ss"
echo "$0 stop : stop ss"
echo "$0 restart : restart ss"
echo "more usages:sslocal -h"
echo "-all : google with Terminal"
exit -1
fi

sudo sslocal -c /etc/shadowsocks/shadowsocks.json -d $1
if [[ "$2" == "-all" ]]; then
echo "$2"
echo "polipo $1"
export http_proxy="http://127.0.0.1:8123"
export https_proxy="http://127.0.0.1:8123"
export GOPROXY=http://127.0.0.1:8123
git config --global http.proxy "http://127.0.0.1:8123"
git config --global https.proxy "http://127.0.0.1:8123"
sudo /etc/init.d/polipo $1
else
export GOPROXY=direct
unset http_proxy
unset https_proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
sudo /etc/init.d/polipo stop
fi

echo "shadowsocks shell run finish!"

执行source shadowsocks.sh start -all`

参考文献

奶爸的天空