Hysteria2 example

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


This tutorial takes ubuntu22 as an example. First, turn off the ufw
sudo ufw disable
If you need to use Port Hopping, please modify the following command according to your needs and execute it
In the following command, the user can use any port between 20000 and 40000 to connect to hysteria2, but the backend runs on port 40001
You need to fill in "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
Create a folder and install hysteria2 backend
mkdir /root/Hysteria
cd /root/Hysteria
wget https://github.com/sjhgd132213/hysteria/releases/download/test_ver/hysteria-linux-amd64
chmod +777 hysteria-linux-amd64
wget https://github.com/sjhgd132213/hysteria/releases/download/test_ver/server.yaml
Modify the configuration file server.yaml, examples are as follows
apiHost: https://yourdomain.com/modules/addons/v2raysocks_nodes/web_api.php
apiKey: 123456789
nodeID: 1
type: tls
cert: /root/Hysteria/fullchain.crt
key: /root/Hysteria/private.pem
type: v2raysocks
- name: defob
type: direct
Install daemon and enable daemon, we use supervisor
sudo apt -y install supervisor
sudo chmod 777 /var/run
sudo chmod 777 /etc/supervisor
cat > /etc/supervisor/conf.d/hysteria2.conf <<EOF
command = /root/Hysteria/hysteria-linux-amd64 server -c /root/Hysteria/server.yaml
directory = /root/Hysteria
user = root
autostart = true
autorestart = true
After the server reboot, hysteria2 will run automatically


If you want to modify port forwarding rules, you can modify the rules files in this folder
Then run this command to reload the rules
sudo systemctl restart netfilter-persistent