hysteria2 节点搭建

hysteria2 节点搭建

一、获取一台VPS

选择一家VPS厂商,获取一台VPS

二、服务器测试

1、Alpine 系统速度以及IP纯净度测试

1
bash <(curl -Ls IP.Check.Place)

1751808500087.png

1
2
3
4
# I/O测试和速度测试
wget -qO- bench.sh | bash
# 回程路由测试
wget -qO- git.io/besttrace | bash

三、hysteria2 服务器节点搭建

1、Alpine 系统节点搭建

1
2
apk update && apk upgrade
wget -O hy2.sh https://raw.githubusercontent.com/zrlhk/alpine-hysteria2/main/hy2.sh && sh hy2.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
#!/bin/bash

apk add wget curl git openssh openssl openrc

generate_random_password() {
dd if=/dev/random bs=18 count=1 status=none | base64
}

generate_random_port() {
shuf -i 10000-65535 -n 1
}

GENPASS="$(generate_random_password)"
GENPORT="$(generate_random_port)"

echo_hysteria_config_yaml() {
cat << EOF
listen: :$GENPORT


#有域名,使用CA证书
#acme:
# domains:
# - test.heybro.bid #你的域名,需要先解析到服务器ip
# email: xxx@gmail.com

#使用自签名证书
tls:
cert: /etc/hysteria/server.crt
key: /etc/hysteria/server.key

auth:
type: password
password: $GENPASS

masquerade:
type: proxy
proxy:
url: https://bing.com/
rewriteHost: true
EOF
}

echo_hysteria_autoStart(){
cat << EOF
#!/sbin/openrc-run

name="hysteria"

command="/usr/local/bin/hysteria"
command_args="server --config /etc/hysteria/config.yaml"

pidfile="/var/run/${name}.pid"

command_background="yes"

depend() {
need networking
}

EOF
}


wget -O /usr/local/bin/hysteria https://download.hysteria.network/app/latest/hysteria-linux-amd64 --no-check-certificate
chmod +x /usr/local/bin/hysteria

mkdir -p /etc/hysteria/

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

#写配置文件
echo_hysteria_config_yaml > "/etc/hysteria/config.yaml"

#写自启动
echo_hysteria_autoStart > "/etc/init.d/hysteria"
chmod +x /etc/init.d/hysteria
#启用自启动
rc-update add hysteria

service hysteria start

#启动hy2
#/usr/local/bin/hysteria server --config /etc/hysteria/config.yaml &

echo "------------------------------------------------------------------------"
echo "hysteria2已经安装完成"
echo "默认端口: $GENPORT , 密码为: $GENPASS ,工具中配置:tls,SNI为: bing.com"
echo "配置文件:/etc/hysteria/config.yaml"
echo "已经随系统自动启动"
echo "看状态 service hysteria status"
echo "重启 service hysteria restart"
echo "请享用。"
echo "------------------------------------------------------------------------"

2、端口跳跃

  1. Debain 系统:

    • 添加或删除端口转发规则

      1
      2
      3
      4
      5
      6
      7
      ## ipv4 节点, 注意-i后面的网卡, 需要通过ip link show查一下用的哪张网卡
      iptables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:50000 -j REDIRECT --to-ports 6212
      ## ipv6 节点
      ip6tables -t nat -A PREROUTING -i venet0 -p udp --dport 20000:50000 -j REDIRECT --to-ports 12833
      ## 删除添加的规则, 下面是ipv4删除规则的方法, ipv6同理
      iptables -L -t nat --line-number
      iptables -t nat -D PREROUTING 1
    • 安装iptables-persistent

      iptables-persistent是一个工具,可以帮助你在系统重启后保留iptables规则。安装这个工具可以确保你的规则在重启后仍然有效。

      1
      2
      3
      4
      5
      6
      apt install iptables-persistent
      systemctl status netfilter-persistent
      systemctl start netfilter-persistent
      systemctl enable netfilter-persistent
      ## iptables 配置完规则后, 执行下面命令, 保存规则
      netfilter-persistent save
  2. Alpine 系统

    • 添加端口跳跃规则(通Debain一样, 安装iptables, 安装iptables的命令规范添加规则)

    • 保存iptables规则

      1
      2
      3
      4
      5
      6
      7
      8
      iptables-save > /etc/iptables/rules.v4
      ip6tables-save > /etc/iptables/rules.v6
      ## 确保文件权限
      sudo chown root:root /etc/iptables/rules.v4
      sudo chmod 600 /etc/iptables/rules.v4
      # 如果保存了IPv6规则
      sudo chown root:root /etc/iptables/rules.v6
      sudo chmod 600 /etc/iptables/rules.v6
    • 创建启动脚本

      创建文件vi /etc/local.d/iptables.start

      1
      2
      3
      #!/bin/sh
      iptables-restore < /etc/iptables/rules.v4
      ip6tables-restore < /etc/iptables/rules.v6

      文件编辑完成后,在命令行执行:

      1
      2
      3
      4
      5
      6
      7
      chmod +x /etc/local.d/iptables.start
      ## 确保/etc/rc.conf文件中包含了local服务的配置
      echo 'local' >> /etc/rc.conf
      ## 确保local服务被启用并在启动时执行
      rc-update add local boot
      ## 手动启动
      rc-service local start

四、hysteria2客户端搭建

1、V2ray配置

添加hysteria2配置文件:

250706230005596.png

配置文件参数填写:

250706231442005.png

2、Clash配置

1
- {name: 🇹🇷 土耳其_NAT, server: xx.xx.xx.xx, port: xxxx, type: hysteria2, client-fingerprint: chrome, password: xxxxxx, sni: bing.com, skip-cert-verify: true, fingerprint: cdc4xxxbc, udp: true}

fingerprint(可选)可以用一下命令查询:

1
2
## /etc/hysteria/server.crt 填自己证书路径
openssl x509 -noout -fingerprint -sha256 -in /etc/hysteria/server.crt | awk -F= '{print $2}' | tr -d ':' | tr '[:upper:]' '[:lower:]'