Hysteria2 example

Hysteria2 claims to be able to solve internet speed problems during peak periods

In WHMCS

Install

This tutorial employs Ubuntu 22 as an illustrative example.

Initially, disable the Uncomplicated Firewall (UFW).

sudo ufw disable

If port hopping is required, kindly customize the provided command as per your requirements and execute it accordingly

In the provided command, users are permitted to utilize any port within the range of 20000 to 40000 for connecting to hysteria2, whereas the backend operates on port 40001

Please input "20000-40000" for the client port and "40001" for the backend port in the WHMCS node details

# install iptables-persistent
apt install iptables-persistent -y

# open 22,80,443 ports
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# turn on port forwarding
# IPv4
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:40000 -j DNAT --to-destination :40001
# IPv6
ip6tables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:40000 -j DNAT --to-destination :40001

# save rule
sudo iptables-save > /etc/iptables/rules.v4
sudo ip6tables-save > /etc/iptables/rules.v6

sudo systemctl enable netfilter-persistent
sudo systemctl start netfilter-persistent

Please create a directory and proceed with installing the hysteria2 backend.

mkdir /root/Hysteria
cd /root/Hysteria
wget https://v2raysocks.com/hysteria2/hysteria-linux-amd64
chmod +777 hysteria-linux-amd64
wget https://v2raysocks.com/hysteria2/server.yaml

Please make the necessary modifications to the configuration file server.yaml, as exemplified below.

v2raysocks:
  apiHost: https://yourdomain.com/modules/addons/v2raysocks_nodes/web_api.php
  apiKey: 123456789
  nodeID: 1
tls:
  type: tls
  cert: /root/Hysteria/fullchain.crt
  key: /root/Hysteria/private.pem
auth:
  type: v2raysocks
trafficStats:
  listen: 127.0.0.1:7653 
outbounds:
  - name: defob
    type: direct

Please install the daemon and enable it. We will utilize Supervisor for this purpose.

sudo apt -y install supervisor
sudo chmod 777 /var/run
sudo chmod 777 /etc/supervisor
supervisord

cat > /etc/supervisor/conf.d/hysteria2.conf <<EOF
[program:hysteria2]
command = /root/Hysteria/hysteria-linux-amd64 server -c /root/Hysteria/server.yaml
directory = /root/Hysteria
user = root
autostart = true
autorestart = true
EOF

Following a server reboot, hysteria2 will be launched automatically.

Modify

If you wish to adjust port forwarding rules, you may edit the rule files located within this directory.

/etc/iptables

Subsequently, execute the following command to reload the rules:

sudo systemctl restart netfilter-persistent

Last updated