安装

下载地址

linux一键安装脚本

说明文档

使用systemctl管理hysteria2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[Unit]
Description=Hysteria Server Service (config.yaml)
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/hysteria server --config /etc/hysteria/config.yaml
WorkingDirectory=/etc/hysteria
User=hysteria
Group=hysteria
Environment=HYSTERIA_LOG_LEVEL=info
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

管理服务

1
2
3
sudo systemctl enable hysteria-server.service
sudo systemctl start hysteria-server.service
sudo systemctl stop hysteria-server.service

服务端

记得防火墙放行udp端口

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
listen: :80
#证书,注意过期时间
tls:
cert:
key:
#运行测速
speedTest: true

auth:
type: password
password: xxxx

#伪装成标准的 HTTP/3 流量
#file:作为一个静态文件服务器,从一个目录提供内容。
#proxy:作为一个反向代理,从另一个网站提供内容。
#string:返回一个固定的字符串。
masquerade:
type: file | proxy | string
file:
dir: /www/masq
proxy:
url: https://some.site.net
rewriteHost: true
string:
content: hello stupid world
headers:
content-type: text/plain
custom-stuff: ice cream so good
statusCode: 200

#出站规则(分流)
outbounds:
#socks5代理
- name: my_outbound_1
type: socks5
socks5:
addr: ip:port
#http代理
- name: my_outbound_2
type: http
http:
url: http://ip:port
#直连
- name: my_outbound_3
type: direct
direct:
mode: auto
#规则
acl:
file: /etc/hysteria/acl.txt

客户端

以clash为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
proxies:
- name: test
type: hysteria2
server:
port: 80
# 端口跃迁
#pors: 20000-30000
udp: true
password: xxx
#带宽
up: "150 Mbps"
down: "100 Mbps"
#TLS验证
sni:
skip-cert-verify: false # 是否跳过验证

出站

修改出站规则,以解锁网易云灰色歌曲为例

1
2
3
4
5
6
7
8
9
10
11
outbounds:
- name: music
type: http
http:
url: http://ip:8081
- name: Direct
type: direct
direct:
mode: auto
acl:
file: /etc/hysteria/acl.txt
1
2
3
4
5
6
7
8
9
10
# 网易云解锁
music(music.163.com)
music(apm.music.163.com)
music(apm3.music.163.com)
music(interface.music.163.com)
music(interface3.music.163.com)
music(interface.music.163.com.163jiasu.com)
music(interface3.music.163.com.163jiasu.com)
# 直连
Direct(all)

端口跃迁

服务端

Hysteria 服务端并不能同时监听多个端口,因此不能在服务器端使用上面的格式作为监听地址。建议配合 iptables 或 nftables 的 DNAT 将端口转发到服务器的监听端口。

1
2
3
4
# IPv4
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:50000 -j REDIRECT --to-ports 443
# IPv6
ip6tables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:50000 -j REDIRECT --to-ports 443

在这个示例中,服务器监听 443 端口,但客户端可以通过 20000-50000 范围内的任何端口连接

无法连接节点的排错记录

域名证书过期

1
2
sni: pve.010920.xyz
skip-cert-verify: false

sni对应证书的域名;skip-cert-verify设置为false的情况下,证书过期会无法连接,临时设置为true即可

DNS解析

1
server: your-domain-name

设置为域名的情况下,要保证该域名能被设置的DNS服务器解析,否则会因找不到IP地址无法连接