-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathHysteria2.sh
109 lines (93 loc) · 2.64 KB
/
Hysteria2.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
#!/bin/bash
# 随机生成端口和密码
[ -z "$HY2_PORT" ] && HY2_PORT=$(shuf -i 2000-65000 -n 1)
[ -z "$PASSWD" ] && PASSWD=$(openssl rand -hex 8)
# 检查是否为root下运行
[[ $EUID -ne 0 ]] && echo -e '\033[1;35m请在root用户下运行脚本\033[0m' && exit 1
# 判断系统并安装依赖
SYSTEM=$(cat /etc/os-release | grep '^ID=' | awk -F '=' '{print $2}' | tr -d '"')
case $SYSTEM in
"debian"|"ubuntu")
package_install="apt-get install -y"
;;
"centos"|"oracle"|"rhel")
package_install="yum install -y"
;;
"fedora"|"rocky"|"almalinux")
package_install="dnf install -y"
;;
"alpine")
package_install="apk add"
;;
*)
echo -e '\033[1;35m暂不支持的系统!\033[0m'
exit 1
;;
esac
$package_install openssl unzip wget curl
# 安装Hysteria2
bash <(curl -fsSL https://get.hy2.sh/)
# 生成自签证书
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout /etc/hysteria/server.key -out /etc/hysteria/server.crt -subj "/CN=bing.com" -days 36500 && sudo chown hysteria /etc/hysteria/server.key && sudo chown hysteria /etc/hysteria/server.crt
# 生成hy2配置文件
cat << EOF > /etc/hysteria/config.yaml
listen: :$HY2_PORT
tls:
cert: /etc/hysteria/server.crt
key: /etc/hysteria/server.key
auth:
type: password
password: "$PASSWD"
fastOpen: true
masquerade:
type: proxy
proxy:
url: https://bing.com
rewriteHost: true
transport:
udp:
hopInterval: 30s
EOF
# 启动Hysteria2
systemctl start hysteria-server.service
systemctl restart hysteria-server.service
# 设置开机自启
systemctl enable hysteria-server.service
# 获取本机IP地址
ipv4=$(curl -s ipv4.ip.sb)
if [ -n "$ipv4" ]; then
HOST_IP="$ipv4"
else
ipv6=$(curl -s --max-time 1 ipv6.ip.sb)
if [ -n "$ipv6" ]; then
HOST_IP="$ipv6"
else
echo -e "\e[1;35m无法获取IPv4或IPv6地址\033[0m"
exit 1
fi
fi
echo -e "\e[1;32m本机IP: $HOST_IP\033[0m"
# 获取ipinfo
ISP=$(curl -s https://speed.cloudflare.com/meta | awk -F\" '{print $26"-"$18}' | sed -e 's/ /_/g')
# 输出hy2信息
echo -e "\e[1;32mHysteria2安装成功\033[0m"
echo ""
echo -e "\e[1;33mV2rayN 或 Nekobox\033[0m"
echo -e "\e[1;32mhysteria2://$PASSWD@$HOST_IP:$HY2_PORT/?sni=www.bing.com&alpn=h3&insecure=1#$ISP\033[0m"
echo ""
echo -e "\e[1;33mSurge\033[0m"
echo -e "\e[1;32m$ISP = hysteria2, $HOST_IP, $HY2_PORT, password = $PASSWD, skip-cert-verify=true, sni=www.bing.com\033[0m"
echo ""
echo -e "\e[1;33mClash\033[0m"
cat << EOF
- name: $ISP
type: hysteria2
server: $HOST_IP
port: $HY2_PORT
password: $PASSWD
alpn:
- h3
sni: www.bing.com
skip-cert-verify: true
fast-open: true
EOF