Port Hopping
Users in China sometimes report that their ISPs block or throttle persistent UDP connections. However, these restrictions often only apply to the specific port being used. Port hopping can be used as a workaround for this situation.
Client
The Hysteria client supports a special multi-port address format:
example.com:1234,5678,9012 # (1)!
example.com:20000-50000 # (2)!
example.com:1234,5000-6000,7044,8000-9000 # (3)!
- Multiple individual ports.
- A range of ports.
- A combination of both.
There is no limit to the number of ports you can specify.
The client will randomly select one of the specified ports for the initial connection and will periodically switch to a different port. The option for controlling the interval is hopInterval in the transport section:
- The minimum port hopping interval. Must be at least 5s.
- The maximum port hopping interval.
Each hop will use a random interval between minHopInterval and maxHopInterval. This makes the hopping pattern less predictable and harder to detect.
NOTE: You can either use
hopIntervalfor a fixed interval, orminHopInterval/maxHopIntervalfor a random interval. You cannot use both.
Assuming the server is reachable on all the ports you specified, the hopping process is transparent to the upper layers and should not cause any data loss/disconnection.
Server
Built-in port range (Linux)
On Linux, the Hysteria server has built-in support for listening on a port range. Simply specify a port range in the listen field:
The server will listen on the first port in the range and automatically set up firewall rules (using nftables or iptables) to redirect traffic from all other ports to the first port. The rules are automatically cleaned up when the server shuts down.
NOTE: This requires either
nft(nftables) oriptables/ip6tablesto be available on the system. The server may need to be run with appropriate privileges (e.g. root orCAP_NET_ADMIN) to modify firewall rules.
Manual setup
Usually not needed, but you can use iptables or nftables DNAT to forward the ports manually:
In this example, the server listens on port 443, but the client can connect to any port in the range 20000-50000.