forked from jxzy199306/V2ray-Bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v2ray.sh
332 lines (302 loc) · 7.77 KB
/
v2ray.sh
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#Check Root
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
#Check OS
if [ -f /etc/redhat-release ];then
OS='CentOS'
elif [ ! -z "`cat /etc/issue | grep bian`" ];then
OS='Debian'
elif [ ! -z "`cat /etc/issue | grep Ubuntu`" ];then
OS='Ubuntu'
else
echo "Not support OS, Please reinstall OS and retry!"
exit 1
fi
# Get Public IP address
ipc=$(ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1)
if [[ "$IP" = "" ]]; then
ipc=$(wget -qO- -t1 -T2 ipv4.icanhazip.com)
fi
uuid=$(cat /proc/sys/kernel/random/uuid)
function Install(){
#Install Basic Packages
if [[ ${OS} == 'CentOS' ]];then
yum install curl wget unzip ntp ntpdate -y
else
apt-get update
apt-get install curl unzip ntp wget ntpdate -y
fi
#Set DNS
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
#Update NTP settings
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate us.pool.ntp.org
#Disable SELinux
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
#Run Install
cd /root
bash <(curl -L -s https://install.direct/go.sh)
}
clear
echo 'V2Ray 一键安装|配置脚本 Author:Kirito && 雨落无声'
echo ''
echo '此脚本会关闭iptables防火墙,切勿用于生产环境!'
while :; do echo
read -p "输入用户等级(自用请输入1,共享请输入0):" level
if [[ ! $level =~ ^[0-1]$ ]]; then
echo "${CWARNING}输入错误! 请输入正确的数字!${CEND}"
else
break
fi
done
read -p "输入主要端口(默认:32000):" mainport
[ -z "$mainport" ] && mainport=32000
read -p "输入数据端口起点(默认:32001):" subport1
[ -z "$subport1" ] && subport1=32000
read -p "输入数据端口终点(默认:32500):" subport2
[ -z "$subport2" ] && subport2=32500
read -p "输入每次开放端口数(默认:10):" portnum
[ -z "$portnum" ] && portnum=10
read -p "输入端口变更时间(单位:分钟):" porttime
[ -z "$porttime" ] && porttime=5
read -p "是否启用HTTP伪装?(默认开启) [y/n]:" ifhttpheader
[ -z "$ifhttpheader" ] && ifhttpheader='y'
if [[ $ifhttpheader == 'y' ]];then
httpheader=',
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"connectionReuse": true,
"header": {
"type": "http",
"request": {
"version": "1.1",
"method": "GET",
"path": ["/"],
"headers": {
"Host": ["www.baidu.com", "www.sogou.com/"],
"User-Agent": [
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46"
],
"Accept-Encoding": ["gzip, deflate"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
},
"response": {
"version": "1.1",
"status": "200",
"reason": "OK",
"headers": {
"Content-Type": ["application/octet-stream", "application/x-msdownload", "text/html", "application/x-shockwave-flash"],
"Transfer-Encoding": ["chunked"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
}
}
}
}'
else
httpheader=''
read -p "是否启用mKCP协议?(默认开启) [y/n]:" ifmkcp
[ -z "$ifmkcp" ] && ifmkcp='y'
if [[ $ifmkcp == 'y' ]];then
mkcp=',
"streamSettings": {
"network": "kcp"
}'
else
mkcp=''
fi
fi
#CheckIfInstalled
if [ ! -f "/usr/bin/v2ray/v2ray" ]; then
Install
fi
#Disable iptables
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
#Configure Server
service v2ray stop
rm -rf config
cat << EOF > config
{"log" : {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbound": {
"port": $mainport,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$uuid",
"level": $level,
"alterId": 100
}
],
"detour": {
"to": "detour"
}
}${mkcp}${httpheader}
},
"outbound": {
"protocol": "freedom",
"settings": {}
},
"inboundDetour": [
{
"protocol": "vmess",
"port": "$subport1-$subport2",
"tag": "detour",
"settings": {},
"allocate": {
"strategy": "random",
"concurrency": $portnum,
"refresh": $porttime
}${mkcp}${httpheader}
}
],
"outboundDetour": [
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"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"
],
"outboundTag": "blocked"
}
]
}
}
}
EOF
rm -rf /etc/v2ray/config.back
mv /etc/v2ray/config.json /etc/v2ray/config.back
mv config /etc/v2ray/config.json
rm /root/config.json
cat << EOF > /root/config.json
{
"log": {
"loglevel": "warning"
},
"inbound": {
"port": 1080,
"listen": "127.0.0.1",
"protocol": "http",
"settings": {
"auth": "noauth",
"udp": false,
"ip": "127.0.0.1"
}
},
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "$ipc",
"port": $mainport,
"users": [
{
"id": "$uuid",
"alterId": 100
}
]
}
]
}${mkcp}${httpheader}
},
"outboundDetour": [
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
}
],
"dns": {
"servers": [
"8.8.8.8",
"8.8.4.4",
"localhost"
]
},
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"type": "chinasites",
"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"
],
"outboundTag": "direct"
},
{
"type": "chinaip",
"outboundTag": "direct"
}
]
}
}
}
EOF
service v2ray start
clear
echo '教程地址:https://github.com/FunctionClub/V2ray-Bash/blob/master/README.md'
echo '配置完成,客户端配置文件在 /root/config.json'
echo ''
echo "程序主端口:$mainport"
echo "UUID: $uuid"