Skip to content

wireguard ​

A WireGuard endpoint is the endpoints section, as in sing-box 1.11+. One object is both an outbound (in routing, to: {outbound: wg}) and an inbound (the condition inbound: wg): connections the peers open through the tunnel to foreign addresses go through routing as if they came from an inbound.

yaml
endpoints:
  wg:
    wireguard:
      address: [10.0.0.2/32, fd00::2/128]
      private_key: <base64>
      listen_port: 51820          # without it the system chooses the port
      mtu: 1408                   # the default
      peers:
        - address: vpn.example.com
          port: 51820
          public_key: <base64>
          pre_shared_key: <base64>
          allowed_ips: [0.0.0.0/0, ::/0]
          persistent_keepalive_interval: 25
          reserved: [0, 0, 0]     # Cloudflare WARP bytes
    dial:                         # the socket to the peers
      interface: eth0
outbounds:
  direct:
    direct:
route:
  rules:
    - match: {inbound: wg}
      to: {outbound: direct}
  final:
    outbound: wg

The fields are as in sing-box (name is the interface name, wg-<name> by default). Hostnames in peers[].address are resolved by the system resolver when the endpoint is built. Extensions:

  • mode: userspace (default) — its own implementation on a TUN device; kernel — an interface of the wireguard or amneziawg kernel module (kmod-wireguard / kmod-amneziawg on OpenWrt), without wg/awg; auto — kernel if the module is there and can handle the configuration, otherwise userspace (the choice is written to the log). The modules cannot handle reserved, dial.interface, dial.detour and ciphers other than chacha20-poly1305: with mode: kernel these are a configuration error.
  • dial.detour: <outbound>: datagrams to the peers go through the packet connection of this outbound (for example, socks or shadowsocks), as in sing-box. The endpoint's socket then listens only on loopback, listen, listen_port and dial.interface have no effect, and a peer without address is reachable only if it came through the outbound itself. Userspace only.
  • awg: AmneziaWG obfuscation (see below), in any mode.
  • ciphers: transport ciphers by priority, negotiated in the handshake (see below), userspace only.

awg and ciphers are in the default build; in a build without the wireguard-awg / wireguard-ciphers features they are a configuration error (except a zero awg block and ciphers: [chacha20-poly1305]), not a silent fallback to plain WireGuard.

ICMP from peers to foreign addresses is not forwarded (ping does not go further through the tunnel); the kernel answers for the endpoint's own addresses.

awg ​

The AmneziaWG 3.1 protocol, as in amneziawg-go 3.1.20261116 and the amneziawg kernel module 3.1.20261113; the parameter sets of AmneziaWG 1.x (jc…s2, h1–h4 as numbers) and 2.0 (plus s3, s4, h ranges, i1–i5) are subsets of it. The names are as in the awg/UAPI configuration. Without the block, or with zeros, it is plain WireGuard on the wire.

fieldwhat it doesside
jc, jmin, jmaxjc junk datagrams of length jmin…jmax before each initiationown
i1–i5signature datagrams before the junk, made of tags: <b 0x…> bytes, <r N> random, <rc N> letters, <rd N> digits, <t> time (4 bytes BE), <c> counter (as in the kernel module), <d>, <ds>, <dz N> (as in amneziawg-go: empty / N zeros); text outside <…> is ignoredown
s1–s4random bytes before the initiation, the response, the cookie and transport messagesboth
h1–h4the message type: a number or a range N-M (a random value for each message); the ranges do not overlap; MAC1 is computed over the written valueboth
header_protection_keyheader protection (3.x): 32 bytes, base64 (awg genkey) or 64 hex; XOR with a ChaCha20 keystream with a nonce from the first 12 bytes of the prefix — the whole message for handshakes, the 16-byte header for transport; needs s1–s4 ≥ 12both
random_trailersa random tail after handshakes and zeros inside the transport ciphertext, within the largest datagram seen from the peerboth
content_padding_additionN-M zeros inside the transport ciphertext instead of alignment to 16 (takes precedence over random_trailers)own
disable_cookiesdo not answer with a cookie and do not check MAC2 under loadown
rekey_after_time, rekey_timeout, reject_after_time, keepalive_timeout, max_handshake_attemptsWireGuard timers, seconds (a number or a range; the value is drawn each time the timer is set)own

The peer's persistent_keepalive_interval also accepts a range N-M (AmneziaWG 3). The s4 bytes go before every transport message: mtu must leave room for them (as in amneziawg-go, a datagram longer than the path is not sent).

yaml
endpoints:
  wg:
    wireguard:
      awg:
        jc: 4
        jmin: 40
        jmax: 70
        s1: 15
        s2: 18
        s3: 20
        s4: 24
        h1: 1000-1100
        h2: 2000-2100
        h3: 3000-3100
        h4: 4000-4100
        i1: <b 0xc0ffee><r 16><t>
        header_protection_key: <base64>
      # ...

mode: kernel needs the amneziawg module; it cannot handle (an error in kernel, userspace in auto): the tags <d>, <ds>, <dz>, <b> without 0x, an argument to <t>/<c>, timer values, content_padding_addition and keepalive above 65535. A peer keepalive range also requires the amneziawg module. A peer's reserved with awg is an error: the message type takes all four bytes.

ciphers ​

Tunnel data can be encrypted not only with ChaCha20-Poly1305 but also with AES-GCM-128 or AES-GCM-256. The cipher is chosen in the handshake by the scheme of an amneziawg-go fork with AES-GCM support (its Ciphers = …) and is compatible with it in both directions. The handshake itself stays Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s, and the message sizes do not change.

yaml
endpoints:
  wg:
    wireguard:
      ciphers: [aes-gcm-256, chacha20-poly1305]
      # ...
  • Names: chacha20-poly1305, aes-gcm-128, aes-gcm-256; one to three, without repeats. The order is the priority.
  • The first cipher in the initiator's list that the responder has wins: on each side, a session it started itself goes by its own priority. A peer that cannot negotiate (wireguard-go, the kernel, sing-box, amneziawg-go without the fork) counts as offering only chacha20-poly1305. With no common cipher the handshake is rejected: without chacha20-poly1305 in the list such peers will not connect.
  • The negotiation is hidden inside the encrypted handshake fields; to a vanilla peer the handshake looks normal.
  • Without ciphers: [chacha20-poly1305, aes-gcm-256] (the fork's default) if the processor has AES instructions (AES-NI and PCLMULQDQ on x86, AES and PMULL on ARMv8), and [chacha20-poly1305] if not. With ChaCha20 first, the endpoint never asks a peer for AES; it uses AES-GCM-256 only when the peer asks for it first and the local CPU has AES instructions. With AES in the list the initiation carries the list's tag inside the encrypted timestamp: indistinguishable from outside, vanilla peers do not notice it, but only [chacha20-poly1305] matches vanilla byte for byte. A list with AES on a processor without its instructions works, but a warning is written to the log.
  • Recommendation: on x86-64 and ARMv8 with AES instructions, if the peer is the same, [aes-gcm-128, aes-gcm-256, chacha20-poly1305] (AES-GCM-128 is the first 16 bytes of the KDF key, cheaper than AES-GCM-256 in rounds); on MIPS, ARMv7 and others without AES, no ciphers or [chacha20-poly1305]. chacha20-poly1305 at the end of the list keeps compatibility with vanilla peers.
  • mode: kernel with a cipher other than chacha20-poly1305 is a configuration error, and auto picks userspace (the kernel modules know only ChaCha20; the fork's module is not used). Without ciphers, kernel and auto work: the kernel module simply does not negotiate, and the peers end up with ChaCha20.
  • Works with awg: the negotiation lives inside the encrypted fields and does not depend on what the packets look like on the wire (with the fork, its AWG parameters that it knows).
  • The chosen cipher is written to the log at the debug level: peer N: session with aes-gcm-256.

Differences from the fork ​

The forkours
Kernelits own amneziawg-linux-kernel-module with AES-GCMthe kernel modules do not negotiate: mode: kernel with AES is a configuration error, auto picks userspace
Changing the list at runtimesessions survive, the list applies from the next handshakea reload rebuilds the endpoint, the peers handshake again

config_file ​

A path to an ordinary wg/awg file (wg0.conf, awg0.conf; a relative one is taken from the process's working directory, -D). The file is the source of everything it can express; the endpoint keeps what never occurs in the file (mode, listen, public_endpoint, name, udp_*, workers, the dial block).

yaml
endpoints:
  wg:
    wireguard:
      config_file: /etc/amnezia/amneziawg/awg0.conf
      mode: auto
      listen: auto
in the fileendpoint field
[Interface] PrivateKey, ListenPort, Address (several lines allowed), MTUprivate_key, listen_port, address, mtu
Jc, Jmin, Jmax, S1–S4, H1–H4, I1–I5, HeaderProtectionKey, ContentPaddingAddition, RandomTrailers, DisableCookies, RekeyAfterTime, RekeyTimeout, RejectAfterTime, KeepaliveTimeout, MaxHandshakeAttemptsthe awg block
Ciphers (as in the amneziawg-go fork)ciphers
[Peer] PublicKey, PresharedKey, AllowedIPs, Endpoint, PersistentKeepalive; the comment # Name = …peers[] (name, public_key, …)
  • Keys are case- and _-insensitive: header_protection_key (as in UAPI) = HeaderProtectionKey.
  • An endpoint field that the file also sets (private_key, listen_port, address, mtu, ciphers, awg, peers) has no effect: a warning for each is written to the log.
  • PreUp/PostUp/PreDown/PostDown (the commands are never run), DNS, Table, SaveConfig, FwMark are skipped with a warning. An unknown key, section or bad value is a configuration error of the form <file>:<line>: ….
  • The file is reread on every configuration load (SIGHUP, --watch on the YAML, the Admin API): a changed file rebuilds the endpoint. --watch does not watch the file itself.
  • Clients added through ours client or the dashboard are appended to the end of the file as a [Peer] section (a temporary file and rename); the rest of the text and the comments are not touched. If the file cannot be written, adding clients is disabled with an error.

UDP of the peers' connections ​

udp_timeout is the lifetime of such a UDP flow without packets (5m by default). udp_mapping, udp_filtering and udp_nat_max are the mapping, filtering and max_flows of the nat block of tproxy (the default for udp_nat_max is 4096).

system, on_demand and workers are accepted for compatibility with sing-box and have no effect: the interface is chosen by mode.

listen ​

On which addresses the peers' datagrams are accepted (an ours extension):

  • auto (default) — the WAN addresses: of the interfaces through which the default routes of the main table go, separately for IPv4 and IPv6, all WANs at once. A change of route or address (a PPPoE reconnect) is applied by itself. With no default route in either family, everything is accepted, with a warning; with none for one family, that family's datagrams are dropped.
  • all — all addresses of the host (as sing-box and wg do).
  • an interface name (eth1, pppoe-wan) — only what came through it.
  • an address (203.0.113.7, 2001:db8::1) — only to it.

Peers from the local network will not connect with auto: they send to the LAN address, not the WAN one. For them, use listen: all (or the name of the LAN interface). The endpoint warns at start and whenever the WAN changes, naming the host's addresses that auto drops peers' datagrams to (loopback, link-local and the tunnel's own addresses aside).

In every listen mode, and in both userspace and kernel, the socket listens on all addresses (the kernel module cannot do otherwise); the restriction is the nftables table inet ours-wg-listen-<interface>: its input chain drops UDP to the endpoint's port on addresses that are not allowed. So a change of the WAN address is a replacement of rules, not a new socket: the peers' sessions survive it. With listen: all there is no table. CAP_NET_ADMIN is needed (it is needed anyway).

public_endpoint ​

The address clients get (ours client, the dashboard): host:port, host (the port is listen_port) or auto (default) — the WAN address, public before private, IPv4 before IPv6. If it is private or CGNAT (100.64.0.0/10), the client gets it anyway, with a warning: such an address is not visible from outside. It does not affect how the endpoint works.

Routes and kernel mode ​

CAP_NET_ADMIN is needed. Routes to the peers' allowed_ips are added with the lowest priority and do not override the system's routes. In kernel mode the peers' connections to foreign addresses are brought into routing through nftables tproxy: the process adds the table inet ours-wg-<interface>, an ip rule with priority 103 (mark 0x4000000, table 0x7767) and the route local default dev lo in that table, and removes them on stop; the peers' requests to the host's own addresses go straight to the host. Details are in modules/wireguard. Differences from sing-box are in differences/protocols.

GPL-3.0-or-later