linux 使用sh@d0ws0cks client

Linux Centos7下安装使用Shadowsocks客户端,实现科学上网


准备

  • SS: 搭建一个可以连接外网的服务器 教程可见 自己动手搭梯子
  • 服务器:本人用的腾讯云服务器,系统为Centos7

开始

安装epel源、安装pip包管理、安装Shadowsocks客户端

1 sudo yum install epel-release
2 sudo yum install python-pip
3 sudo pip install shadowsocks

若执行sudo pip install shadowsocks提示:
You are using pip version 8.1.2, however version 18.1 is available.
You should consider upgrading via the ‘pip install --upgrade pip’ command.
请执行 pip install --upgrade pip

配置Shadowsocks客户端


新建客户端配置文件

1 sudo mkdir /etc/shadowsocks
2 sudo vi /etc/shadowsocks/shadowsocks.json

配置信息如下

{
        "server": "x.x.x.x", 
        "server_port": 1035, 
        "local_address": "127.0.0.1", 
        "local_port": 1080, 
        "password": "password", 
        "timeout": 300, 
        "method": "aes-256-cfb", 
        "fast_open": false, 
        "workers": 1
}

[server]     提供ss服务的服务器的ip地址
[server_port]   提供ss服务的服务器的端口号
[local_address]  本地地址
[local_host]   本地监听端口
[password]    ss连接密码
[method]    加密方式

 

 

配置开机自启动

新建/etc/systemd/system/shadowsocks.service文件命令如下:

sudo vim /etc/systemd/system/shadowsocks.service

文件内容如下

[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/sslocal -c /etc/shadowsocks/shadowsocks.json
[Install]
WantedBy=multi-user.target

 

文件创建完成后,依次执行如下命令:

systemctl enable shadowsocks.service
systemctl start shadowsocks.service
systemctl status shadowsocks.service

 

检查Shadowsocks是否正常运行

curl --socks5 127.0.0.1:1080 http://httpbin.org/ip

客户端运行正常则展示结果为:
{
“origin”: “x.x.x.x” #ss服务器IP
}

 

privoxy
安装privoxy

yum install privoxy -y
systemctl enable privoxy
systemctl start privoxy
systemctl status privoxy

 


配置privoxy

sudo vim /etc/privoxy/config

listen-address 127.0.0.1:8118   # 8118 是默认端口,不用改
forward-socks5t / 127.0.0.1:1080 . #转发到本地端口,注意最后有个点

设置http、https请求代理
sudo vim /etc/profile 修改环境变量

PROXY_HOST=127.0.0.1
export all_proxy=http://$PROXY_HOST:8118
export ftp_proxy=http://$PROXY_HOST:8118
export http_proxy=http://$PROXY_HOST:8118
export https_proxy=http://$PROXY_HOST:8118
export no_proxy=localhost,172.16.0.0/16,192.168.0.0/16.,127.0.0.1,10.10.0.0/16

 

source /etc/profile 使更新的环境变量生效

测试代理是否生效
curl -I www.google.com

返回如下结果,代理配置成功

HTTP/1.1 200 OK
Date: Thu, 03 Jan 2019 15:38:03 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP=“This is not a P3P policy! See g.co/p3phelp for more info.”
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2019-01-03-15; expires=Sat, 02-Feb-2019 15:38:03 GMT; path=/; domain=.google.com
Set-Cookie: NID=154=NxAhlbgz2a6wLNsxGp7leyPoUWSwbbVLu-K-8sbIqgVX27XWn6VTlo-pkU51crX_Fkhmcj_s4effQfanY8CoV_kLFbg_-iSU646OMrUE91S-KDo2kh31JOpFR2Du353eF-8LngCij1JN4LXfv9pWVMSVpzOhU_aUB6vu1n_rEoY; expires=Fri, 05-Jul-2019 15:38:03 GMT; path=/; domain=.google.com; HttpOnly
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding
Proxy-Connection: keep-alive

 

posted @ 2019-03-11 17:20  水中的火柴盒  阅读(546)  评论(0编辑  收藏  举报