搭建shadowsocks server 和 client端

sever 端

1
2
sudo apt update
sudo apt install shadowsocks

下载完成后,配置shadowsocks 文件,

1
vim /etc/shadowsocks/config.json
1
2
3
4
5
6
7
8
9
{
"server":"ethan2lee.online", #you server ip
"server_port":8888,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"your_password",
"timeout":300,
"method":"aes-256-cfb"
}

一般来说,我们只需要更改“server”和“password”字段的值即可,根据自己实际情况配置。更改完后,保存。

接下来就是启动server端了,先设置开机自启,再启动。

1
2
3
4
➜  ~ sudo systemctl enable  shadowsocks.service

shadowsocks.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable shadowsocks
1
➜  ~ sudo systemctl start   shadowsocks.service

查看服务状态:

1
2
3
4
5
6
7
8
9
10
11
12
➜  ~ sudo systemctl status  shadowsocks.service
● shadowsocks.service - LSB: Fast tunnel proxy that helps you bypass firewalls
Loaded: loaded (/etc/init.d/shadowsocks; bad; vendor preset: enabled)
Active: active (exited) since Sat 2018-10-20 04:59:16 UTC; 4s ago
​ Docs: man:systemd-sysv-generator(8)
Process: 634 ExecStart=/etc/init.d/shadowsocks start (code=exited, status=0/SUCCESS)
​ Tasks: 0
Memory: 0B
​ CPU: 0

Oct 20 04:59:16 ethan systemd[1]: Starting LSB: Fast tunnel proxy that helps you bypass firewalls...
Oct 20 04:59:16 ethan systemd[1]: Started LSB: Fast tunnel proxy that helps you bypass firewalls.

这样我们shadowsocks的server端就配置完成了。

client端

在需要用shadowsocks的server服务的机子也安装shaodowsocks。

1
2
sudo apt update
sudo apt install shadowsocks

同样需要配置一下shadowsocks的配置文件,一般跟server端的配置差不多,但是需要自行更改“local_port”的字段值。

1
vim /etc/shadowsocks/config.json
1
2
3
4
5
6
7
8
9
{
"server":"ethan2lee.online", #you server ip
"server_port":8888,
"local_address": "127.0.0.1",
"local_port":1080, ### 在clien端可以自主配置的
"password":"your_password",
"timeout":300,
"method":"aes-256-cfb"
}

配置完成之手进行保存。

开启client 端,这样我们只要使用sock5协议通过代理端口1080访问网络,就可以完全使用server的网络环境了。

1
2
3
4
➜  ~ sslocal -c /etc/shadowsocks/config.json
INFO: loading config from /etc/shadowsocks/config.json
shadowsocks 2.1.0
2018-10-20 05:10:08 INFO starting local at 127.0.0.1:1080

打开之后,shadowsocks的client 端是运行在前台的。我们先按Ctr +c 终止进行,再输入以下命令,让它在后台运行:

1
2
3
➜  ~ nohup sslocal -c /etc/shadowsocks/config.json &
[1] 9479
nohup: ignoring input and appending output to 'nohup.out'

这样它就作为守护进程在运行着了。

proxychains

安装完shadowsocks之后,如果想让终端命令也经常代理,那么我们就需要proxychains来帮忙了。

安装proxychains

1
sudo apt install proxychains

修改proxychains 配置文件,直接找到最后一行。

1
➜  ~ vim /etc/proxychains.conf

socks4 127.0.0.1 9095改为

1
socks5 127.0.0.1 1080

1080 为你刚刚配置shadowsocks client端的“local_host”字段的值,配置完成后保存。

经过以上所有步骤,我们可以通过一下命令来查看我们是否配置正确了:

1
proxychains wget www.google.com

如果有一下输出,那么就证明你配置成功了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
➜  ~ proxychains wget www.google.com
ProxyChains-3.1 (http://proxychains.sf.net)
--2018-10-20 05:28:01-- http://www.google.com/
Resolving www.google.com (www.google.com)... |DNS-request| www.google.com
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| www.google.com is 74.125.20.103
74.125.20.103
Connecting to www.google.com (www.google.com)|74.125.20.103|:80... |S-chain|-<>-127.0.0.1:1080-<><>-74.125.20.103:80-<><>-OK
connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html [ <=> ] 11.05K --.-KB/s in 0s

2018-10-20 05:28:02 (63.6 MB/s) - ‘index.html’ saved [11319]

如果没有,就只能继续百度了。