Networking Azure

WireGuard VPN on Ubuntu 26.04 LTS on Azure User Guide

| Product: WireGuard VPN on Ubuntu 26.04 LTS on Azure

Overview

This guide covers deploying and using WireGuard VPN on Ubuntu 26.04 LTS on Azure from cloudimg's Azure Marketplace image. WireGuard is a modern, fast VPN that runs in the Linux kernel. It uses Curve25519 for key exchange and ChaCha20-Poly1305 for encryption, and presents a single UDP listener configured by one small file: no certificates, no PKI and no IPsec daemon.

The image installs WireGuard from Ubuntu 26.04's own repositories: wireguard-tools 1.0.20250521 (the wg and wg-quick tools) and the wireguard metapackage. The WireGuard kernel module ships in the Ubuntu 26.04 Azure kernel, so there is no DKMS module and no outside repository. On the first boot of every VM, wireguard-firstboot.service generates a fresh server key pair, writes /etc/wireguard/wg0.conf (mode 0600, root only), starts wg-quick@wg0, records the VM's public IP address from Azure as the endpoint peers dial, and writes the server public key and connection details to /stage/scripts/wireguard-credentials.log. The private key is never written anywhere but wg0.conf.

The server starts with no peers. The wg-peers helper adds a client in one command: it picks the next free address in the 10.50.0.0/24 overlay (the server is 10.50.0.1), applies the peer live without dropping other tunnels, and prints the client's configuration. IP forwarding is on; NAT for full-tunnel internet access is in wg0.conf but commented out, so you turn it on deliberately (Step 10).

What is included:

  • WireGuard (wireguard-tools 1.0.20250521 and the wireguard metapackage) from Ubuntu 26.04's repositories, with the in-kernel WireGuard module

  • wireguard-firstboot.service, which generates a per-VM server key pair on the first boot, writes /etc/wireguard/wg0.conf and starts wg-quick@wg0

  • /etc/wireguard/wg0.conf with the server on 10.50.0.1/24, listening on UDP 51820, and commented examples of a peer block and the NAT rules

  • wg-quick@wg0.service, enabled so the tunnel comes up on every boot

  • The wg-peers helper (also installed as cloudimg-wireguard): add-peer, remove-peer, list and endpoint

  • A login banner that shows the endpoint peers dial

  • IP forwarding (net.ipv4.ip_forward=1, net.ipv6.conf.all.forwarding=1) in /etc/sysctl.d/99-wireguard.conf

  • The server's public key and connection details in /stage/scripts/wireguard-credentials.log (mode 0600, root only)

  • Ubuntu 26.04 LTS, fully patched at build time, with unattended security updates on

  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

Prerequisites

  • An active Azure subscription

  • An SSH public key for VM authentication

  • A virtual network and subnet in the target region (the portal can create them for you)

  • WireGuard on each client device: the official WireGuard app on Windows, macOS, iOS or Android, or the wireguard-tools package on Linux

Recommended virtual machine size: Standard_B2s (2 vCPU, 4 GiB RAM). WireGuard is very light; a B2s carries a small team or a branch office comfortably. For many active peers or sustained site-to-site traffic, choose a larger general purpose size with accelerated networking.

Step 1: Deploy from the Azure Portal

In the Azure Portal, open Marketplace, search for WireGuard VPN on Ubuntu 26.04, select the cloudimg entry and click Create. On Basics choose your subscription, resource group, region and size, and set the administrator user name and SSH public key.

The Basics tab's inbound port list only offers TCP ports, so allow SSH (22) there, then add the WireGuard rule: on the Networking tab create a network security group with an inbound rule for UDP 51820, or add it once the VM exists: open the VM, choose Networking > Network settings > Create port rule > Inbound port rule, set Destination port ranges 51820, Protocol UDP, Action Allow, and narrow Source to your peers' networks if you know them. WireGuard does not answer packets from unknown keys, so an open UDP 51820 reveals nothing, but a narrower rule is better practice. Narrow the SSH rule to your own address range.

Without the UDP rule the server looks healthy, but no peer can connect: the client shows the tunnel as on and no handshake ever completes.

Click Review + create, then Create. Deployment takes about two minutes. Note the VM's Public IP address on its Overview page: it is the address you SSH to and the endpoint every peer dials. The VM itself sees only its private VNet address on eth0; first boot reads the public one from Azure and records it for you (Step 4).

Step 2: Deploy from the Azure CLI

RG="wireguard-prod"
LOCATION="eastus"
VM_NAME="wireguard-01"
ADMIN_USER="azureuser"
IMAGE_URN="cloudimg1647283583153:wireguard-ubuntu-26-04:default:latest"
SSH_KEY="$(cat ~/.ssh/id_rsa.pub)"

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn "$IMAGE_URN"

az group create --name "$RG" --location "$LOCATION"

az network vnet create \
  --resource-group "$RG" \
  --name wg-vnet --address-prefix 10.96.0.0/16 \
  --subnet-name wg-subnet --subnet-prefix 10.96.1.0/24

az network nsg create --resource-group "$RG" --name wg-nsg

az network nsg rule create \
  --resource-group "$RG" --nsg-name wg-nsg \
  --name allow-ssh --priority 100 \
  --source-address-prefixes "<your-mgmt-cidr>" \
  --destination-port-ranges 22 --access Allow --protocol Tcp

az network nsg rule create \
  --resource-group "$RG" --nsg-name wg-nsg \
  --name allow-wireguard --priority 110 \
  --source-address-prefixes "<your-client-cidr-or-internet>" \
  --destination-port-ranges 51820 --access Allow --protocol Udp

az vm create \
  --resource-group "$RG" --name "$VM_NAME" \
  --image "$IMAGE_URN" \
  --size Standard_B2s \
  --admin-username "$ADMIN_USER" --ssh-key-values "$SSH_KEY" \
  --vnet-name wg-vnet --subnet wg-subnet --nsg wg-nsg \
  --public-ip-sku Standard

Read the VM's public IP address, the address you SSH to and the endpoint peers dial:

az vm show -d --resource-group "$RG" --name "$VM_NAME" --query publicIps -o tsv

Step 3: Connect with SSH

ssh azureuser@<vm-public-ip>

The login banner shows the WireGuard details, with the endpoint first boot recorded:

 WireGuard VPN: interface wg0, UDP 51820, overlay 10.50.0.0/24 (server 10.50.0.1)
 Peer endpoint: 52.186.158.16:51820
 The eth0 address is private and is not reachable from the internet.
 Add a client:  sudo wg-peers add-peer <name> --pubkey <client-public-key>   (also: list, remove-peer, endpoint)
 Server details: sudo cat /stage/scripts/wireguard-credentials.log

Step 4: Check the WireGuard service

First boot has already made this VM's key pair and started the tunnel:

sudo test -f /var/lib/cloudimg/wireguard-firstboot.done && echo FIRSTBOOT_DONE
systemctl is-active wg-quick@wg0
ip -brief addr show wg0
sudo wg show
FIRSTBOOT_DONE
active
wg0              UNKNOWN        10.50.0.1/24
interface: wg0
  public key: +rSgWiVJshc2pNDN9gPxqUnnfmnVGnDgV3YTFIoTJks=
  private key: (hidden)
  listening port: 51820

wg-quick@wg0 is a one-shot unit: systemctl status shows it active (exited) once the interface is up. The public key is this VM's own (yours will differ); wg show never prints the private key.

wg-quick@wg0 active, wg show with the listening port and this VM's public key, and the wireguard-tools version

Check the endpoint first boot recorded. It is the VM's public IP address, read from Azure's instance metadata:

sudo wg-peers endpoint
Endpoint: 52.186.158.16:51820
The eth0 address is private and is not reachable from the internet.

If the VM had no public IP at first boot, or peers should dial a DNS name, record it yourself with sudo wg-peers endpoint <ip-or-dns-name>; sudo wg-peers endpoint --detect asks Azure again.

Step 5: Read the server details

sudo cat /stage/scripts/wireguard-credentials.log

The file holds the server's public key, the endpoint, the overlay addresses and the steps to add a peer. It never holds the private key, which stays in /etc/wireguard/wg0.conf:

SERVER_PUBLIC_KEY=+rSgWiVJshc2pNDN9gPxqUnnfmnVGnDgV3YTFIoTJks=
SERVER_ENDPOINT=52.186.158.16:51820
# Peers dial SERVER_ENDPOINT. The eth0 address is private and is not reachable from the internet.
SERVER_VPN_ADDRESS=10.50.0.1/24
LISTEN_PORT=51820
SUBNET=10.50.0.0/24
SERVER_VPN_IP=10.50.0.1

The credentials file: this VM's server public key, the endpoint, the overlay addresses and how to add a peer

Step 6: Make a key pair on the client

Generate each client's key pair on the client: its private key never leaves the device.

On a Linux client:

wg genkey | tee client-priv.key | wg pubkey > client-pub.key
chmod 600 client-priv.key
cat client-pub.key

In the WireGuard app on Windows, macOS, iOS or Android, choose Add Tunnel > Add empty tunnel: the app generates the key pair and shows the Public key. Copy it.

Step 7: Add the peer on the server

Add the client with its public key. wg-peers gives it the next free overlay address, applies it live and prints the client's configuration:

sudo wg-peers add-peer alice-laptop --pubkey <client-public-key>
Added peer 'alice-laptop' as 10.50.0.2 (live on wg0).
Client configuration: save it as wg0.conf on the client (chmod 600), or paste it into the WireGuard app.
# alice-laptop
[Interface]
PrivateKey = <the client private key that matches bNdpPIYCJD1aSDz6sWEidORDX0hd81TH81aQm5XjhDY=>
Address = 10.50.0.2/32

[Peer]
PublicKey = +rSgWiVJshc2pNDN9gPxqUnnfmnVGnDgV3YTFIoTJks=
Endpoint = 52.186.158.16:51820
AllowedIPs = 10.50.0.0/24
PersistentKeepalive = 25

List the peers, with each one's latest handshake:

sudo wg-peers list

wg-peers add-peer assigning 10.50.0.2 and printing the client configuration, then wg-peers list

Remove a peer (a lost device, a leaver) with sudo wg-peers remove-peer <name>; it is dropped live and its block removed from wg0.conf.

To add a peer by hand instead, append a block to /etc/wireguard/wg0.conf and reload; the reload applies the change without dropping other tunnels:

[Peer]
# Name = alice-laptop
PublicKey = <client-public-key>
AllowedIPs = 10.50.0.2/32
sudo systemctl reload wg-quick@wg0

Step 8: Configure the client and connect

Put the printed configuration on the client, replacing the PrivateKey line with the client's own private key. On a Linux client, in the directory where you ran Step 6:

sudo install -d -m 0700 /etc/wireguard
sudo tee /etc/wireguard/wg0.conf > /dev/null << EOF
[Interface]
PrivateKey = $(cat client-priv.key)
Address = 10.50.0.2/32

[Peer]
PublicKey = <server-public-key>
Endpoint = <vm-public-ip>:51820
AllowedIPs = 10.50.0.0/24
PersistentKeepalive = 25
EOF
sudo chmod 600 /etc/wireguard/wg0.conf
sudo wg-quick up wg0
ping -c 3 10.50.0.1

In the WireGuard app, paste the Address line and the whole [Peer] block into the tunnel you created in Step 6 (the app already holds the private key), then activate it.

Once connected, sudo wg-peers list on the server shows the peer's latest handshake, and sudo wg show shows its endpoint and transfer counters. Set AllowedIPs = 0.0.0.0/0 on the client to send all its traffic through the VPN, after turning on NAT on the server (Step 10).

Step 9: Network settings

ip -brief addr show wg0
ss -ulnH | grep ':51820 '
sysctl net.ipv4.ip_forward net.ipv6.conf.all.forwarding
wg0              UNKNOWN        10.50.0.1/24
UNCONN 0      0              0.0.0.0:51820 0.0.0.0:*
UNCONN 0      0                 [::]:51820    [::]:*
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1

WireGuard listens on UDP 51820 on IPv4 and IPv6, and forwarding is on so peers can reach each other through the server.

The wg0 address, the UDP 51820 listeners and IP forwarding

Step 10: Full-tunnel internet access (optional)

By default the server is a private overlay: peers reach the server and each other, not the internet through it. To make it an internet gateway for clients with AllowedIPs = 0.0.0.0/0, turn on the NAT lines in wg0.conf. Check the VM's internet-facing interface first (eth0 on Azure; the lines use it):

ip route show default
sudo sed -i 's|^#PostUp = iptables|PostUp = iptables|; s|^#PostDown = iptables|PostDown = iptables|' /etc/wireguard/wg0.conf
sudo systemctl restart wg-quick@wg0
sudo iptables -t nat -L POSTROUTING -n

The last command shows a MASQUERADE rule for eth0. Restarting drops connected peers for a moment; they reconnect by themselves.

Step 11: Components

Component Path
WireGuard kernel module in the Ubuntu 26.04 Azure kernel
wg, wg-quick /usr/bin/wg, /usr/bin/wg-quick
Server configuration /etc/wireguard/wg0.conf
Recorded endpoint /etc/wireguard/endpoint
Peer helper /usr/local/sbin/cloudimg-wireguard (alias /usr/local/sbin/wg-peers)
Service wg-quick@wg0.service
First boot /usr/local/sbin/wireguard-firstboot.sh, wireguard-firstboot.service
Server details /stage/scripts/wireguard-credentials.log
First boot marker /var/lib/cloudimg/wireguard-firstboot.done
Forwarding settings /etc/sysctl.d/99-wireguard.conf
wg --version
wireguard-tools v1.0.20250521 - https://git.zx2c4.com/wireguard-tools/

Step 12: Managing the service

sudo systemctl status wg-quick@wg0 --no-pager
sudo systemctl reload wg-quick@wg0     # apply wg0.conf changes, keeping tunnels up
sudo systemctl restart wg-quick@wg0    # full restart, drops tunnels briefly
sudo systemctl stop wg-quick@wg0
sudo systemctl start wg-quick@wg0

Updates: unattended upgrades install Ubuntu's security updates, WireGuard's included; sudo apt update && sudo apt upgrade applies the rest.

Step 13: Troubleshooting

A peer never gets a handshake

  • The client's Endpoint must be the VM's public IP address (sudo wg-peers endpoint), never the private eth0 address

  • The network security group must allow inbound UDP 51820 from the client

  • The public key the server holds for the peer (sudo wg-peers list) must match the client's public key exactly

  • Some networks block outbound UDP; try from another network

  • To watch packets arrive, install tcpdump (sudo apt install tcpdump) and run sudo tcpdump -ni eth0 udp port 51820 while the client connects

The handshake works but no traffic flows

  • The client's AllowedIPs must cover the destination: 10.50.0.0/24 for the overlay, 0.0.0.0/0 for everything

  • For full-tunnel access, the NAT rule from Step 10 must be on: sudo iptables -t nat -L POSTROUTING -n

The server key is lost or exposed

  • Generate a new key pair (wg genkey | sudo tee /etc/wireguard/server-priv.key | wg pubkey), put the new private key in wg0.conf's PrivateKey, restart wg-quick@wg0, and give every peer the new server public key

Step 14: Security recommendations

  • Treat the VM as a bastion: root on it is the VPN's master key. Keep SSH narrowed to your own addresses

  • Generate client keys on the clients; the server only ever needs their public keys

  • Keep each peer's server-side AllowedIPs to its own /32, as wg-peers does

  • Remove peers you no longer trust with sudo wg-peers remove-peer <name>, and review sudo wg-peers list for peers with no recent handshake

  • Use Azure NSG flow logs if you need an audit trail of UDP 51820 sources

Step 15: Support and licensing

WireGuard's kernel module and wireguard-tools are licensed under the GPLv2. There is no per-peer, per-tunnel or per-server fee for WireGuard.

cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.