Free VPN Setup Guide for Baota and Hysteria 2 with Domain
-
Prepare Domain and Certificate: Essential infrastructure setup must be done first.
Before getting started, you need a clean domain and a valid SSL certificate. -
DNS Resolution: At your domain registrar, point your subdomain (e.g.,
hy2.yourdomain.com) to your VPS IP.
Critical Warning: If you use Cloudflare DNS, the orange cloud must remain gray (DNS Only). Enabling the proxy intercepts UDP traffic and will instantly break Hysteria 2.
- Deploy Certificate:
- Log in to the Baota (aaPanel) -> Website -> Add Site (enter your subdomain).
- Go to the SSL settings of the site, select Let's Encrypt, and check your domain to apply for the certificate.
- Once you see the green
[SSL Deployed]message, this step is complete.
- Install Hysteria 2 Core: Official script installation.
Connect to your server via SSH and run the official one-click installation script. This script will automatically detect your Linux distribution and fetch the latest core.
bash <(curl -fsSL https://get.hy2.sh/)
- Write Server Configuration: Define ports, passwords, and masquerade targets.
This step will automatically create the configuration file. Before running it, modify the first three variables in the code below to your own information, then copy and paste the entire block into your terminal and press Enter.
# === Modify your custom configuration here ===
MY_DOMAIN="hy2.yourdomain.com" # Change to your subdomain
MY_PASSWORD="YourStrongPassword!" # Change to your strong password
MY_PORT="40000" # Change to your main port
# =================================
mkdir -p /etc/hysteria
cat <<EOF > /etc/hysteria/config.yaml
listen: :${MY_PORT}
bandwidth:
up: 200 mbps
down: 1000 mbps
tls:
cert: /www/server/panel/vhost/cert/${MY_DOMAIN}/fullchain.pem
key: /www/server/panel/vhost/cert/${MY_DOMAIN}/privkey.pem
auth:
type: password
password: "${MY_PASSWORD}"
masquerade:
type: proxy
proxy:
url: https://apple.com
rewriteHost: true
EOF
echo "✅ Configuration file written successfully!"
- Take Over the Daemon: Resolving the major pitfall of BT Panel certificate permission denials.
The certificate directory generated by BT Panel is restricted to therootuser. Running Hysteria as a standard unprivileged user by default will cause an immediate crash. Run the following code to force the service to run under root privileges:
cat <<EOF > /etc/systemd/system/hysteria-server.service
[Unit]
Description=Hysteria Server Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/hysteria server --config /etc/hysteria/config.yaml
WorkingDirectory=/etc/hysteria
User=root
Group=root
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable hysteria-server.service
systemctl restart hysteria-server.service
systemctl status hysteria-server.service --no-pager | grep Active
- Note: The output must show a green
active (running), otherwise it indicates a configuration error.*
- Deploy Port Hopping Anti-Blocking Network: The core mechanism to combat QoS and blocking.
Useiptablesto establish a port hopping range from 20000 to 40000. This script includes a fault-tolerant mechanism to automatically clean up old rules, preventing stale test rules from intercepting traffic.
# Extract the main port from the configuration file
MAIN_PORT=$(grep -E "^listen:" /etc/hysteria/config.yaml | grep -oP '\d+')
# 1. Fault-tolerant cleanup: attempt to delete any existing old redirect rules (ignore errors)
iptables -t nat -D PREROUTING -p udp --dport 20000:40000 -j REDIRECT --to-ports $MAIN_PORT 2>/dev/null || true
ip6tables -t nat -D PREROUTING -p udp --dport 20000:40000 -j REDIRECT --to-ports $MAIN_PORT 2>/dev/null || true
# 2. Write New Jump Rules (IPv4 + IPv6 Dual-Stack Traffic Capture)
iptables -t nat -A PREROUTING -p udp --dport 20000:40000 -j REDIRECT --to-ports $MAIN_PORT
ip6tables -t nat -A PREROUTING -p udp --dport 20000:40000 -j REDIRECT --to-ports $MAIN_PORT
# 3. Persistent Storage (For Debian/Ubuntu, ensures settings survive reboots)
apt update && apt install iptables-persistent -y
netfilter-persistent save
echo "✅ Port hopping network deployment completed. Main port: $MAIN_PORT"
Cloud Firewall Warning:
In addition to allowingUDP 20000-40000in the Baota (aaPanel) -> Security panel, you must log in to your cloud provider's console (such as Alibaba Cloud, Tencent Cloud, etc.) and add the exact same UDP inbound rule in the Security Group settings; otherwise, the connection will completely fail!
- Deploy the One-Click Dynamic Sharing Script: Direct mobile connection via QR code scanning, with automatic URL-safe encoding.
Run the following code on your server. Afterward, you can simply typehy2-linkin the terminal anytime to automatically generate the sharing link and QR code matching your current configuration.
cat << 'EOF' > /usr/local/bin/hy2-link
# !/bin/bash
CONFIG="/etc/hysteria/config.yaml"
if [ ! -f "$CONFIG" ]; then
echo "❌ Error: Hysteria configuration file not found ($CONFIG)"
exit 1
fi
echo "🔍 Parsing configuration..."
PORT=$(grep -E "^listen:" $CONFIG | grep -oP '\d+')
PASSWORD=$(grep -E "password:" $CONFIG | awk -F'"' '{print $2}')
DOMAIN=$(grep -E "cert:" $CONFIG | awk -F'cert/' '{print $2}' | awk -F'/' '{print $1}')
# Automatically handle special characters in the password (@, :, etc.) to prevent client parsing crashes
SAFE_PASS=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$PASSWORD'''))")
LINK="hysteria2://${SAFE_PASS}@${DOMAIN}:${PORT}/?sni=${DOMAIN}&mport=20000-40000#Hy2-${DOMAIN}"
apt update >/dev/null 2>&1
apt install qrencode python3 -y >/dev/null 2>&1
echo -e "
=========================================="
echo -e "🎉 Your dedicated Hysteria 2 link for this node 🎉"
echo -e "==========================================
"
echo -e "$LINK
"
echo -e "📱 Scan the QR code below on your phone for one-click import:
"
qrencode -t ANSI256 "$LINK"
EOF
chmod +x /usr/local/bin/hy2-link
echo "✅ Script deployed successfully! Run hy2-link in the terminal anytime to generate the QR code."
- Multi-platform client setup: Pitfall-avoidance parameter settings for each platform.
After runninghy2-linkto get the link, configure your clients according to the following guide:
-
🖥️ Windows (v2rayN)
-
Maximum bandwidth settings: Fill in truthfully based on your actual situation (e.g., Up
30, Down100). Never leave it blank or enter an excessively large number (e.g., 1000), otherwise it will cause flow control chaos leading to congestion and packet loss. -
Core correction: Go to
Settings -> Core Settingsand force the Hysteria 2 core tosing_box. Go toTun Mode Settingsand make sure to check [Legacy TUN Protection]. -
🍎 Mac & 📱 iOS
-
Hiddify: A free, all-platform gem with native sing-box support. Simply copy the generated link and paste it to import.
-
Shadowrocket: The top choice for iOS and Apple Silicon (M-series) Mac. Just scan the QR code to import — the most stable experience.
🛑 Ultimate Troubleshooting Guide
If your client is still experiencing frequent timeouts after completing the steps above, please check against these three common pitfalls with 100% certainty:
1. Cloud Provider's "Double Firewall" Block
Symptom: The port is clearly allowed in Baota (aaPanel), but the client cannot connect.
Reality: Most people only remember to open the Baota firewall. Major cloud vendors (AWS, Alibaba Cloud, Tencent Cloud) have an outermost, physical-level "Security Group" in their web consoles. Traffic must pass through the security group before reaching Baota.
Solution: Log in to the cloud console -> Instance Security Groups -> Inbound Rules -> Add a rule allowing the UDP protocol, ports 20000/40000.
2. The "Ghost Interception" of Iptables
Symptom: Both layers of firewalls are enabled, but the main port is unreachable.
Truth: iptables executes logic by matching strictly from top to bottom. If you previously wrote port redirection rules during past troubleshooting (such as forwarding traffic to port 54321), as long as the old rule sits higher up, any new rules will be completely ignored.
Solution: Run iptables -t nat -L PREROUTING -n -v --line-numbers in SSH. Check the first few lines to see if there are any rules intercepting ports 20000:40000 but pointing to the wrong port. If so, completely remove it using iptables -t nat -D PREROUTING <line_number>.
3. Parsing Avalanches Caused by Special Characters
Phenomenon: After manually entering a link or generating one through other methods, the client reports an error, or the parsed password and port are completely incorrect.
The Truth: The standard format is hysteria2://password@domain:port. If you set your password to Admin@2026 for security, the client will misinterpret the @ as a domain separator, causing the fields to become completely garbled.
Solution: This is why you must use the hy2-link script in Step 6. It automatically encodes characters like @ into URL-safe formats (e.g., %40) at the underlying level, eliminating such "paranormal" issues at the source.
Related Technical Insights & Field Notes
OrangeVPS Review: Why I Renewed This Budget VPS for 10 Years
As a full stack engineer and independent builder deploying international web applications, cloud native clusters, and a...
How Modern IP Reputation and Network Risk Control Systems Work
In cloud computing and global business architectures, the selection of server nodes often determines the stability of u...
Top Website Performance and Core Web Vitals Testing Tools Guide
Top Website Performance & Speed Testing Tools Guide 2026: WebPageTest, GTmetrix, Catchpoint, Pingdom & PageSpeed Compar...