配置v2ray为shadowsocks客户端

v2ray是一款新兴的sock5代理工具,采用go编写,默认支持shadowsocks原生协议,自带开机启动脚本,这里介绍在linux下配置v2ray为shadowsocks客户端

安装

1
2
3
4
5
6
7
8
9
10
11
mkdir -p /usr/bin/v2ray
mkdir -p /etc/v2ray
mkdir -p /var/log/v2ray

wget https://github.com/v2ray/v2ray-core/releases/download/v2.51/v2ray-linux-64.zip
unzip v2ray-linux-64.zip
cd v2ray*linux-64

cp {v2ray,v2ctl,geoip.dat,geosite.dat} /usr/bin/v2ray/
sudo cp systemd/v2ray.service /lib/systemd/system/v2ray.service
sudo cp systemv/v2ray /etc/init.d/v2ray

配置

作为shadowsocks客户端的配置如下

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$ cat /etc/v2ray/config.json

{
"log":{
"loglevel":"warning"
},
"inbound":{
"port":1080, //监听端口
"protocol":"socks",
"settings":{
"auth":"noauth"
}
},
"outbound":{
"protocol":"shadowsocks",
"settings":{
"servers":[
{
"address":"服务器地址",
"method":"加密方式",
"password":"密码",
"port":服务器端口,
"ota":false
}
]
}
},
"outboundDetour":[
{
"protocol":"freedom",
"settings":{

},
"tag":"direct"
}
],
"dns":{
"servers":[
"8.8.8.8",
"8.8.4.4",
"localhost"
]
},
"routing":{
"strategy":"rules",
"settings":{
"domainStrategy":"IPIfNonMatch",
"rules":[
{
"type":"field",
"port":"1-52",
"outboundTag":"direct"
},
{
"type":"field",
"port":"54-79",
"outboundTag":"direct"
},
{
"type":"field",
"port":"81-442",
"outboundTag":"direct"
},
{
"type":"field",
"port":"444-65535",
"outboundTag":"direct"
},
{
"type":"field",
"domain":[
"geosite:cn"
],
"outboundTag":"direct"
},
{
"type":"field",
"ip":[
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10",
"geoip:cn"
],
"outboundTag":"direct"
}
]
}
}
}

启动配置

release自带的init启动文件默认不支持centos6,启动会报错It could not find the /lib/init/vars.sh and /lib/lsb/init-functions,根据issue的解决方法解决

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
$ cat /etc/init.d/v2ray

#!/bin/sh
#
# v2ray Startup script for v2ray
#
# chkconfig: - 24 76
# processname: v2ray
# pidfile: /var/run/v2ray.pid
# description: V2Ray proxy services
#

### BEGIN INIT INFO
# Provides: v2ray
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: V2Ray proxy services
# Description: V2Ray proxy services
### END INIT INFO

DESC=v2ray
NAME=v2ray
DAEMON=/usr/bin/v2ray/v2ray
PIDFILE=/var/run/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
SCRIPTNAME=/etc/init.d/$NAME
RETVAL=0

DAEMON_OPTS="-config /etc/v2ray/config.json"

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Source function library.
. /etc/rc.d/init.d/functions

start() {
local pids=$(pgrep -f $DAEMON)
if [ -n "$pids" ]; then
echo "$NAME (pid $pids) is already running"
RETVAL=0
return 0
fi

echo -n $"Starting $NAME: "

mkdir -p /var/log/v2ray
$DAEMON $DAEMON_OPTS 1>/dev/null 2>&1 &
echo $! > $PIDFILE

sleep 2
pgrep -f $DAEMON >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
success; echo
touch $LOCKFILE
else
failure; echo
fi
return $RETVAL
}

stop() {
local pids=$(pgrep -f $DAEMON)
if [ -z "$pids" ]; then
echo "$NAME is not running"
RETVAL=0
return 0
fi

echo -n $"Stopping $NAME: "
killproc -p ${PIDFILE} ${NAME}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
}

reload() {
echo -n $"Reloading $NAME: "
killproc -p ${PIDFILE} ${NAME} -HUP
RETVAL=$?
echo
}

rh_status() {
status -p ${PIDFILE} ${DAEMON}
}

# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
status)
rh_status
RETVAL=$?
;;
restart)
stop
start
;;
reload)
reload
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart}" >&2
RETVAL=2
;;
esac
exit $RETVAL

测试

建议配合proxychains-ng一起使用,为命令行添加代理工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ubuntu@VM-238-131-ubuntu:~$ px curl ip-api.com

[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/local/proxychains/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.12
[proxychains] Strict chain ... 127.0.0.1:1080 ... ip-api.com:80 ... OK
{
"country" : "Singapore",
"countryCode" : "SG",
"region" : "01",
"regionName" : "Central Singapore Community Development Council",
"city" : "Singapore",
"zip" : "",
"lat" : 1.2855,
"lon" : 103.8565,
"timezone" : "Asia/Singapore",
"isp" : "Microsoft Corp",
"org" : "Microsoft Azure",
"as" : "AS8075 Microsoft Corporation",
"mobile" : false,
"proxy" : false,
"query" : "168.63.*.*"
}

需要注意的是我提供的配置文件自带智能代理,国内IP是直连,国外IP是走代理

1
2
3
4
5
6
7
8
9
ubuntu@VM-238-131-ubuntu:~/dl$ px curl cip.cc
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/local/proxychains/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.12
[proxychains] Strict chain ... 127.0.0.1:1080 ... cip.cc:80 ... OK
IP : 115.159.*.*
地址 : 中国 上海

数据二 : 上海市 | 深圳市腾讯计算机系统有限公司BGP数据中心(BGP)
分享到: