a186r avatar

在终端使用代理

a186r

Published: 14 Apr 2018 › Updated: 14 Apr 2018

在终端使用代理

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

1 安装polipo
sudo apt-get install polipo

2 编辑配置文件/etc/polipo/config

# 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 = true    
logFile = /var/log/polipo/polipo.log    
    
proxyAddress = "0.0.0.0"    
    
socksParentProxy = "127.0.0.1:1080"    
socksProxyType = socks5    
    
chunkHighMark = 50331648    
objectHighMark = 16384    
    
serverMaxSlots = 64    
serverSlots = 16    
serverSlots1 = 32

3 重启polipo服务

sudo service polipo restart    

4 设置环境变量

export http_proxy="http://127.0.0.1:8123"    
export https_proxy="https://127.0.0.1:8123"  

可添加至~/.bashrc文件中使所有shell均可实现全局SOCKS5访问,如果不添加,那么只有当前终端可使用,其他终端不能使用,添加了话,添加到最后就行.

5 检测一下是否可以通过socks5协议获取google主页面

curl www.google.com   

如果成功则说明可以访问。

6 设置开机自启

经过前面的设置后,终于大功告成!!!!!!!除了每次开机都需要输入的ssr start和sudo service polipo start(未测试已开启状态下重启计算机polipo服务是否关闭,因为反正都要设置开机自启,我就懒得测试了)

我使用的是在rc.local设置开机自启脚本.

7 创建启动脚本

先在随意地方创建一个脚本文件,我的是start_ssr_polipo.sh

sudo vim start_ssr_polipo.sh  

然后在start_ssr_polipo.sh这个文件中写入

#!/bin/bash  
echo password(你的密码) | sudo -S service polipo start  
ssr start  

然后给这个脚本执行权限

sudo chmod +x start_ssr_polipo.sh  

8 修改rc.local

在我的ubuntu18.04中,我并没有在etc下找到rc.local文件,但是可以按5.1的方法在etc下创建一个rc.local文件,我从网上找来了该文件的内容:


#!/bin/sh -e  
#  
# rc.local  
#  
# This script is executed at the end of each multiuser runlevel.  
# Make sure that the script will "exit 0" on success or any other  
# value on error.  
#  
# In order to enable or disable this script just change the execution  
# bits.  
#  
# By default this script does nothing.  
    
exit 0  

在exit 0之前添加start_ssr_polipo.sh文件的全路径

然后保存,同样要给它执行权限

sudo chmod +x rc.local   

这就ok了

Leave 在终端使用代理 to:

Written by

Read more #lixnu posts


Best Posts From a186r

We have not curated any of a186r's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From a186r