Skip to content
glowfish

Home · Help · Setting up a WireGuard server

Setting up a WireGuard server

WireGuard is a lean VPN: a few lines of configuration, fast connection, apps for Windows, macOS, Linux, Android and iOS. Your own devices reach the vServer and its services (database, administration, internal websites) encrypted, without these services being open on the internet. This guide applies to Debian 13 and Ubuntu 26.04.

Routing all internet traffic of a home network or another connection through a vServer (VPN exit) is not permitted. See section 4.14 of the terms and conditions.

Which server

WireGuard runs in the kernel. The simplest option is therefore a vServer with KVM, which has its own kernel. It needs a public IPv4 address and a free UDP port.

1. Installing and generating keys

apt update && apt install wireguard-tools qrencode
cd /etc/wireguard && umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee handy.key | wg pubkey > handy.pub

2. Server configuration

/etc/wireguard/wg0.conf, insert the keys from the files:

[Interface]
Address    = 10.66.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>

[Peer]
# Phone
PublicKey  = <contents of handy.pub>
AllowedIPs = 10.66.0.2/32

3. Start

systemctl enable --now wg-quick@wg0

If a firewall is running, UDP port 51820 must be open (ufw: ufw allow 51820/udp).

4. Connecting a device

Save the following configuration as /etc/wireguard/handy.conf and import it in the WireGuard app as a file or QR code (qrencode -t ansiutf8 < handy.conf):

[Interface]
Address    = 10.66.0.2/32
PrivateKey = <contents of handy.key>

[Peer]
PublicKey  = <contents of server.pub>
Endpoint   = <IPv4 address of the server>:51820
AllowedIPs = 10.66.0.1/32
PersistentKeepalive = 25

Only traffic to the vServer (10.66.0.1) goes through the VPN. Services on the server can be limited to this address, for example a database with bind-address = 10.66.0.1. Routing all internet traffic of a connection through the vServer (VPN exit) is not permitted. See section 4.14 of the terms and conditions.

Check

wg show shows the latest handshake for each device. If nothing is shown there, the device is not getting through: compare the port, endpoint address and key pairs.

See also: View vServer with KVM First steps on the vServer