Skip to content

hysteria2 ​

Hysteria 2 over QUIC: the client authenticates with a single HTTP/3 request, then each TCP connection is a QUIC stream and UDP goes as QUIC datagrams. The sides negotiate the speed: with known bandwidths Brutal congestion control works, otherwise BBR. The server answers foreign HTTP/3 requests with a masquerade. Compatible with sing-box hysteria2 and the official Hysteria 2.

TLS (the tls block) is required on both sides, the ALPN is h3. The shared QUIC fields are in quic.md.

Inbound ​

FieldTypeDefaultMeaning
userslist of {name, password}—The users' passwords
up_mbps, down_mbpsnumber0The server's speed to and from the client, Mbit/s; 0 means no limit (BBR)
ignore_client_bandwidthboolfalseIgnore the speed the client declares
obfsblock {salamander: {password}} or {gecko: {…}}—Packet obfuscation, see below; the kind is the key, a type field is an error
masqueradeblock or stringa 404 answerWhat to answer to foreign HTTP/3 requests
bbr_profilestandard, conservative, aggressivestandardBBR tuning while the speed is not negotiated, see below
brutal_debugboolfalseWrite the share of acknowledged Brutal packets to the log (debug level)

Socket settings are the listener block (the server listens on UDP).

masquerade is one of three:

yaml
# a fixed answer
masquerade:
  type: string
  status_code: 200          # 200 by default
  headers:
    content-type: text/html
  content: "<html>hello</html>"

# the files of a directory, like Go's http.FileServer
masquerade:
  type: file
  directory: /var/www       # $VAR is expanded; a directory that does not exist gives 404 answers

# a reverse proxy to a site
masquerade:
  type: proxy
  url: https://www.example.com/
  rewrite_host: false       # true sends the site's Host instead of the one the client sent

A URL string is the short form: masquerade: file:///var/www is type: file, masquerade: https://… is type: proxy.

type: file serves a file, the index.html of a directory or a directory listing; a directory without a trailing / and …/index.html are redirected (301). Last-Modified, If-Modified-Since and a single Range are supported; several ranges give the whole file. The content type comes from the extension (Go's built-in table) or the first bytes.

type: proxy goes to the site directly, bypassing routing, over HTTP/1.1, trusting the system root certificates. The client's path and query are appended to url; connection headers and X-Forwarded-* are dropped. The request body is up to 1 MiB. If the site is unavailable, 502.

Outbound ​

FieldTypeDefaultMeaning
serverhost:portrequiredThe server address; the port can be omitted with hop
hopblock—Port hopping: ports — a list of "port" or "start:end"; interval — how often to change the port, 30s by default, no less than 5s; interval_max — the upper bound of a random interval, interval by default. The sing-box names (server_ports, hop_interval) are an error with a hint
passwordstringrequiredThe password
up_mbps, down_mbpsnumber0The client's speed; 0 means BBR
obfsblock {salamander: {password}} or {gecko: {…}}—Obfuscation, as on the server
networktcp, udp or a listbothWhat to pass
bbr_profilestandard, conservative, aggressivestandardAs on the server
brutal_debugboolfalseAs on the server
disable_chrome_parrotboolfalsetrue gives an ordinary QUIC handshake (rustls) instead of a Chrome-like one

Blocks: tls (required), dial.

A Chrome-like handshake ​

By default the client imitates Chrome's QUIC handshake, as sing-box does with ChromeParrot. This overrides the windows, stream limits, idle timeout and initial_packet_size from quic, and the versions, ciphers and groups from tls; alpn, sni, disable_sni, certificate verification and the client certificate still apply. There is no session resumption or 0-RTT. disable_chrome_parrot: true turns this off.

Obfuscation ​

salamander: {password} — each packet is XORed with a key derived from the password and a random salt.

gecko: {password, min_packet_size, max_packet_size} — Salamander, and in addition the handshake packets (QUIC long header) are cut into 2–8 pieces, each padded with random bytes to a random size from [min_packet_size, max_packet_size] and sent as a separate datagram. The defaults are 512 and 1200; 0 < min ≤ max ≤ 2048 is allowed. The sizes may differ between the sides: the receiver neither knows nor checks them. The password is the same on both sides.

yaml
obfs:
  gecko:
    password: obfs-secret
    min_packet_size: 600
    max_packet_size: 1100

Congestion control ​

Until the sides agree on a speed (or if one of them has not set up_mbps/down_mbps), BBR works. bbr_profile changes its gains and the length of the startup the same way as the reference implementation's profiles:

ProfileStartup gainWindow during startupWindow afterwardsRounds without growth before startup ends
standard2.8852.8852.03
conservative2.251.751.752
aggressive3.02.252.54

After the speed is negotiated, Brutal works; brutal_debug: true writes … [brutal] ACK rate: … lines every two seconds at the debug level, as the reference does.

Not supported ​

  • realm (on both sides) — realm: not implemented.

Example ​

yaml
inbounds:
  hy2-in:
    hysteria2:
      listen: ":443"
      up_mbps: 500
      down_mbps: 500
      users:
        - name: alice
          password: secret
      obfs:
        salamander:
          password: obfs-secret
      masquerade:
        type: file
        directory: /var/www
      tls:
        certificate_path: /etc/ours/cert.pem
        key_path: /etc/ours/key.pem
outbounds:
  hy2-out:
    hysteria2:
      server: hy.example.com:443
      hop:
        ports: ["20000:20100"]
        interval: 30s
      password: secret
      up_mbps: 50
      down_mbps: 200
      obfs:
        salamander:
          password: obfs-secret
      tls:
        sni: hy.example.com
route:
  final:
    outbound: hy2-out

Module description for developers: modules/hysteria2.

GPL-3.0-or-later