Your own AmneziaWG server

AmneziaWG is WireGuard with obfuscation: packet headers are changed and junk packets go in between. It is just as fast and installs on a Linux VPS — by hand or from an app over SSH. Give the server 1 GB of memory or more: AmneziaWG builds a module for the kernel.

Updated

On this page

How it differs from WireGuard

Inside it is the same WireGuard: fast and simple. The difference is on the outside: the packets are changed, so AmneziaWG gets through where plain WireGuard is already recognized.

Where filtering is serious, it gets found over time. Then a protocol that looks like an ordinary website to your ISP is the better pick: VLESS Reality or Veli.

How to install it by hand

Below is the setup on Ubuntu as root from the Amnezia project's official PPA. The amneziawg package builds the kernel module and installs the awg and awg-quick tools.

  1. 1

    Take a server with spare memory

    AmneziaWG builds a module for the server's kernel. With 1 GB of memory and no swap that takes 5–10 minutes, and with less it may not build.

  2. 2

    Turn on package sources

    The build needs source packages from APT. /etc/apt/sources.list must have a deb-src line with no # in front. On Ubuntu 24.04 the settings are in /etc/apt/sources.list.d/ubuntu.sources: change the line Types: deb to Types: deb deb-src.

  3. 3

    Install what the build needs

    Command:

    On the server
    apt update &&
      apt install -y software-properties-common python3-launchpadlib gnupg2 linux-headers-$(uname -r)
  4. 4

    Install AmneziaWG

    Commands:

    On the server
    add-apt-repository ppa:amnezia/ppa

    Then apt install -y amneziawg. On Debian the same PPA is added by hand: the commands are in the README of the amneziawg-linux-kernel-module project on GitHub.

  5. 5

    Create the keys

    Commands:

    On the server
    mkdir -p /etc/amnezia/amneziawg &&
      cd /etc/amnezia/amneziawg

    Then umask 077, then

    On the server
    awg genkey | tee server.key | awg pubkey > server.pub

    Do the same for each device:

    On the server
    awg genkey | tee phone.key | awg pubkey > phone.pub
  6. 6

    Write awg0.conf

    File: /etc/amnezia/amneziawg/awg0.conf. A sample is in the next section.

  7. 7

    Turn on forwarding

    Commands:

    On the server
    echo net.ipv4.ip_forward=1 > /etc/sysctl.d/99-awg.conf

    Then sysctl --system. Without it a device connects but doesn't reach the internet.

  8. 8

    Open the port

    If ufw is on: ufw allow 51820/udp. With ufw, forwarding is needed too: in /etc/default/ufw set DEFAULT_FORWARD_POLICY="ACCEPT" and run ufw reload. If the host has a firewall in its dashboard, open the UDP port there too.

  9. 9

    Start it

    Command: awg-quick up awg0. Check: awg show lists the interface and connected devices. To start it after a reboot:

    On the server
    systemctl enable awg-quick@awg0
  10. 10

    Make a file for each device

    An AmneziaWG profile is a .conf file. Each device gets its own: one key on two devices at the same time does not work. A sample is below.

The server file awg0.conf

Replace SERVER_PRIVATE_KEY with the contents of server.key and PHONE_PUBLIC_KEY with the contents of phone.pub. eth0 is the server's outside interface: ip route shows its name after the word dev in the default line. If there is no iptables: apt install -y iptables.

Pick your own H1–H4: four different numbers from 5 to 2147483647. Port 51820 can be any free UDP port.

awg0.conf
[Interface]
PrivateKey = SERVER_PRIVATE_KEY
Address = 10.8.0.1/24
ListenPort = 51820
Jc = 4
Jmin = 8
Jmax = 80
S1 = 40
S2 = 70
H1 = 1376029114
H2 = 2052410238
H3 = 908143527
H4 = 1610284493
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
[Peer]
PublicKey = PHONE_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32

The device file

PHONE_PRIVATE_KEY is the contents of phone.key, SERVER_PUBLIC_KEY is the contents of server.pub, IP is the server address. Copy the Jc–H4 lines from the server as they are.

The next device is one more [Peer] on the server with its own key and the address 10.8.0.3/32, then 10.8.0.4/32 and on. After editing: awg-quick down awg0, then awg-quick up awg0.

The device file
[Interface]
PrivateKey = PHONE_PRIVATE_KEY
Address = 10.8.0.2/32
DNS = 1.1.1.1
Jc = 4
Jmin = 8
Jmax = 80
S1 = 40
S2 = 70
H1 = 1376029114
H2 = 2052410238
H3 = 908143527
H4 = 1610284493
[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

What the masking settings mean

  • Jc — how many junk packets go out before the handshake: from 1 to 128, usually 4–12.
  • Jmin and Jmax — the smallest and largest junk packet size in bytes. Usually 8 and 80; Jmax is at most 1280.
  • S1 and S2 — how many random bytes are added to the handshake packets: S1 to the first one, S2 to the reply. Usually 15–150, and S1 + 56 must not equal S2.
  • H1–H4 — your own markers in place of the headers of the four WireGuard packet types. Four different numbers from 5 to 2147483647.
  • S1, S2 and H1–H4 must match on the server and the device. Jc, Jmin and Jmax may differ.

If the install does not go through

  • Not enough memory — take a bigger plan or a protocol with no build, such as Veli or VLESS Reality.
  • An error about the package mirror — that is the host's server. Try again later or pick another mirror in the hosting panel.
  • Short of disk space — free some on the server and try again.

In Veli

AmneziaWG from the app

In Veli: Profiles → Add → “Your own server”, the server's address and password, “Add the server”. On the server screen select AmneziaWG and click the install button. If the server already has a protocol, the “Add a protocol” tile opens the “New protocol” window: AmneziaWG goes next to it without touching the ones already there.

While the module builds, the line under the step says what the server is waiting for. A profile for this computer appears on its own, and “Add a device” gives a QR code and a link for a phone or another computer. Each device has its own client: you can delete it without affecting the others.

FAQ

AmneziaWG or VLESS Reality?

AmneziaWG is fast like WireGuard. VLESS Reality looks like an ordinary website from the outside and works better where filtering is serious. The choice depends on the network, not taste.

Why does the AmneziaWG install take long?

It builds a module for the server's kernel: with 1 GB of memory and no swap that takes 5–10 minutes. On top of that, a fresh server installs its system updates in its first minutes.

Can AmneziaWG run next to other protocols?

Yes. One server can run Veli, VLESS Reality, AmneziaWG, WireGuard, Shadowsocks and OpenVPN.

AmneziaWG without building it by hand

Veli builds the module on the server, shows what the install is waiting for and gives each device its own profile.