Ultimate Hysteria 2 Anti-Blocking Node Deployment Guide
This guide features a battle-tested core logic that accurately addresses pain points like aaPanel certificate permissions, iptables rules hijacking, and special character URL encoding. To make it truly plug-and-play—beginner-friendly and scalable for bulk deployment—I have restructured the content and optimized the scripts.
Below is the optimized foolproof deployment guide. All steps include fault-tolerant error handling, making it ready to use as a standard operating procedure (SOP) for your team:
-
Prepare Domain and SSL Certificate: Infrastructure setup (must be executed first).
Before getting started, we need a clean domain name and a valid SSL certificate.- DNS Resolution: At your domain registrar, point your subdomain (e.g.,
hy2.yourdomain.com) to your VPS IP address.
Critical Tip: If you use Cloudflare for DNS management, the cloud icon must stay gray (DNS Only). Enabling the orange proxy will block UDP traffic, causing Hysteria 2 to completely fail.
- Deploy SSL Certificate:
- Log in to aaPanel -> Website -> Add site (enter your subdomain).
- Go to the site's SSL settings, select Let's Encrypt, select your domain, and apply for the certificate.
- Once you see the green
[SSL Deployed]status, this step is complete.
- DNS Resolution: At your domain registrar, point your subdomain (e.g.,
-
One-Click Install Hysteria 2 Core: Official script installation.
Connect to your server via SSH and run the official one-click installation script. It will automatically detect your Linux distribution and pull the latest core binary.
bash <(curl -fsSL https://get.hy2.sh/)
- Write Server Configuration File: Define port, password, and masquerade target.
This step automatically creates the configuration file. Before running the command, update the variables in the first three lines below with your own details, then copy and paste the entire snippet into your terminal and press Enter.
# === Modify your custom configuration here ===
MY_DOMAIN="hy2.yourdomain.com" # Replace with your subdomain
MY_PASSWORD="YourStrongPassword!" # Replace with your strong password
MY_PORT="40000" # Replace with 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 Process: Fix the BT Panel certificate permission denied pitfall.
The certificate directory generated by BT Panel is restricted to therootaccount. Running Hysteria as the default unprivileged user will cause it to crash immediately. Execute the following commands to forcibly manage the service with 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: You must see a green
active (running)in the output; otherwise, the configuration is incorrect.*
- Deploy Port Hopping Network to Prevent Blocking: The core mechanism against QoS and blocking.
Useiptablesto create a port hopping range between 20000 and 40000. This script includes a fault-tolerant mechanism to automatically clean up old rules, preventing legacy 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 port-hopping rules (ignore errors)
```bash
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 Port-Hopping 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. Persistence (For Debian/Ubuntu, ensures settings survive reboots)
apt update && apt install iptables-persistent -y
netfilter-persistent save
echo "✅ Port hopping network deployment complete, main port: $MAIN_PORT"
> **Cloud Firewall Warning**:
> In addition to allowing `UDP 20000-40000` in **Baota Panel (aaPanel) -> Security**, you **must** log in to your cloud provider's console (such as Alibaba Cloud, Tencent Cloud, etc.) and add the same UDP inbound rules to your **Security Group**. Otherwise, connection will fail completely!
6. **Deploy One-Click Dynamic Sharing Script:** Scan the QR code on mobile for direct connection, with automatic URL-safe encoding.
Run the following code on your server. In the future, you can type `hy2-link` in the terminal at any time to automatically generate a sharing link and QR code matching your current configuration.
```bash
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 "🎉 Exclusive Hysteria 2 Link for Current Node 🎉"
echo -e "==========================================
"
echo -e "$LINK
"
echo -e "📱 Scan the QR code below on your mobile device to import with one click:
"
qrencode -t ANSI256 "$LINK"
EOF
chmod +x /usr/local/bin/hy2-link
echo "✅ Script deployed successfully! Type 'hy2-link' in the terminal to generate the QR code at any time."
- Multi-Platform Client Integration: Configuration settings to avoid common pitfalls.
After runninghy2-linkto get the link, configure your client according to the following guide:
-
🖥️ Windows (v2rayN)
- Maximum Bandwidth Settings: Fill in realistically based on your actual network conditions (e.g., Up
30, Down100). Do not leave this blank or enter excessively large numbers (e.g., 1000), as this will disrupt congestion control and cause packet loss. - Kernel Troubleshooting: Go to
Settings -> Kernel Settingsand force the Hysteria 2 kernel tosing_box. Go toTun Mode Settingsand you must check "Legacy TUN Protection".
- Maximum Bandwidth Settings: Fill in realistically based on your actual network conditions (e.g., Up
-
🍎 Mac & 📱 iOS
- Hiddify: A free cross-platform powerhouse with native sing-box support. Simply copy the generated link and paste it to import.
- Shadowrocket: The preferred choice for iOS and Apple Silicon (M-series) Mac. Scan the QR code to import directly for the most stable experience.
🛑 Ultimate Troubleshooting Guide
If the client is still experiencing excessive timeouts after completing the above steps, check against the following three common pitfalls 100% item by item:
1. Cloud Provider's "Double-Gate" Blocking
Symptom: The port is clearly allowed in the Baota Panel, but the client still cannot connect.
Root Cause: Most people only remember to open the firewall in the Baota Panel. Major cloud providers (AWS, Alibaba Cloud, Tencent Cloud) have an outermost, physical-level "Security Group" in their web consoles. Traffic must pass through this security group before it can reach the Baota Panel.
Solution: Log in to the cloud console -> Instance Security Groups -> Inbound Rules -> Add a rule to allow UDP protocol, ports 20000/40000.
2. Iptables "Ghost Hijacking"
Symptom: Both firewall layers are enabled, but you cannot connect to the main port.
The Reality: The execution logic of iptables is strict top-down matching. If you previously configured redirection rules for other ports (e.g., redirecting to port 54321) during past tinkering, as long as the old rule remains above, the new rule will be completely ignored.
Solution: Run iptables -t nat -L PREROUTING -n -v --line-numbers in SSH. Check if the first few lines contain rules that intercept 20000:40000 but point to the wrong port. If so, use iptables -t nat -D PREROUTING <line_number> to completely remove it.
3. Parsing Avalanche Triggered by Special Characters
Symptom: After manually entering links or generating them through other methods, the client throws an error, or the parsed password and port are completely wrong.
The Reality: The standard format is hysteria2://password@domain:port. If you set your password to Admin@2026 for security, the client will mistake this @ for the domain separator, causing the parsed fields to be completely scrambled.
Solution: This is why we must use the hy2-link script in Step 6. It automatically encodes @ into its URL-safe form (%40) under the hood, eliminating such bizarre issues at the root.
Related Technical Insights & Field Notes
Why AI's Rapid Progress Demands New Metrics for Monitoring Development
In the midst of growing concerns about the risks associated with artificial intelligence, Anthropic PBC has taken a cru...
Crusoe's $30.9B Valuation Underscores AI Data Center Revolution
In a landmark development, Crusoe Inc., a Denver based company specializing in the construction of artificial intellige...
The Financial Paradox of Hyper-Scale AI Infrastructure
The physical and financial boundaries of enterprise computing are expanding faster than the traditional electric grid c...