AmneziaWG server

This page sets up AmneziaWG on Ubuntu 24.04 for the app: our fork of amneziawg-go as the engine (the engine the app runs too) and the awg tools from the Amnezia packages, the server's keys and its own obfuscation values, its interface awg0, forwarding and NAT so the phones reach the internet through it, a configuration file for each phone that the app imports, and removing a phone again. Its last part sets up the profile in the app, on iPhone and on Android.

Where this page comes from

We ran these steps on our test server, Ubuntu 24.04 with Linux 6.8, 4 vCPUs and 4 GB of memory, on 9 November 2026, as the page shows them, with our server's name in place of vpn.example.com: the Amnezia packages gave us amneziawg-tools 3.1.20260812, Go fetched version 1.25.0 for the build, and the last line of part 1 printed amneziawg-go v3.1.20260828-srp.1. Then both phones connected with the page's phone1.conf, and phone2, removed as part 5 says, was refused (the awg-guide-… cases in Test results). Three things ran differently: our server had the kernel module before, and moved to our fork the same morning with the same commands, after apt purge amneziawg amneziawg-dkms and rmmod amneziawg instead of a restart, so part 1 found its packages already there; the ufw line of part 3 was not run, as ufw is not active on our server; and part 5 removed phone2, which we had added with part 4's script for that. After systemctl restart awg-quick@awg0 the server still had phone1 and its obfuscation values, as SaveConfig = true keeps them.

What you need

1. Install

apt update
apt install -y software-properties-common
add-apt-repository -y ppa:amnezia/ppa
apt install -y amneziawg-tools golang-go git make
rm -rf /usr/local/src/amneziawg-go
git clone --branch v3.1.20260828-srp.1 --depth 1 https://github.com/bigmoveus/amneziawg-go /usr/local/src/amneziawg-go
cd /usr/local/src/amneziawg-go
GOTOOLCHAIN=auto make
make install
/usr/bin/amneziawg-go --version

2. The server's keys and obfuscation values

cd /etc/amnezia/amneziawg
umask 077
awg genkey | tee server.key | awg pubkey > server.pub
awg genkey > header.key
S1=$(shuf -i 15-150 -n 1); S2=$(shuf -i 15-150 -n 1); S3=$(shuf -i 15-150 -n 1); S4=$(shuf -i 15-40 -n 1)
[ "$S2" -eq $((S1 + 56)) ] && S2=$((S2 + 1))
h() { start=$(( $1 * 1073741824 + $(shuf -i 5-1000000000 -n 1) )); echo "$start-$(( start + 50000000 ))"; }
cat > /etc/amnezia/amneziawg/awg0.conf <<EOF
[Interface]
Address = 10.67.67.1/24
ListenPort = 51820
PrivateKey = $(cat /etc/amnezia/amneziawg/server.key)
S1 = $S1
S2 = $S2
S3 = $S3
S4 = $S4
H1 = $(h 0)
H2 = $(h 1)
H3 = $(h 2)
H4 = $(h 3)
HeaderProtectionKey = $(cat /etc/amnezia/amneziawg/header.key)
MTU = $((1420 - S4))
SaveConfig = true
PostUp = iptables -I FORWARD 1 -i %i -j ACCEPT; iptables -I FORWARD 2 -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.67.67.0/24 -o ens160 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.67.67.0/24 -o ens160 -j MASQUERADE
EOF
echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/60-amneziawg.conf
sysctl -p /etc/sysctl.d/60-amneziawg.conf
systemctl enable --now awg-quick@awg0
awg show awg0

awg show prints the interface with its public key, listening port: 51820 and its obfuscation values.

3. Firewall

Open UDP port 51820 to the phones. If ufw is active: ufw allow 51820/udp. The PostUp rules of part 2 already let the phones' traffic through.

4. A file for each phone

Each phone gets its own key pair and its own preshared key, which adds a second secret to the handshake. This script makes them, adds the phone to awg0 and writes the file the app imports, with the server's obfuscation values and three of the phone's own: Jc junk packets of Jmin to Jmax random bytes that the phone sends before every handshake. Save it as /etc/amnezia/amneziawg/add-phone.sh and put your server's name or address in endpoint=:

#!/bin/bash
# add-phone.sh NAME NUMBER: a key pair and a preshared key for the phone NAME, its peer on awg0 with the address
# 10.67.67.NUMBER, and /etc/amnezia/amneziawg/clients/NAME.conf, the file the app imports.
set -euo pipefail
name=$1; number=$2; endpoint=vpn.example.com:51820
cd /etc/amnezia/amneziawg
umask 077
mkdir -p clients
private=$(awg genkey); public=$(echo "$private" | awg pubkey); psk=$(awg genpsk)
echo "$public" > "clients/$name.pub"
awg set awg0 peer "$public" preshared-key <(echo "$psk") allowed-ips "10.67.67.$number/32"
awg-quick save awg0
cat > "clients/$name.conf" <<EOF
[Interface]
PrivateKey = $private
Address = 10.67.67.$number/32
DNS = 1.1.1.1, 8.8.8.8
Jc = 4
Jmin = 40
Jmax = 70
$(grep -E '^(S[1-4]|H[1-4]|HeaderProtectionKey|MTU) = ' awg0.conf)

[Peer]
PublicKey = $(cat server.pub)
PresharedKey = $psk
Endpoint = $endpoint
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
EOF
echo "/etc/amnezia/amneziawg/clients/$name.conf"
chmod 700 /etc/amnezia/amneziawg/add-phone.sh
/etc/amnezia/amneziawg/add-phone.sh phone1 2

5. Removing a phone

This script takes a phone off awg0 at once and out of the saved configuration; save it as /etc/amnezia/amneziawg/remove-phone.sh:

#!/bin/bash
# remove-phone.sh NAME: the phone NAME off awg0 and out of awg0.conf, and its files deleted.
set -euo pipefail
name=$1
cd /etc/amnezia/amneziawg
awg set awg0 peer "$(cat "clients/$name.pub")" remove
awg-quick save awg0
rm -f "clients/$name.pub" "clients/$name.conf"
chmod 700 /etc/amnezia/amneziawg/remove-phone.sh
/etc/amnezia/amneziawg/remove-phone.sh phone2

The server answers nothing to a key it does not know, so a removed phone cannot connect: the app waits for the handshake and then reports that the server did not answer it.

6. Check

awg show awg0

Each phone is a peer with its allowed ips. A phone that connected has an endpoint (the address it came from), a latest handshake (renewed every 2 minutes while traffic flows) and its transfer.

7. Set up the app on the phone

An AmneziaWG profile has the same fields on iPhone and Android; where the two phones differ, the steps say so. Install the app first: on iPhone from TestFlight (Installation), on Android by building it from the source (Installation). Where to start says which build to use.

Create the profile

  1. Copy /etc/amnezia/amneziawg/clients/phone1.conf, the file part 4 made, to the phone.
  2. On the home screen, tap +.
  3. Tap Protocol and choose AmneziaWG VPN.
  4. Description: optional, the profile's name on the home screen. When it is empty, the home screen shows the server's name or address.
  5. Tap Import Config (.conf). It opens the phone's files: choose phone1.conf. The row then says Imported, and Server and Port fill themselves in from the file's Endpoint line: the name or address you put in endpoint=, and 51820. The file also brings the phone's keys, the server's obfuscation values of part 2 and the phone's Jc, Jmin and Jmax, so leave Manual Configuration as it is: its row says Overridden by import.
  6. Leave everything under Options as it is, and tap Save.
  7. Delete the copies of phone1.conf you do not need, as part 4 says: the app keeps the file, on iPhone in the Keychain and on Android in its encrypted store.
Protocol screen on iPhone with AmneziaWG VPN ticked
Choosing AmneziaWG, on iPhone.
The same Protocol screen on Android
The same screen on Android.
Profile editor on iPhone with an imported configuration: Import Config Imported, Server and Port 51820
A profile with an imported file, on iPhone.
The same profile on Android
The same on Android.
Options section on iPhone: Auto Reconnect, Retry Times, On Sleep and Log Level
The options, on iPhone.
The same options on Android
The same on Android.

Connect

  1. Select the profile on the home screen and tap the power button.
  2. The first time, the system asks for permission: iOS asks whether the app may add a VPN configuration, and Android shows a Connection request. Allow it.
  3. The status changes to Connected once the server has answered the handshake, and the row of the profile then shows the time of one request through the tunnel.
Check On the server, run awg show awg0 as in part 6: the peer whose allowed ips are 10.67.67.2/32, the address part 4 gave phone1, now has an endpoint, a latest handshake and its transfer. If the app shows Connection Failed instead, tap the status under the power button to open the log, and see Troubleshooting, which explains each message.

Setting up the app describes every field.