Linux 命令行下 Hysteria 2 客户端的安装与配置教程

前言

最近在探索网络代理工具时,使用了 Hysteria 2(简称 hy2),这是一个基于 QUIC 协议的高性能代理软件,适合弱网环境和翻墙场景。在 Linux 命令行下安装和配置 Hysteria 2 时,遇到了一些问题,如连接超时、配置转换等。通过一步步排查,最终成功运行。本文整理了整个过程,总结成教程,便于大家参考。

Hysteria 2 的安装

Hysteria 2 支持 Linux 多种架构,推荐使用官方一键安装脚本:

1
bash <(curl -fsSL https://get.hy2.sh/)

这会自动下载最新版本,安装到 /usr/local/bin/hysteria,并生成示例配置文件 /etc/hysteria/config.yaml,同时创建 systemd 服务 hysteria-server(服务端模式)。

如果需要手动安装:

  1. 从 GitHub Releases 下载二进制文件(例如 amd64 版):

    1
    2
    3
    wget https://github.com/apernet/hysteria/releases/latest/download/hysteria-linux-amd64-avx
    chmod +x hysteria-linux-amd64-avx
    sudo mv hysteria-linux-amd64-avx /usr/local/bin/hysteria
  2. 授予网络绑定权限:

    1
    sudo setcap cap_net_bind_service=+ep /usr/local/bin/hysteria

验证安装:运行 hysteria version,显示版本号即可。

服务端配置(可选)

如果需要自建服务端,编辑 /etc/hysteria/config.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
listen: :443

tls:
cert: /path/to/cert.pem
key: /path/to/key.pem

auth:
type: password
password: your_password

masquerade:
type: proxy
proxy:
url: https://www.example.com
rewriteHost: true

bandwidth:
up: 100 mbps
down: 100 mbps

生成自签名证书(测试用):

1
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout key.pem -out cert.pem -subj "/CN=your.domain.com" -days 36500

启动服务:

1
2
sudo systemctl start hysteria-server
sudo systemctl enable hysteria-server

从 Clash 配置转换到 Hysteria 2 客户端配置

如果有 Clash 中的 Hysteria 2 配置,例如:

1
2
3
4
5
6
7
8
9
name: nodename
type: hysteria2
server: domain.com
port: '12345'
password: abcdefg
up: '1 gbps'
down: '1 gbps'
obfs: salamander
obfs-password: abcdefg

可以转换为 Hysteria 2 的客户端 YAML 配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server: domain.com:12345

auth: abcdefg

obfs:
type: salamander
salamander:
password: abcdefg

bandwidth:
up: 1 gbps
down: 1 gbps

tls:
sni: domain.com
insecure: false

socks5:
listen: 127.0.0.1:1080

http:
listen: 127.0.0.1:8080

保存为 config.yaml,然后运行客户端:

1
./hysteria-linux-amd64 -c config.yaml

运行与测试

运行后,日志显示:

1
2
3
4
2025-10-03T20:26:51+08:00       INFO    client mode
2025-10-03T20:26:52+08:00 INFO connected to server {"udpEnabled": true, "tx": 125000000, "count": 1}
2025-10-03T20:26:52+08:00 INFO HTTP proxy server listening {"addr": "127.0.0.1:8080"}
2025-10-03T20:26:52+08:00 INFO SOCKS5 server listening {"addr": "127.0.0.1:1080"}

测试代理:

  • SOCKS5:curl --socks5 127.0.0.1:1080 https://www.google.com
  • HTTP:curl -x http://127.0.0.1:8080 https://www.google.com

如果直接 curl https://www.google.com 失败,但通过代理成功,可能是网络限制。解决方案:

配置 TUN 模式(全局代理)

config.yaml 添加:

1
2
3
4
5
6
7
tun:
enable: true
stack: system
autoRoute: true
dns:
- 8.8.8.8
- 1.1.1.1

以 root 运行:sudo ./hysteria-linux-amd64 -c config.yaml

设置环境变量

1
2
3
export http_proxy=http://127.0.0.1:8080
export https_proxy=http://127.0.0.1:8080
curl https://www.google.com

常见问题排查

  • 连接超时错误:如 connect error: timeout: no recent network activity,检查服务端运行、防火墙端口(UDP 8015)、配置匹配。启用混淆或更换端口。

  • TLS 问题:设置 tls.insecure: true 测试。

  • 性能优化:启用 BBR 拥塞控制:

    1
    2
    sudo sysctl -w net.ipv4.tcp_congestion_control=bbr
    sudo sysctl -w net.core.default_qdisc=fq
  • 后台运行:使用 nohup 或 systemd 服务。

结语

通过以上步骤,Hysteria 2 在 Linux 下可以轻松配置和运行,适合需要高性能代理的场景。更多细节参考官方文档:Hysteria 2 官网。如果遇到问题,欢迎评论交流!


Linux 命令行下 Hysteria 2 客户端的安装与配置教程
https://blog.yonagi.top/2025/10/02/ca7a74e69d65/
作者
Yonagi
发布于
2025年10月3日
许可协议